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

Commit e89a642

Browse files
authored
Merge pull request #20 from amardeshbd/feature/2_grid_view_for_layout_selection_refinement
Feature/2 grid view for layout selection refinement
2 parents 490b097 + d23e825 commit e89a642

24 files changed

+242
-176
lines changed

.idea/copyright/apache_license.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A demo application for Android `ConstraintLayout` with various usage with sample
1818
* [ ] Horizontal Axis: left, right, start and end sides
1919
* [ ] Vertical Axis: top, bottom sides and text baseline
2020
- [ ] Margins
21-
- [ ] Centering positioning and bias
21+
- [x] Centering positioning and bias
2222
- [ ] Circular positioning _(Added in 1.1)_
2323
- [ ] Visibility behavior
2424
- [ ] Dimension constraints
@@ -45,3 +45,8 @@ These are the **my** objectives for this demo application.
4545
* Learn and use the new architecture components in the sample app
4646
* Learn and use proper architecture for the app - likely MVVM
4747
* Document everything well so that future external contribution is easier
48+
49+
## Preview
50+
Here is a snapshot of current progress _(This will be updated from time to time)_.
51+
52+
![Browse Layout Variances](https://user-images.githubusercontent.com/99822/39676220-f20ef5c6-5134-11e8-9430-08f90b5fe5fb.png) ![Show Layout Screen](https://user-images.githubusercontent.com/99822/39676265-a0bb1f28-5135-11e8-8c34-014cef844e97.png)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package com.hossainkhan.android.demo.browse
1818

19-
import android.content.Context
2019
import android.support.v7.widget.RecyclerView
2120
import android.view.LayoutInflater
2221
import android.view.View
2322
import android.view.ViewGroup
23+
import android.widget.ImageView
2424
import android.widget.TextView
2525
import com.hossainkhan.android.demo.R
2626
import com.hossainkhan.android.demo.data.LayoutInformation
@@ -36,6 +36,7 @@ class LayoutBrowseAdapter(
3636
class ViewHolder(itemViewRoot: View,
3737
private val onClickListener: (Int) -> Unit) : RecyclerView.ViewHolder(itemViewRoot) {
3838
val itemName = itemViewRoot.findViewById<TextView>(R.id.layout_preview_name)!!
39+
val itemThumb = itemViewRoot.findViewById<ImageView>(R.id.imageView)
3940

4041
init {
4142
itemViewRoot.setOnClickListener {
@@ -60,6 +61,7 @@ class LayoutBrowseAdapter(
6061
// - get element from your dataset at this position
6162
// - replace the contents of the view with that element
6263
holder.itemName.text = data[position].title
64+
holder.itemThumb.setImageResource(data[position].thumbnailResourceId)
6365
}
6466

6567
// Return the size of your dataset (invoked by the layout manager)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.hossainkhan.android.demo.browse
1818

1919
import android.support.v7.app.AppCompatActivity
2020
import android.os.Bundle
21+
import android.support.v7.widget.GridLayoutManager
2122
import android.support.v7.widget.LinearLayoutManager
2223
import android.support.v7.widget.RecyclerView
2324
import 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)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ class LayoutDataStore @Inject constructor(
2828
private val resources: Resources) {
2929
val supportedLayoutInfos = listOf(
3030
LayoutInformation(
31-
layoutResourceId = R.layout.activity_positioning_top_left,
31+
layoutResourceId = R.layout.preview_positioning_top_left,
32+
thumbnailResourceId = R.drawable.ic_positioning_top_left,
3233
title = "Positioning: Top Left",
3334
description = "Top left using constraints."),
3435
LayoutInformation(
35-
layoutResourceId = R.layout.activity_positioning_centered,
36+
layoutResourceId = R.layout.preview_positioning_centered,
37+
thumbnailResourceId = R.drawable.ic_positioning_center,
3638
title = "Positioning: Centered",
3739
description = "Centered view using constraints on top-bottom and left-right.")
3840
)
@@ -52,7 +54,7 @@ class LayoutDataStore @Inject constructor(
5254
*/
5355
fun getLayoutUrl(@LayoutRes layoutResourceId: Int): String {
5456
// Containes package name and layout name
55-
// com.hossainkhan.android.demo:layout/activity_positioning_top_left
57+
// com.hossainkhan.android.demo:layout/preview_positioning_top_left
5658
val resourceName = resources.getResourceName(layoutResourceId)
5759

5860
if(!resourceName.contains("layout")) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.hossainkhan.android.demo.data
1818

19+
import android.support.annotation.DrawableRes
1920
import android.support.annotation.LayoutRes
2021

2122
/**
@@ -24,6 +25,8 @@ import android.support.annotation.LayoutRes
2425
data class LayoutInformation(
2526
@LayoutRes
2627
val layoutResourceId: Int,
28+
@DrawableRes
29+
val thumbnailResourceId: Int,
2730
val title: CharSequence,
2831
val description: CharSequence
2932
)

app/src/main/java/com/hossainkhan/android/demo/layoutpositioning/LayoutPositioningDemoActivity.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff 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)

app/src/main/res/drawable/grid_overlay.xml

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)