11package com.simplemobiletools.filemanager.pro.dialogs
22
3+ import android.view.View
34import androidx.appcompat.app.AlertDialog
45import com.simplemobiletools.commons.activities.BaseSimpleActivity
6+ import com.simplemobiletools.commons.extensions.beVisibleIf
57import com.simplemobiletools.commons.extensions.setupDialogStuff
68import com.simplemobiletools.commons.helpers.*
79import com.simplemobiletools.filemanager.pro.R
@@ -11,25 +13,36 @@ import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
1113class 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 {
0 commit comments