Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit 9591af1

Browse files
committed
[ADDED] [#102] Menu item to go directly to resources.
1 parent 9bccdc0 commit 9591af1

File tree

9 files changed

+103
-30
lines changed

9 files changed

+103
-30
lines changed

.idea/assetWizardSettings.xml

+2-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/hossainkhan/android/demo/data/LayoutDataStore.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ class LayoutDataStore @Inject constructor(
205205
LayoutInformation(
206206
layoutResourceId = R.layout.activity_learning_resource,
207207
thumbnailResourceId = R.drawable.ic_book_128dp,
208-
title = "Resources",
209-
description = "XYZ")
208+
title = "Additional Resources: Tech Talks & Blogs",
209+
description = "External resources on constraint layout. Tech talks on YouTube or blogs.")
210210

211211

212212
/*

app/src/main/java/com/hossainkhan/android/demo/data/ResourceInfo.kt

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ import com.google.firebase.Timestamp
2020
import java.util.*
2121

2222

23+
/**
24+
* External resource info.
25+
*
26+
* Example:
27+
* - author: Nicolas Roard & John Hoford
28+
* - event: Google I/O'19
29+
* - publish_date: 9 May 2019
30+
* - summary: Learn the capabilities of ConstraintLayout
31+
* - title: What's New in ConstraintLayout
32+
* - type: techtalk
33+
* - url: https://www.youtube.com/watch?v=29gLA90m6Gk
34+
*/
2335
data class ResourceInfo(
2436
var author: String = "",
2537
var summary: String = "",

app/src/main/java/com/hossainkhan/android/demo/data/Timestamp.kt

-23
This file was deleted.

app/src/main/java/com/hossainkhan/android/demo/ui/browse/LayoutBrowseActivity.kt

+29
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
package com.hossainkhan.android.demo.ui.browse
1818

1919
import android.os.Bundle
20+
import android.view.Menu
21+
import android.view.MenuItem
2022
import androidx.appcompat.app.AppCompatActivity
23+
import androidx.core.app.NavUtils
2124
import androidx.lifecycle.ViewModelProviders
2225
import androidx.recyclerview.widget.GridLayoutManager
2326
import androidx.recyclerview.widget.RecyclerView
@@ -69,4 +72,30 @@ class LayoutBrowseActivity : AppCompatActivity() {
6972
adapter = viewAdapter
7073
}
7174
}
75+
76+
//
77+
// Setup menu item on the action bar.
78+
//
79+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
80+
val inflater = menuInflater
81+
inflater.inflate(R.menu.menu_layout_browse, menu)
82+
return true
83+
}
84+
85+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
86+
return when (item.itemId) {
87+
R.id.show_external_resource -> {
88+
viewModel.onExternalResourceSelected()
89+
true
90+
}
91+
android.R.id.home -> {
92+
// Respond to the action bar's Up/Home button
93+
// https://developer.android.com/training/implementing-navigation/ancestral
94+
NavUtils.navigateUpFromSameTask(this)
95+
return true
96+
}
97+
else -> super.onOptionsItemSelected(item)
98+
}
99+
}
100+
72101
}

app/src/main/java/com/hossainkhan/android/demo/ui/browse/LayoutBrowseViewModel.kt

+4
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ class LayoutBrowseViewModel @Inject constructor(
8989
}
9090

9191
}
92+
93+
fun onExternalResourceSelected() {
94+
browseNavigator.loadActivity(LearningResourceActivity::class.java)
95+
}
9296
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
~ Copyright (c) 2019 Hossain Khan
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="24dp"
19+
android:height="24dp"
20+
android:viewportWidth="24.0"
21+
android:viewportHeight="24.0">
22+
<path
23+
android:fillColor="@color/md_grey_300"
24+
android:pathData="M21,3L3,3c-1.11,0 -2,0.89 -2,2v12c0,1.1 0.89,2 2,2h5v2h8v-2h5c1.1,0 1.99,-0.9 1.99,-2L23,5c0,-1.11 -0.9,-2 -2,-2zM21,17L3,17L3,5h18v12zM16,11l-7,4L9,7z"/>
25+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Copyright (c) 2019 Hossain Khan
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
xmlns:tools="http://schemas.android.com/tools">
20+
21+
<item
22+
android:id="@+id/show_external_resource"
23+
android:icon="@drawable/ic_ondemand_video_black_24dp"
24+
android:title="@string/btn_cta_external_resource"
25+
android:visible="true"
26+
app:showAsAction="always"
27+
tools:targetApi="o" />
28+
</menu>

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<string name="app_name">ConstraintLayout Demo</string>
33
<string name="btn_cta_okay">OK</string>
44
<string name="btn_cta_information">Info</string>
5+
<string name="btn_cta_external_resource">Resources</string>
56
<string name="btn_cta_preview_layout_xml">Preview XML</string>
67

78

0 commit comments

Comments
 (0)