Skip to content

Commit 51c3810

Browse files
committed
simplify column count customization
1 parent f01bcb0 commit 51c3810

File tree

8 files changed

+60
-46
lines changed

8 files changed

+60
-46
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ class MainActivity : SimpleActivity() {
190190
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden && currentFragment !is StorageFragment
191191
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden && currentFragment !is StorageFragment
192192

193-
findItem(R.id.increase_column_count).isVisible =
194-
currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT && currentFragment !is StorageFragment
195-
findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1 && currentFragment !is StorageFragment
193+
findItem(R.id.column_count).isVisible = currentViewType == VIEW_TYPE_GRID && currentFragment !is StorageFragment
196194

197195
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
198196
findItem(R.id.settings).isVisible = !isCreateDocumentIntent
@@ -235,8 +233,7 @@ class MainActivity : SimpleActivity() {
235233
R.id.change_view_type -> changeViewType()
236234
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
237235
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
238-
R.id.increase_column_count -> increaseColumnCount()
239-
R.id.reduce_column_count -> reduceColumnCount()
236+
R.id.column_count -> changeColumnCount()
240237
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
241238
R.id.settings -> launchSettings()
242239
R.id.about -> launchAbout()
@@ -568,15 +565,21 @@ class MainActivity : SimpleActivity() {
568565
}
569566
}
570567

571-
private fun increaseColumnCount() {
572-
getAllFragments().forEach {
573-
(it as? ItemOperationsListener)?.increaseColumnCount()
568+
private fun changeColumnCount() {
569+
val items = ArrayList<RadioItem>()
570+
for (i in 1..MAX_COLUMN_COUNT) {
571+
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
574572
}
575-
}
576573

577-
private fun reduceColumnCount() {
578-
getAllFragments().forEach {
579-
(it as? ItemOperationsListener)?.reduceColumnCount()
574+
val currentColumnCount = config.fileColumnCnt
575+
RadioGroupDialog(this, items, config.fileColumnCnt) {
576+
val newColumnCount = it as Int
577+
if (currentColumnCount != newColumnCount) {
578+
config.fileColumnCnt = newColumnCount
579+
getAllFragments().forEach {
580+
(it as? ItemOperationsListener)?.columnCountChanged()
581+
}
582+
}
580583
}
581584
}
582585

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import android.view.MenuItem
99
import androidx.appcompat.widget.SearchView
1010
import androidx.core.view.MenuItemCompat
1111
import androidx.recyclerview.widget.GridLayoutManager
12+
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
1213
import com.simplemobiletools.commons.extensions.*
1314
import com.simplemobiletools.commons.helpers.NavigationIcon
1415
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
1516
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
1617
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1718
import com.simplemobiletools.commons.models.FileDirItem
19+
import com.simplemobiletools.commons.models.RadioItem
1820
import com.simplemobiletools.commons.views.MyGridLayoutManager
1921
import com.simplemobiletools.commons.views.MyRecyclerView
2022
import com.simplemobiletools.filemanager.pro.R
@@ -85,8 +87,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
8587
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden
8688
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden
8789

88-
findItem(R.id.increase_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT
89-
findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1
90+
findItem(R.id.column_count).isVisible = currentViewType == VIEW_TYPE_GRID
9091
}
9192
}
9293

@@ -99,8 +100,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
99100
R.id.change_view_type -> changeViewType()
100101
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
101102
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
102-
R.id.increase_column_count -> increaseColumnCount()
103-
R.id.reduce_column_count -> reduceColumnCount()
103+
R.id.column_count -> changeColumnCount()
104104
else -> return@setOnMenuItemClickListener false
105105
}
106106
return@setOnMenuItemClickListener true
@@ -166,20 +166,44 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
166166
getRecyclerAdapter()?.updateDisplayFilenamesInGrid()
167167
}
168168

169+
private fun changeColumnCount() {
170+
val items = ArrayList<RadioItem>()
171+
for (i in 1..MAX_COLUMN_COUNT) {
172+
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
173+
}
174+
175+
val currentColumnCount = config.fileColumnCnt
176+
RadioGroupDialog(this, items, config.fileColumnCnt) {
177+
val newColumnCount = it as Int
178+
if (currentColumnCount != newColumnCount) {
179+
config.fileColumnCnt = newColumnCount
180+
columnCountChanged()
181+
}
182+
}
183+
}
184+
169185
override fun increaseColumnCount() {
170186
if (currentViewType == VIEW_TYPE_GRID) {
171-
config.fileColumnCnt = ++(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount
187+
config.fileColumnCnt += 1
172188
columnCountChanged()
173189
}
174190
}
175191

176192
override fun reduceColumnCount() {
177193
if (currentViewType == VIEW_TYPE_GRID) {
178-
config.fileColumnCnt = --(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount
194+
config.fileColumnCnt -= 1
179195
columnCountChanged()
180196
}
181197
}
182198

199+
override fun columnCountChanged() {
200+
(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount = config.fileColumnCnt
201+
refreshMenuItems()
202+
getRecyclerAdapter()?.apply {
203+
notifyItemRangeChanged(0, listItems.size)
204+
}
205+
}
206+
183207
override fun finishActMode() {}
184208

185209
private fun setupSearch(menu: Menu) {
@@ -370,13 +394,6 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
370394
}
371395
}
372396

373-
private fun columnCountChanged() {
374-
refreshMenuItems()
375-
getRecyclerAdapter()?.apply {
376-
notifyItemRangeChanged(0, listItems.size)
377-
}
378-
}
379-
380397
private fun setupLayoutManager() {
381398
if (config.getFolderViewType(currentMimeType) == VIEW_TYPE_GRID) {
382399
currentViewType = VIEW_TYPE_GRID

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,19 +488,20 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
488488

489489
override fun increaseColumnCount() {
490490
if (currentViewType == VIEW_TYPE_GRID) {
491-
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
491+
context!!.config.fileColumnCnt += 1
492492
columnCountChanged()
493493
}
494494
}
495495

496496
override fun reduceColumnCount() {
497497
if (currentViewType == VIEW_TYPE_GRID) {
498-
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
498+
context!!.config.fileColumnCnt -= 1
499499
columnCountChanged()
500500
}
501501
}
502502

503-
private fun columnCountChanged() {
503+
override fun columnCountChanged() {
504+
(items_list.layoutManager as MyGridLayoutManager).spanCount = context!!.config.fileColumnCnt
504505
(activity as? MainActivity)?.refreshMenuItems()
505506
getRecyclerAdapter()?.apply {
506507
notifyItemRangeChanged(0, listItems.size)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,20 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
178178

179179
override fun increaseColumnCount() {
180180
if (currentViewType == VIEW_TYPE_GRID) {
181-
context?.config?.fileColumnCnt = ++(recents_list.layoutManager as MyGridLayoutManager).spanCount
181+
context!!.config.fileColumnCnt += 1
182182
columnCountChanged()
183183
}
184184
}
185185

186186
override fun reduceColumnCount() {
187187
if (currentViewType == VIEW_TYPE_GRID) {
188-
context?.config?.fileColumnCnt = --(recents_list.layoutManager as MyGridLayoutManager).spanCount
188+
context!!.config.fileColumnCnt -= 1
189189
columnCountChanged()
190190
}
191191
}
192192

193-
private fun columnCountChanged() {
193+
override fun columnCountChanged() {
194+
(recents_list.layoutManager as MyGridLayoutManager).spanCount = context!!.config.fileColumnCnt
194195
(activity as? MainActivity)?.refreshMenuItems()
195196
getRecyclerAdapter()?.apply {
196197
notifyItemRangeChanged(0, listItems.size)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.simplemobiletools.commons.helpers.TAB_RECENT_FILES
55
import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS
66

77
const val PATH = "path"
8-
const val MAX_COLUMN_COUNT = 20
8+
const val MAX_COLUMN_COUNT = 15
99

1010
// shared preferences
1111
const val SHOW_HIDDEN = "show_hidden"

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/interfaces/ItemOperationsListener.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ interface ItemOperationsListener {
1818

1919
fun toggleFilenameVisibility()
2020

21+
fun columnCountChanged()
22+
2123
fun increaseColumnCount()
2224

2325
fun reduceColumnCount()

app/src/main/res/menu/menu.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,9 @@
5454
android:title="@string/stop_showing_hidden"
5555
app:showAsAction="never" />
5656
<item
57-
android:id="@+id/increase_column_count"
57+
android:id="@+id/column_count"
5858
android:showAsAction="never"
59-
android:title="@string/increase_column_count"
60-
app:showAsAction="never" />
61-
<item
62-
android:id="@+id/reduce_column_count"
63-
android:showAsAction="never"
64-
android:title="@string/reduce_column_count"
59+
android:title="@string/column_count"
6560
app:showAsAction="never" />
6661
<item
6762
android:id="@+id/more_apps_from_us"

app/src/main/res/menu/menu_mimetypes.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@
3535
android:title="@string/stop_showing_hidden"
3636
app:showAsAction="never" />
3737
<item
38-
android:id="@+id/increase_column_count"
38+
android:id="@+id/column_count"
3939
android:showAsAction="never"
40-
android:title="@string/increase_column_count"
41-
app:showAsAction="never" />
42-
<item
43-
android:id="@+id/reduce_column_count"
44-
android:showAsAction="never"
45-
android:title="@string/reduce_column_count"
40+
android:title="@string/column_count"
4641
app:showAsAction="never" />
4742
</menu>

0 commit comments

Comments
 (0)