Skip to content

Commit e665c38

Browse files
committed
allow sorting items by proper numeric values in their names
1 parent 809984c commit e665c38

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ android {
5858
}
5959

6060
dependencies {
61-
implementation 'com.simplemobiletools:commons:5.28.24'
61+
implementation 'com.simplemobiletools:commons:5.29.1'
6262
implementation 'com.github.Stericson:RootTools:df729dcb13'
6363
implementation 'com.github.Stericson:RootShell:1.6'
6464
implementation 'com.alexvasilkov:gesture-views:2.5.2'

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/ChangeSortingDialog.kt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.simplemobiletools.filemanager.pro.dialogs
22

3+
import android.view.View
34
import androidx.appcompat.app.AlertDialog
45
import com.simplemobiletools.commons.activities.BaseSimpleActivity
6+
import com.simplemobiletools.commons.extensions.beVisibleIf
57
import com.simplemobiletools.commons.extensions.setupDialogStuff
68
import com.simplemobiletools.commons.helpers.*
79
import com.simplemobiletools.filemanager.pro.R
@@ -11,25 +13,36 @@ import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
1113
class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = "", val callback: () -> Unit) {
1214
private var currSorting = 0
1315
private var config = activity.config
14-
private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null)
16+
private var view: View
1517

1618
init {
17-
view.sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
19+
currSorting = config.getFolderSorting(path)
20+
view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null).apply {
21+
sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
22+
23+
sorting_dialog_numeric_sorting.beVisibleIf(currSorting and SORT_BY_NAME != 0)
24+
sorting_dialog_numeric_sorting.isChecked = currSorting and SORT_USE_NUMERIC_VALUE != 0
25+
}
1826

1927
AlertDialog.Builder(activity)
20-
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
21-
.setNegativeButton(R.string.cancel, null)
22-
.create().apply {
23-
activity.setupDialogStuff(view, this, R.string.sort_by)
24-
}
28+
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
29+
.setNegativeButton(R.string.cancel, null)
30+
.create().apply {
31+
activity.setupDialogStuff(view, this, R.string.sort_by)
32+
}
2533

26-
currSorting = config.getFolderSorting(path)
2734
setupSortRadio()
2835
setupOrderRadio()
2936
}
3037

3138
private fun setupSortRadio() {
3239
val sortingRadio = view.sorting_dialog_radio_sorting
40+
41+
sortingRadio.setOnCheckedChangeListener { group, checkedId ->
42+
val isSortingByName = checkedId == sortingRadio.sorting_dialog_radio_name.id
43+
view.sorting_dialog_numeric_sorting.beVisibleIf(isSortingByName)
44+
}
45+
3346
val sortBtn = when {
3447
currSorting and SORT_BY_SIZE != 0 -> sortingRadio.sorting_dialog_radio_size
3548
currSorting and SORT_BY_DATE_MODIFIED != 0 -> sortingRadio.sorting_dialog_radio_last_modified
@@ -62,6 +75,10 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = "
6275
sorting = sorting or SORT_DESCENDING
6376
}
6477

78+
if (view.sorting_dialog_numeric_sorting.isChecked) {
79+
sorting = sorting or SORT_USE_NUMERIC_VALUE
80+
}
81+
6582
if (view.sorting_dialog_use_for_this_folder.isChecked) {
6683
config.saveCustomSorting(path, sorting)
6784
} else {

app/src/main/res/layout/dialog_change_sorting.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,21 @@
8383
android:id="@+id/use_for_this_folder_divider"
8484
layout="@layout/divider" />
8585

86+
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
87+
android:id="@+id/sorting_dialog_numeric_sorting"
88+
android:layout_width="match_parent"
89+
android:layout_height="wrap_content"
90+
android:layout_marginTop="@dimen/small_margin"
91+
android:paddingTop="@dimen/normal_margin"
92+
android:paddingBottom="@dimen/normal_margin"
93+
android:text="@string/sort_numeric_parts" />
94+
8695
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
8796
android:id="@+id/sorting_dialog_use_for_this_folder"
8897
android:layout_width="match_parent"
8998
android:layout_height="wrap_content"
90-
android:paddingTop="@dimen/activity_margin"
91-
android:paddingBottom="@dimen/activity_margin"
99+
android:paddingTop="@dimen/normal_margin"
100+
android:paddingBottom="@dimen/normal_margin"
92101
android:text="@string/use_for_this_folder" />
93102

94103
</LinearLayout>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<integer name="default_sorting">32769</integer>
3+
</resources>

0 commit comments

Comments
 (0)