From 05d37cbfcc6df8a8fc4ad98489f361fd925a7453 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 14:35:52 +0200 Subject: [PATCH] add a dialog for selecting folder thumbnail grouping --- .../gallery/activities/MediaActivity.kt | 22 +++++++++++++++++++ .../gallery/helpers/Config.kt | 4 ++++ .../gallery/helpers/Constants.kt | 8 +++++++ app/src/main/res/menu/menu_media.xml | 4 ++++ 4 files changed, 38 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 266a85431..b29caf3e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -217,6 +217,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { R.id.open_camera -> launchCamera() R.id.folder_view -> switchToFolderView() R.id.change_view_type -> changeViewType() + R.id.group -> showGroupByDialog() R.id.hide_folder -> tryHideFolder() R.id.unhide_folder -> unhideFolder() R.id.exclude_folder -> tryExcludeFolder() @@ -416,6 +417,27 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } + private fun showGroupByDialog() { + val items = arrayListOf( + RadioItem(GROUP_BY_NONE, getString(R.string.do_not_group_files)), + RadioItem(GROUP_BY_LAST_MODIFIED, getString(R.string.by_last_modified)), + RadioItem(GROUP_BY_DATE_TAKEN, getString(R.string.by_date_taken)), + RadioItem(GROUP_BY_FILE_TYPE, getString(R.string.by_file_type)), + RadioItem(GROUP_BY_EXTENSION, getString(R.string.by_extension)) + ) + + if (mShowAll) { + items.add(RadioItem(GROUP_BY_FOLDER, getString(R.string.by_folder))) + } + + RadioGroupDialog(this, items, config.groupBy) { + config.groupBy = it as Int + invalidateOptionsMenu() + media_grid.adapter = null + setupAdapter() + } + } + private fun tryHideFolder() { if (config.wasHideFolderTooltipShown) { hideFolder() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 59fcde108..cf291465c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -326,4 +326,8 @@ class Config(context: Context) : BaseConfig(context) { var wereFavoritesPinned: Boolean get() = prefs.getBoolean(WERE_FAVORITES_PINNED, false) set(wereFavoritesPinned) = prefs.edit().putBoolean(WERE_FAVORITES_PINNED, wereFavoritesPinned).apply() + + var groupBy: Int + get() = prefs.getInt(GROUP_BY, GROUP_BY_NONE) + set(groupBy) = prefs.edit().putInt(GROUP_BY, groupBy).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 3fd37fcf0..de9e4e7ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -50,6 +50,7 @@ const val WAS_OTG_HANDLED = "was_otg_handled" const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation" const val BOTTOM_ACTIONS = "bottom_actions" const val WERE_FAVORITES_PINNED = "were_favorites_pinned" +const val GROUP_BY = "group_by" // slideshow const val SLIDESHOW_INTERVAL = "slideshow_interval" @@ -112,3 +113,10 @@ const val TYPE_RAWS = 8 const val LOCAITON_INTERNAL = 1 const val LOCATION_SD = 2 const val LOCATION_OTG = 3 + +const val GROUP_BY_NONE = 0 +const val GROUP_BY_LAST_MODIFIED = 1 +const val GROUP_BY_DATE_TAKEN = 2 +const val GROUP_BY_FILE_TYPE = 3 +const val GROUP_BY_EXTENSION = 4 +const val GROUP_BY_FOLDER = 5 diff --git a/app/src/main/res/menu/menu_media.xml b/app/src/main/res/menu/menu_media.xml index de3b01776..f59adabec 100644 --- a/app/src/main/res/menu/menu_media.xml +++ b/app/src/main/res/menu/menu_media.xml @@ -31,6 +31,10 @@ android:icon="@drawable/ic_camera" android:title="@string/open_camera" app:showAsAction="ifRoom"/> +