From bfb6b2dfa1dd4635fbe09b618750477c6a2b7984 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 10 Jan 2023 18:37:43 +0100 Subject: [PATCH] merge increase/reduce column into 1 for quick changes --- .../gallery/pro/activities/MainActivity.kt | 29 +++++++++++++++---- .../gallery/pro/activities/MediaActivity.kt | 29 +++++++++++++++---- app/src/main/res/menu/menu_main.xml | 13 +++------ app/src/main/res/menu/menu_media.xml | 13 +++------ 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 702ccbcf0..b1acc459c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -16,9 +16,11 @@ import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog +import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FileDirItem +import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.Release import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.commons.views.MyRecyclerView @@ -303,8 +305,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private fun refreshMenuItems() { if (!mIsThirdPartyIntent) { main_menu.getToolbar().menu.apply { - findItem(R.id.increase_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt < MAX_COLUMN_COUNT - findItem(R.id.reduce_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt > 1 + findItem(R.id.column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID findItem(R.id.set_as_default_folder).isVisible = !config.defaultFolder.isEmpty() findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations) } @@ -349,8 +350,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { R.id.temporarily_show_excluded -> tryToggleTemporarilyShowExcluded() R.id.stop_showing_excluded -> tryToggleTemporarilyShowExcluded() R.id.create_new_folder -> createNewFolder() - R.id.increase_column_count -> increaseColumnCount() - R.id.reduce_column_count -> reduceColumnCount() + R.id.column_count -> changeColumnCount() R.id.set_as_default_folder -> setAsDefaultFolder() R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() R.id.settings -> launchSettings() @@ -727,17 +727,34 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } } + 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 = (directories_grid.layoutManager as MyGridLayoutManager).spanCount + RadioGroupDialog(this, items, currentColumnCount) { + val newColumnCount = it as Int + if (currentColumnCount != newColumnCount) { + config.dirColumnCnt = newColumnCount + columnCountChanged() + } + } + } + private fun increaseColumnCount() { - config.dirColumnCnt = ++(directories_grid.layoutManager as MyGridLayoutManager).spanCount + config.dirColumnCnt += 1 columnCountChanged() } private fun reduceColumnCount() { - config.dirColumnCnt = --(directories_grid.layoutManager as MyGridLayoutManager).spanCount + config.dirColumnCnt -= 1 columnCountChanged() } private fun columnCountChanged() { + (directories_grid.layoutManager as MyGridLayoutManager).spanCount = config.dirColumnCnt refreshMenuItems() getRecyclerAdapter()?.apply { notifyItemRangeChanged(0, dirs.size) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 716bfbb40..171a99800 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -16,9 +16,11 @@ import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.transition.Transition import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog +import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* 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.gallery.pro.R @@ -248,8 +250,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { findItem(R.id.unset_as_default_folder).isVisible = isDefaultFolder val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) - findItem(R.id.increase_column_count).isVisible = viewType == VIEW_TYPE_GRID && config.mediaColumnCnt < MAX_COLUMN_COUNT - findItem(R.id.reduce_column_count).isVisible = viewType == VIEW_TYPE_GRID && config.mediaColumnCnt > 1 + findItem(R.id.column_count).isVisible = viewType == VIEW_TYPE_GRID findItem(R.id.toggle_filename).isVisible = viewType == VIEW_TYPE_GRID } } @@ -280,8 +281,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { R.id.create_new_folder -> createNewFolder() 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.set_as_default_folder -> setAsDefaultFolder() R.id.unset_as_default_folder -> unsetAsDefaultFolder() R.id.slideshow -> startSlideshow() @@ -731,17 +731,34 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } } + 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 = (media_grid.layoutManager as MyGridLayoutManager).spanCount + RadioGroupDialog(this, items, currentColumnCount) { + val newColumnCount = it as Int + if (currentColumnCount != newColumnCount) { + config.mediaColumnCnt = newColumnCount + columnCountChanged() + } + } + } + private fun increaseColumnCount() { - config.mediaColumnCnt = ++(media_grid.layoutManager as MyGridLayoutManager).spanCount + config.mediaColumnCnt += 1 columnCountChanged() } private fun reduceColumnCount() { - config.mediaColumnCnt = --(media_grid.layoutManager as MyGridLayoutManager).spanCount + config.mediaColumnCnt -= 1 columnCountChanged() } private fun columnCountChanged() { + (media_grid.layoutManager as MyGridLayoutManager).spanCount = config.mediaColumnCnt handleGridSpacing() refreshMenuItems() getMediaAdapter()?.apply { diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 151b5b668..89b718f99 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -59,15 +59,10 @@ android:title="@string/create_new_folder" app:showAsAction="never" /> - + android:id="@+id/column_count" + android:icon="@drawable/ic_column_count_vector" + android:title="@string/column_count" + app:showAsAction="ifRoom" /> - + android:id="@+id/column_count" + android:icon="@drawable/ic_column_count_vector" + android:title="@string/column_count" + app:showAsAction="ifRoom" />