From 44e07edb81ff5fb34c4fb6f7f4363d7fa7f17990 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Mar 2020 12:28:49 +0100 Subject: [PATCH] move folder sorting handling in Commons --- app/build.gradle | 2 +- .../gallery/pro/activities/MainActivity.kt | 4 ++-- .../gallery/pro/activities/MediaActivity.kt | 6 +++--- .../gallery/pro/activities/SearchActivity.kt | 2 +- .../gallery/pro/activities/ViewPagerActivity.kt | 2 +- .../gallery/pro/asynctasks/GetMediaAsynctask.kt | 4 ++-- .../gallery/pro/dialogs/ChangeSortingDialog.kt | 6 +++--- .../gallery/pro/dialogs/PickMediumDialog.kt | 2 +- .../gallery/pro/extensions/Context.kt | 4 ++-- .../gallery/pro/helpers/Config.kt | 16 ---------------- .../gallery/pro/helpers/Constants.kt | 1 - .../gallery/pro/helpers/MediaFetcher.kt | 2 +- 12 files changed, 17 insertions(+), 34 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ea94efb60..5e8ac0869 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.23.11' + implementation 'com.simplemobiletools:commons:5.23.13' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 c5d929a84..c8f2ac505 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 @@ -901,7 +901,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { return } - val sorting = config.getFileSorting(directory.path) + val sorting = config.getFolderSorting(directory.path) val grouping = config.getFolderGrouping(directory.path) val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 || sorting and SORT_BY_DATE_TAKEN != 0 || @@ -987,7 +987,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { return } - val sorting = config.getFileSorting(folder) + val sorting = config.getFolderSorting(folder) val grouping = config.getFolderGrouping(folder) val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 || sorting and SORT_BY_DATE_TAKEN != 0 || 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 06ad3005c..2eaf9f668 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 @@ -159,7 +159,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { media_empty_text_label.setTextColor(config.textColor) media_empty_text.setTextColor(getAdjustedPrimaryColor()) - if (mMedia.isEmpty() || config.getFileSorting(mPath) and SORT_BY_RANDOM == 0) { + if (mMedia.isEmpty() || config.getFolderSorting(mPath) and SORT_BY_RANDOM == 0) { tryLoadGallery() } } @@ -413,7 +413,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { media_horizontal_fastscroller.isHorizontal = true media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll) - val sorting = config.getFileSorting(if (mShowAll) SHOW_ALL else mPath) + val sorting = config.getFolderSorting(if (mShowAll) SHOW_ALL else mPath) if (allowHorizontalScroll) { media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble media_horizontal_fastscroller.setViews(media_grid, media_refresh_layout) { @@ -437,7 +437,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } private fun checkLastMediaChanged() { - if (isDestroyed || config.getFileSorting(mPath) and SORT_BY_RANDOM != 0) { + if (isDestroyed || config.getFolderSorting(mPath) and SORT_BY_RANDOM != 0) { return } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt index 69bfa3200..85dc0331a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt @@ -212,7 +212,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener { media_horizontal_fastscroller.isHorizontal = true media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll) - val sorting = config.getFileSorting(SHOW_ALL) + val sorting = config.getFolderSorting(SHOW_ALL) if (allowHorizontalScroll) { media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble media_horizontal_fastscroller.setViews(media_grid) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index c770ace40..3b62ffa8c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -1095,7 +1095,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun refreshViewPager() { - if (config.getFileSorting(mDirectory) and SORT_BY_RANDOM == 0) { + if (config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0) { GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) { gotMedia(it) }.execute() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt index c459a0b30..5cbd156d6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt @@ -20,7 +20,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage override fun doInBackground(vararg params: Void): ArrayList { val pathToUse = if (showAll) SHOW_ALL else mPath val folderGrouping = context.config.getFolderGrouping(pathToUse) - val fileSorting = context.config.getFileSorting(pathToUse) + val fileSorting = context.config.getFolderSorting(pathToUse) val getProperDateTaken = fileSorting and SORT_BY_DATE_TAKEN != 0 || folderGrouping and GROUP_BY_DATE_TAKEN_DAILY != 0 || folderGrouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0 @@ -40,7 +40,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage media.addAll(newMedia) } - mediaFetcher.sortMedia(media, context.config.getFileSorting(SHOW_ALL)) + mediaFetcher.sortMedia(media, context.config.getFolderSorting(SHOW_ALL)) media } else { mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, getVideoDurations) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt index 9db8e7b13..cffa62738 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt @@ -22,7 +22,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti private var view: View init { - currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(pathToUse) + currSorting = if (isDirectorySorting) config.directorySorting else config.getFolderSorting(pathToUse) view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null).apply { use_for_this_folder_divider.beVisibleIf(showFolderCheckbox || (currSorting and SORT_BY_NAME != 0 || currSorting and SORT_BY_PATH != 0)) @@ -97,9 +97,9 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti config.directorySorting = sorting } else { if (view.sorting_dialog_use_for_this_folder.isChecked) { - config.saveFileSorting(pathToUse, sorting) + config.saveCustomSorting(pathToUse, sorting) } else { - config.removeFileSorting(pathToUse) + config.removeCustomSorting(pathToUse) config.sorting = sorting } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt index 036b1eadf..2d9df0eb5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt @@ -73,7 +73,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c } val scrollHorizontally = activity.config.scrollHorizontally && isGridViewType - val sorting = activity.config.getFileSorting(if (path.isEmpty()) SHOW_ALL else path) + val sorting = activity.config.getFolderSorting(if (path.isEmpty()) SHOW_ALL else path) view.apply { media_grid.adapter = adapter diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 406781435..9b7f474fa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -599,7 +599,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag }) as ArrayList val pathToUse = if (path.isEmpty()) SHOW_ALL else path - mediaFetcher.sortMedia(media, config.getFileSorting(pathToUse)) + mediaFetcher.sortMedia(media, config.getFolderSorting(pathToUse)) val grouped = mediaFetcher.groupMedia(media, pathToUse) callback(grouped.clone() as ArrayList) val OTGPath = config.OTGPath @@ -865,7 +865,7 @@ fun Context.updateDirectoryPath(path: String) { val albumCovers = config.parseAlbumCovers() val includedFolders = config.includedFolders - val sorting = config.getFileSorting(path) + val sorting = config.getFolderSorting(path) val grouping = config.getFolderGrouping(path) val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 || sorting and SORT_BY_DATE_TAKEN != 0 || diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt index 68ff6268b..06663d8f1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt @@ -21,22 +21,6 @@ class Config(context: Context) : BaseConfig(context) { get(): Int = prefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING) set(order) = prefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply() - fun saveFileSorting(path: String, value: Int) { - if (path.isEmpty()) { - sorting = value - } else { - prefs.edit().putInt(SORT_FOLDER_PREFIX + path.toLowerCase(), value).apply() - } - } - - fun getFileSorting(path: String) = prefs.getInt(SORT_FOLDER_PREFIX + path.toLowerCase(), sorting) - - fun removeFileSorting(path: String) { - prefs.edit().remove(SORT_FOLDER_PREFIX + path.toLowerCase()).apply() - } - - fun hasCustomSorting(path: String) = prefs.contains(SORT_FOLDER_PREFIX + path.toLowerCase()) - fun saveFolderGrouping(path: String, value: Int) { if (path.isEmpty()) { groupBy = value diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 248cf6393..d6d6abef0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -4,7 +4,6 @@ import com.simplemobiletools.commons.helpers.MONTH_SECONDS // shared preferences const val DIRECTORY_SORT_ORDER = "directory_sort_order" -const val SORT_FOLDER_PREFIX = "sort_folder_" const val GROUP_FOLDER_PREFIX = "group_folder_" const val VIEW_TYPE_PREFIX = "view_type_folder_" const val SHOW_HIDDEN_MEDIA = "show_hidden_media" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index e463da1f8..4edf2d8dc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -38,7 +38,7 @@ class MediaFetcher(val context: Context) { curMedia.addAll(newMedia) } - sortMedia(curMedia, context.config.getFileSorting(curPath)) + sortMedia(curMedia, context.config.getFolderSorting(curPath)) return curMedia }