From 4812dff07738a99de6237f4b61dcffc1b317306e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 May 2019 21:39:10 +0200 Subject: [PATCH] fix #1400, allow toggling numeric sorting at numbers --- .../gallery/pro/dialogs/ChangeSortingDialog.kt | 12 ++++++++++-- .../gallery/pro/helpers/MediaFetcher.kt | 16 ++++++++++++++-- .../main/res/layout/dialog_change_sorting.xml | 8 ++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) 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 79c0961a6..680fbe254 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 @@ -21,11 +21,16 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti private var view: View 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) + + sorting_dialog_numeric_sorting.beVisibleIf(showFolderCheckbox) + sorting_dialog_numeric_sorting.isChecked = currSorting and SORT_USE_NUMERIC_VALUE != 0 + sorting_dialog_use_for_this_folder.beVisibleIf(showFolderCheckbox) - sorting_dialog_bottom_note.beVisibleIf(!isDirectorySorting) sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(pathToUse) + sorting_dialog_bottom_note.beVisibleIf(!isDirectorySorting) } AlertDialog.Builder(activity) @@ -35,7 +40,6 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti activity.setupDialogStuff(view, this, R.string.sort_by) } - currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(pathToUse) setupSortRadio() setupOrderRadio() } @@ -79,6 +83,10 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti sorting = sorting or SORT_DESCENDING } + if (view.sorting_dialog_numeric_sorting.isChecked) { + sorting = sorting or SORT_USE_NUMERIC_VALUE + } + if (isDirectorySorting) { config.directorySorting = sorting } else { 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 785627944..be845ac48 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 @@ -287,8 +287,20 @@ class MediaFetcher(val context: Context) { o1 as Medium o2 as Medium var result = when { - sorting and SORT_BY_NAME != 0 -> AlphanumericComparator().compare(o1.name.toLowerCase(), o2.name.toLowerCase()) - sorting and SORT_BY_PATH != 0 -> AlphanumericComparator().compare(o1.path.toLowerCase(), o2.path.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_SIZE != 0 -> o1.size.compareTo(o2.size) sorting and SORT_BY_DATE_MODIFIED != 0 -> o1.modified.compareTo(o2.modified) else -> o1.taken.compareTo(o2.taken) diff --git a/app/src/main/res/layout/dialog_change_sorting.xml b/app/src/main/res/layout/dialog_change_sorting.xml index 8d3dc7570..96fb61ad5 100644 --- a/app/src/main/res/layout/dialog_change_sorting.xml +++ b/app/src/main/res/layout/dialog_change_sorting.xml @@ -101,6 +101,14 @@ android:id="@+id/use_for_this_folder_divider" layout="@layout/divider"/> + +