This repository was archived by the owner on Aug 22, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +47
-5
lines changed
java/com/hossainkhan/android/demo Expand file tree Collapse file tree 5 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package com.hossainkhan.android.demo.browse
1818
1919import android.support.v7.app.AppCompatActivity
2020import android.os.Bundle
21+ import android.support.v7.widget.GridLayoutManager
2122import android.support.v7.widget.LinearLayoutManager
2223import android.support.v7.widget.RecyclerView
2324import android.view.View
@@ -44,7 +45,7 @@ class MainActivity : AppCompatActivity() {
4445 Timber .d(" Got data: ${appDataStore.isFirstTime()} " )
4546 appDataStore.updateFirstTimeUser(false )
4647
47- viewManager = LinearLayoutManager (this )
48+ viewManager = GridLayoutManager (this , resources.getInteger( R .integer.grid_column_count) )
4849 viewAdapter = LayoutBrowseAdapter (
4950 data = appDataStore.layoutStore.supportedLayoutInfos,
5051 itemSelectedListener = this ::onLayoutItemSelected)
Original file line number Diff line number Diff line change @@ -38,4 +38,18 @@ class AppDataStore @Inject constructor(
3838 preferences.edit().putBoolean(PREF_KEY_IS_FIRST_TIME_USER , isFirstTime).apply ()
3939 }
4040
41+ /* *
42+ * Checks if layout information should be shown to user, and updates the flag if it should be shown.
43+ *
44+ * @return `true`, if it's first time being checked, else `false`
45+ */
46+ fun shouldshowLayoutInformation (layoutId : Int ): Boolean {
47+ val layoutPreferenceKey = layoutStore.getLayoutUrl(layoutId)
48+ val shouldShow = preferences.getBoolean(layoutPreferenceKey, true )
49+ if (shouldShow) {
50+ preferences.edit().putBoolean(layoutPreferenceKey, false ).apply ()
51+ }
52+ return shouldShow
53+ }
54+
4155}
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ class LayoutPositioningDemoActivity : AppCompatActivity() {
8181 /* *
8282 * Loads layout information and previews in a snackbar.
8383 */
84- private fun showLayoutInfo (layoutInformation : LayoutInformation ) {
84+ private fun showLayoutInfo (layoutInformation : LayoutInformation , fromUser : Boolean = false ) {
8585 if (flashbar == null ) {
8686 flashbar = Flashbar .Builder (this )
8787 .gravity(Flashbar .Gravity .BOTTOM )
@@ -108,8 +108,13 @@ class LayoutPositioningDemoActivity : AppCompatActivity() {
108108 .build()
109109 }
110110
111- if (flashbar?.isShowing() == false ) {
112- flashbar?.show()
111+ Timber .d(" Flash bar showing: %s" , flashbar?.isShown())
112+ if (flashbar?.isShown() == false ) {
113+ if (fromUser || appDataStore.shouldshowLayoutInformation(layoutInformation.layoutResourceId)) {
114+ flashbar?.show()
115+ }
116+ } else {
117+ flashbar?.dismiss()
113118 }
114119 }
115120
@@ -138,7 +143,7 @@ class LayoutPositioningDemoActivity : AppCompatActivity() {
138143 override fun onOptionsItemSelected (item : MenuItem ): Boolean {
139144 return when (item.itemId) {
140145 R .id.show_layout_info_menu_item -> {
141- showLayoutInfo(layoutInformation)
146+ showLayoutInfo(layoutInformation, true )
142147 true
143148 }
144149 else -> super .onOptionsItemSelected(item)
Original file line number Diff line number Diff line change 1+ <!--
2+ ~ Copyright (c) 2018 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+ <resources >
18+ <!-- On phone use more column on landscape mode for better content browsing -->
19+ <item name =" grid_column_count" type =" integer" >2</item >
20+ </resources >
Original file line number Diff line number Diff line change 2020 <dimen name =" box_size_small" >40dp</dimen >
2121 <dimen name =" box_size_medium" >80dp</dimen >
2222 <dimen name =" box_size_large" >120dp</dimen >
23+
24+ <item name =" grid_column_count" type =" integer" >1</item >
2325</resources >
You can’t perform that action at this time.
0 commit comments