From d6c5b967224a60fb3d19786665e97e89245a7f96 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 8 May 2019 20:46:26 +0200 Subject: [PATCH] allow toggling numeric sorting at folders too --- app/build.gradle | 2 +- .../gallery/pro/dialogs/ChangeSortingDialog.kt | 9 ++++++--- .../gallery/pro/extensions/Context.kt | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 950e7c673..720cd73a8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,7 +61,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.12.15' + implementation 'com.simplemobiletools:commons:5.12.17' 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/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeSortingDialog.kt index c1286a7e4..9db8e7b13 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 @@ -5,6 +5,7 @@ import android.view.View import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.isVisible import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.pro.R @@ -12,7 +13,7 @@ import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.helpers.SHOW_ALL import kotlinx.android.synthetic.main.dialog_change_sorting.view.* -class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorting: Boolean, showFolderCheckbox: Boolean, +class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorting: Boolean, val showFolderCheckbox: Boolean, val path: String = "", val callback: () -> Unit) : DialogInterface.OnClickListener { private var currSorting = 0 @@ -23,7 +24,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti init { currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(pathToUse) view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null).apply { - use_for_this_folder_divider.beVisibleIf(showFolderCheckbox) + use_for_this_folder_divider.beVisibleIf(showFolderCheckbox || (currSorting and SORT_BY_NAME != 0 || currSorting and SORT_BY_PATH != 0)) sorting_dialog_numeric_sorting.beVisibleIf(showFolderCheckbox && (currSorting and SORT_BY_NAME != 0 || currSorting and SORT_BY_PATH != 0)) sorting_dialog_numeric_sorting.isChecked = currSorting and SORT_USE_NUMERIC_VALUE != 0 @@ -47,7 +48,9 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti private fun setupSortRadio() { val sortingRadio = view.sorting_dialog_radio_sorting sortingRadio.setOnCheckedChangeListener { group, checkedId -> - view.sorting_dialog_numeric_sorting.beVisibleIf(checkedId == sortingRadio.sorting_dialog_radio_name.id || checkedId == sortingRadio.sorting_dialog_radio_path.id) + val isSortingByNameOrPath = checkedId == sortingRadio.sorting_dialog_radio_name.id || checkedId == sortingRadio.sorting_dialog_radio_path.id + view.sorting_dialog_numeric_sorting.beVisibleIf(isSortingByNameOrPath) + view.use_for_this_folder_divider.beVisibleIf(view.sorting_dialog_numeric_sorting.isVisible() || view.sorting_dialog_use_for_this_folder.isVisible()) } val sortBtn = when { 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 972443d7b..59cb44f5e 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 @@ -165,7 +165,20 @@ fun Context.getSortedDirectories(source: ArrayList): ArrayList AlphanumericComparator().compare(o1.name.toLowerCase(), o2.name.toLowerCase()) + sorting and SORT_BY_NAME != 0 -> { + if (sorting and SORT_USE_NUMERIC_VALUE != 0) { + AlphanumericComparator().compare(o1.name.toLowerCase(), o2.name.toLowerCase()) + } else { + o1.name.toLowerCase().compareTo(o2.name.toLowerCase()) + } + } + sorting and SORT_BY_PATH != 0 -> { + if (sorting and SORT_USE_NUMERIC_VALUE != 0) { + AlphanumericComparator().compare(o1.path.toLowerCase(), o2.path.toLowerCase()) + } else { + o1.path.toLowerCase().compareTo(o2.path.toLowerCase()) + } + } sorting and SORT_BY_PATH != 0 -> AlphanumericComparator().compare(o1.path.toLowerCase(), o2.path.toLowerCase()) sorting and SORT_BY_SIZE != 0 -> o1.size.compareTo(o2.size) sorting and SORT_BY_DATE_MODIFIED != 0 -> o1.modified.compareTo(o2.modified)