From 5db37d6c5491fad449c247fefb20e70985df4316 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 23:52:42 +0200 Subject: [PATCH] allow sorting Show All separately --- .../gallery/activities/MediaActivity.kt | 4 ++-- .../gallery/asynctasks/GetMediaAsynctask.kt | 7 ++++--- .../gallery/dialogs/ChangeSortingDialog.kt | 10 ++++++---- .../gallery/dialogs/PickMediumDialog.kt | 3 ++- .../simplemobiletools/gallery/extensions/Context.kt | 5 +++-- 5 files changed, 17 insertions(+), 12 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 6bd103889..6d928ecde 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -362,7 +362,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_horizontal_fastscroller.isHorizontal = true media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll) - val sorting = config.getFileSorting(mPath) + val sorting = config.getFileSorting(if (mShowAll) SHOW_ALL else mPath) if (allowHorizontalScroll) { media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble media_horizontal_fastscroller.setViews(media_grid, media_refresh_layout) { @@ -409,7 +409,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun showSortingDialog() { - ChangeSortingDialog(this, false, !config.showAll, mPath) { + ChangeSortingDialog(this, false, true, mPath) { mLoadedInitialPhotos = false media_grid.adapter = null getMedia() 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 27af8bee5..e4b0aa1d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -17,7 +17,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage private val mediaFetcher = MediaFetcher(context) override fun doInBackground(vararg params: Void): ArrayList { - val getProperDateTaken = context.config.getFileSorting(mPath) and SORT_BY_DATE_TAKEN != 0 + val pathToUse = if (showAll) SHOW_ALL else mPath + val getProperDateTaken = context.config.getFileSorting(pathToUse) and SORT_BY_DATE_TAKEN != 0 val favoritePaths = context.getFavoritePaths() val media = if (showAll) { val foldersToScan = mediaFetcher.getFoldersToScan() @@ -27,12 +28,12 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage media.addAll(newMedia) } - mediaFetcher.sortMedia(media, context.config.getFileSorting("")) + mediaFetcher.sortMedia(media, context.config.getFileSorting(SHOW_ALL)) media } else { mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) } - return mediaFetcher.groupMedia(media, if (showAll) SHOW_ALL else mPath) + return mediaFetcher.groupMedia(media, pathToUse) } override fun onPostExecute(media: ArrayList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt index fffac4f25..dc26bb6bf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt @@ -9,6 +9,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.SHOW_ALL import kotlinx.android.synthetic.main.dialog_change_sorting.view.* class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorting: Boolean, showFolderCheckbox: Boolean, @@ -16,13 +17,14 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti DialogInterface.OnClickListener { private var currSorting = 0 private var config = activity.config + private var pathToUse = if (!isDirectorySorting && path.isEmpty()) SHOW_ALL else path private var view: View init { view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null).apply { use_for_this_folder_divider.beVisibleIf(showFolderCheckbox) sorting_dialog_use_for_this_folder.beVisibleIf(showFolderCheckbox) - sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path) + sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(pathToUse) } AlertDialog.Builder(activity) @@ -32,7 +34,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti activity.setupDialogStuff(view, this, R.string.sort_by) } - currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(path) + currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(pathToUse) setupSortRadio() setupOrderRadio() } @@ -78,9 +80,9 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti config.directorySorting = sorting } else { if (view.sorting_dialog_use_for_this_folder.isChecked) { - config.saveFileSorting(path, sorting) + config.saveFileSorting(pathToUse, sorting) } else { - config.removeFileSorting(path) + config.removeFileSorting(pathToUse) config.sorting = sorting } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index 1a45671cb..65cb91e25 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getCachedMedia +import com.simplemobiletools.gallery.helpers.SHOW_ALL import com.simplemobiletools.gallery.helpers.VIEW_TYPE_GRID import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.ThumbnailItem @@ -71,7 +72,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c } val scrollHorizontally = activity.config.scrollHorizontally && isGridViewType - val sorting = activity.config.getFileSorting(path) + val sorting = activity.config.getFileSorting(if (path.isEmpty()) SHOW_ALL else path) view.apply { media_grid.adapter = adapter diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index 086102b1e..4a5cb6348 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -360,8 +360,9 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag } }) as ArrayList - mediaFetcher.sortMedia(media, config.getFileSorting(path)) - val grouped = mediaFetcher.groupMedia(media, path) + val pathToUse = if (path.isEmpty()) SHOW_ALL else path + mediaFetcher.sortMedia(media, config.getFileSorting(pathToUse)) + val grouped = mediaFetcher.groupMedia(media, pathToUse) callback(grouped.clone() as ArrayList) val recycleBinPath = filesDir.toString()