From 61e66a3d5df3a8d47c83a434286f49b738004dd1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 23:37:15 +0200 Subject: [PATCH] allow setting a different grouping for Show All Folders Content --- .../gallery/activities/MediaActivity.kt | 5 +++-- .../gallery/asynctasks/GetMediaAsynctask.kt | 3 ++- .../gallery/dialogs/ChangeGroupingDialog.kt | 15 +++++++-------- .../simplemobiletools/gallery/helpers/Config.kt | 2 +- .../gallery/helpers/MediaFetcher.kt | 3 ++- 5 files changed, 15 insertions(+), 13 deletions(-) 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 307fca91c..6bd103889 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -477,7 +477,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun showGroupByDialog() { - ChangeGroupingDialog(this, mShowAll, mPath) { + ChangeGroupingDialog(this, mPath) { mLoadedInitialPhotos = false media_grid.adapter = null getMedia() @@ -644,7 +644,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun calculateContentHeight(media: ArrayList) { val layoutManager = media_grid.layoutManager as MyGridLayoutManager - val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 && !config.scrollHorizontally + val pathToCheck = if (mPath.isEmpty()) SHOW_ALL else mPath + val hasSections = config.getFolderGrouping(pathToCheck) and GROUP_BY_NONE == 0 && !config.scrollHorizontally val sectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 val thumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height ?: 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index d99d5f370..27af8bee5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -6,6 +6,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getFavoritePaths import com.simplemobiletools.gallery.helpers.MediaFetcher +import com.simplemobiletools.gallery.helpers.SHOW_ALL import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.ThumbnailItem import java.util.* @@ -31,7 +32,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage } else { mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) } - return mediaFetcher.groupMedia(media, mPath) + return mediaFetcher.groupMedia(media, if (showAll) SHOW_ALL else mPath) } override fun onPostExecute(media: ArrayList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeGroupingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeGroupingDialog.kt index 63cecbc2f..9c32dcf55 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeGroupingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeGroupingDialog.kt @@ -11,18 +11,17 @@ import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.* import kotlinx.android.synthetic.main.dialog_change_grouping.view.* -class ChangeGroupingDialog(val activity: BaseSimpleActivity, val isShowingAll: Boolean, val path: String = "", val callback: () -> Unit) : +class ChangeGroupingDialog(val activity: BaseSimpleActivity, val path: String = "", val callback: () -> Unit) : DialogInterface.OnClickListener { private var currGrouping = 0 private var config = activity.config + private val pathToUse = if (path.isEmpty()) SHOW_ALL else path private var view: View init { view = activity.layoutInflater.inflate(R.layout.dialog_change_grouping, null).apply { - use_for_this_folder_divider.beVisibleIf(!isShowingAll) - grouping_dialog_use_for_this_folder.beVisibleIf(!isShowingAll) - grouping_dialog_use_for_this_folder.isChecked = config.hasCustomGrouping(path) - grouping_dialog_radio_folder.beVisibleIf(isShowingAll) + grouping_dialog_use_for_this_folder.isChecked = config.hasCustomGrouping(pathToUse) + grouping_dialog_radio_folder.beVisibleIf(path.isEmpty()) } AlertDialog.Builder(activity) @@ -32,7 +31,7 @@ class ChangeGroupingDialog(val activity: BaseSimpleActivity, val isShowingAll: B activity.setupDialogStuff(view, this, R.string.group_by) } - currGrouping = config.getFolderGrouping(path) + currGrouping = config.getFolderGrouping(pathToUse) setupGroupRadio() setupOrderRadio() } @@ -77,9 +76,9 @@ class ChangeGroupingDialog(val activity: BaseSimpleActivity, val isShowingAll: B } if (view.grouping_dialog_use_for_this_folder.isChecked) { - config.saveFolderGrouping(path, grouping) + config.saveFolderGrouping(pathToUse, grouping) } else { - config.removeFolderGrouping(path) + config.removeFolderGrouping(pathToUse) config.groupBy = grouping } callback() 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 2a1fd92f5..f02a4ef4d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -46,7 +46,7 @@ class Config(context: Context) : BaseConfig(context) { fun getFolderGrouping(path: String): Int { var groupBy = prefs.getInt(GROUP_FOLDER_PREFIX + path.toLowerCase(), groupBy) - if (path.isNotEmpty() && groupBy and GROUP_BY_FOLDER != 0) { + if (path != SHOW_ALL && groupBy and GROUP_BY_FOLDER != 0) { groupBy -= GROUP_BY_FOLDER + 1 } return groupBy diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 88a9a1aeb..60ad07ab9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -346,7 +346,8 @@ class MediaFetcher(val context: Context) { fun groupMedia(media: ArrayList, path: String): ArrayList { val mediumGroups = LinkedHashMap>() - val currentGrouping = context.config.getFolderGrouping(path) + val pathToCheck = if (path.isEmpty()) SHOW_ALL else path + val currentGrouping = context.config.getFolderGrouping(pathToCheck) if (currentGrouping and GROUP_BY_NONE != 0) { return media as ArrayList }