Changed MIN_COLUMNS_COUNT value to 1 and improved readability of created items in changeColumnCount

This commit is contained in:
merkost
2023-07-22 23:13:12 +10:00
parent 037e8ca9d4
commit 25b15785a0
2 changed files with 5 additions and 4 deletions

View File

@ -217,8 +217,9 @@ class MainActivity : SimpleActivity() {
} }
private fun changeColumnCount() { private fun changeColumnCount() {
val items = (CONTACTS_GRID_MIN_COLUMNS_COUNT..CONTACTS_GRID_MAX_COLUMNS_COUNT).map { val items = ArrayList<RadioItem>()
RadioItem(it, resources.getQuantityString(R.plurals.column_counts, it, it)) for (i in 1..CONTACTS_GRID_MAX_COLUMNS_COUNT) {
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
} }
val currentColumnCount = config.contactsGridColumnCount val currentColumnCount = config.contactsGridColumnCount

View File

@ -351,7 +351,7 @@ class ContactsAdapter(
val layoutManager = recyclerView.layoutManager val layoutManager = recyclerView.layoutManager
if (layoutManager is GridLayoutManager) { if (layoutManager is GridLayoutManager) {
val currentSpanCount = layoutManager.spanCount val currentSpanCount = layoutManager.spanCount
val newSpanCount = (currentSpanCount - 1).coerceIn(CONTACTS_GRID_MIN_COLUMNS_COUNT, CONTACTS_GRID_MAX_COLUMNS_COUNT) val newSpanCount = (currentSpanCount - 1).coerceIn(1, CONTACTS_GRID_MAX_COLUMNS_COUNT)
layoutManager.spanCount = newSpanCount layoutManager.spanCount = newSpanCount
recyclerView.requestLayout() recyclerView.requestLayout()
onSpanCountListener(newSpanCount) onSpanCountListener(newSpanCount)
@ -362,7 +362,7 @@ class ContactsAdapter(
val layoutManager = recyclerView.layoutManager val layoutManager = recyclerView.layoutManager
if (layoutManager is GridLayoutManager) { if (layoutManager is GridLayoutManager) {
val currentSpanCount = layoutManager.spanCount val currentSpanCount = layoutManager.spanCount
val newSpanCount = (currentSpanCount + 1).coerceIn(CONTACTS_GRID_MIN_COLUMNS_COUNT, CONTACTS_GRID_MAX_COLUMNS_COUNT) val newSpanCount = (currentSpanCount + 1).coerceIn(1, CONTACTS_GRID_MAX_COLUMNS_COUNT)
layoutManager.spanCount = newSpanCount layoutManager.spanCount = newSpanCount
recyclerView.requestLayout() recyclerView.requestLayout()
onSpanCountListener(newSpanCount) onSpanCountListener(newSpanCount)