From 51c38109e9830bd3892e3cca7d87117941ce9edc Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 5 Jan 2023 11:45:01 +0100 Subject: [PATCH] simplify column count customization --- .../pro/activities/MainActivity.kt | 27 ++++++------ .../pro/activities/MimeTypesActivity.kt | 43 +++++++++++++------ .../pro/fragments/ItemsFragment.kt | 7 +-- .../pro/fragments/RecentsFragment.kt | 7 +-- .../filemanager/pro/helpers/Constants.kt | 2 +- .../pro/interfaces/ItemOperationsListener.kt | 2 + app/src/main/res/menu/menu.xml | 9 +--- app/src/main/res/menu/menu_mimetypes.xml | 9 +--- 8 files changed, 60 insertions(+), 46 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index d605c1c5..86c4e55c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -190,9 +190,7 @@ class MainActivity : SimpleActivity() { findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden && currentFragment !is StorageFragment findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden && currentFragment !is StorageFragment - findItem(R.id.increase_column_count).isVisible = - currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT && currentFragment !is StorageFragment - findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1 && currentFragment !is StorageFragment + findItem(R.id.column_count).isVisible = currentViewType == VIEW_TYPE_GRID && currentFragment !is StorageFragment findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations) findItem(R.id.settings).isVisible = !isCreateDocumentIntent @@ -235,8 +233,7 @@ class MainActivity : SimpleActivity() { R.id.change_view_type -> changeViewType() R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden() R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden() - R.id.increase_column_count -> increaseColumnCount() - R.id.reduce_column_count -> reduceColumnCount() + R.id.column_count -> changeColumnCount() R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() R.id.settings -> launchSettings() R.id.about -> launchAbout() @@ -568,15 +565,21 @@ class MainActivity : SimpleActivity() { } } - private fun increaseColumnCount() { - getAllFragments().forEach { - (it as? ItemOperationsListener)?.increaseColumnCount() + private fun changeColumnCount() { + val items = ArrayList() + for (i in 1..MAX_COLUMN_COUNT) { + items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i))) } - } - private fun reduceColumnCount() { - getAllFragments().forEach { - (it as? ItemOperationsListener)?.reduceColumnCount() + val currentColumnCount = config.fileColumnCnt + RadioGroupDialog(this, items, config.fileColumnCnt) { + val newColumnCount = it as Int + if (currentColumnCount != newColumnCount) { + config.fileColumnCnt = newColumnCount + getAllFragments().forEach { + (it as? ItemOperationsListener)?.columnCountChanged() + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt index e4fcd156..fc08b2b0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt @@ -9,12 +9,14 @@ import android.view.MenuItem import androidx.appcompat.widget.SearchView import androidx.core.view.MenuItemCompat import androidx.recyclerview.widget.GridLayoutManager +import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.NavigationIcon import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.models.FileDirItem +import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.filemanager.pro.R @@ -85,8 +87,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden - findItem(R.id.increase_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT - findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1 + findItem(R.id.column_count).isVisible = currentViewType == VIEW_TYPE_GRID } } @@ -99,8 +100,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { R.id.change_view_type -> changeViewType() R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden() R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden() - R.id.increase_column_count -> increaseColumnCount() - R.id.reduce_column_count -> reduceColumnCount() + R.id.column_count -> changeColumnCount() else -> return@setOnMenuItemClickListener false } return@setOnMenuItemClickListener true @@ -166,20 +166,44 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { getRecyclerAdapter()?.updateDisplayFilenamesInGrid() } + private fun changeColumnCount() { + val items = ArrayList() + for (i in 1..MAX_COLUMN_COUNT) { + items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i))) + } + + val currentColumnCount = config.fileColumnCnt + RadioGroupDialog(this, items, config.fileColumnCnt) { + val newColumnCount = it as Int + if (currentColumnCount != newColumnCount) { + config.fileColumnCnt = newColumnCount + columnCountChanged() + } + } + } + override fun increaseColumnCount() { if (currentViewType == VIEW_TYPE_GRID) { - config.fileColumnCnt = ++(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount + config.fileColumnCnt += 1 columnCountChanged() } } override fun reduceColumnCount() { if (currentViewType == VIEW_TYPE_GRID) { - config.fileColumnCnt = --(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount + config.fileColumnCnt -= 1 columnCountChanged() } } + override fun columnCountChanged() { + (mimetypes_list.layoutManager as MyGridLayoutManager).spanCount = config.fileColumnCnt + refreshMenuItems() + getRecyclerAdapter()?.apply { + notifyItemRangeChanged(0, listItems.size) + } + } + override fun finishActMode() {} private fun setupSearch(menu: Menu) { @@ -370,13 +394,6 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { } } - private fun columnCountChanged() { - refreshMenuItems() - getRecyclerAdapter()?.apply { - notifyItemRangeChanged(0, listItems.size) - } - } - private fun setupLayoutManager() { if (config.getFolderViewType(currentMimeType) == VIEW_TYPE_GRID) { currentViewType = VIEW_TYPE_GRID diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index 028b8c34..c89695d3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -488,19 +488,20 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF override fun increaseColumnCount() { if (currentViewType == VIEW_TYPE_GRID) { - context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount + context!!.config.fileColumnCnt += 1 columnCountChanged() } } override fun reduceColumnCount() { if (currentViewType == VIEW_TYPE_GRID) { - context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount + context!!.config.fileColumnCnt -= 1 columnCountChanged() } } - private fun columnCountChanged() { + override fun columnCountChanged() { + (items_list.layoutManager as MyGridLayoutManager).spanCount = context!!.config.fileColumnCnt (activity as? MainActivity)?.refreshMenuItems() getRecyclerAdapter()?.apply { notifyItemRangeChanged(0, listItems.size) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt index 0e0d9750..dae7ab3c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt @@ -178,19 +178,20 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage override fun increaseColumnCount() { if (currentViewType == VIEW_TYPE_GRID) { - context?.config?.fileColumnCnt = ++(recents_list.layoutManager as MyGridLayoutManager).spanCount + context!!.config.fileColumnCnt += 1 columnCountChanged() } } override fun reduceColumnCount() { if (currentViewType == VIEW_TYPE_GRID) { - context?.config?.fileColumnCnt = --(recents_list.layoutManager as MyGridLayoutManager).spanCount + context!!.config.fileColumnCnt -= 1 columnCountChanged() } } - private fun columnCountChanged() { + override fun columnCountChanged() { + (recents_list.layoutManager as MyGridLayoutManager).spanCount = context!!.config.fileColumnCnt (activity as? MainActivity)?.refreshMenuItems() getRecyclerAdapter()?.apply { notifyItemRangeChanged(0, listItems.size) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt index 91f4b669..5af5a270 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt @@ -5,7 +5,7 @@ import com.simplemobiletools.commons.helpers.TAB_RECENT_FILES import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS const val PATH = "path" -const val MAX_COLUMN_COUNT = 20 +const val MAX_COLUMN_COUNT = 15 // shared preferences const val SHOW_HIDDEN = "show_hidden" diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/interfaces/ItemOperationsListener.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/interfaces/ItemOperationsListener.kt index 1542aa40..c7a35a14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/interfaces/ItemOperationsListener.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/interfaces/ItemOperationsListener.kt @@ -18,6 +18,8 @@ interface ItemOperationsListener { fun toggleFilenameVisibility() + fun columnCountChanged() + fun increaseColumnCount() fun reduceColumnCount() diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index 24b7d028..86e77f0b 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -54,14 +54,9 @@ android:title="@string/stop_showing_hidden" app:showAsAction="never" /> - -