Added custom sorting (#464)

This commit is contained in:
Agnieszka C
2021-10-12 15:49:30 +02:00
parent fd14f01f1f
commit 23cdd2511b
4 changed files with 42 additions and 7 deletions

View File

@ -1,7 +1,9 @@
package com.simplemobiletools.notes.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_CREATED
import com.simplemobiletools.commons.helpers.SORT_BY_TITLE
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
@ -29,12 +31,24 @@ class SortChecklistDialog(private val activity: SimpleActivity, private val call
private fun setupSortRadio() {
val fieldRadio = view.sorting_dialog_radio_sorting
fieldRadio.setOnCheckedChangeListener { group, checkedId ->
val isCustomSorting = checkedId == fieldRadio.sorting_dialog_radio_custom.id
view.sorting_dialog_radio_order.beVisibleIf(!isCustomSorting)
view.sorting_dialog_order_divider.beVisibleIf(!isCustomSorting)
view.move_undone_checklist_items_divider.beVisibleIf((!isCustomSorting))
view.settings_move_undone_checklist_items_holder.beVisibleIf(!isCustomSorting)
}
var fieldBtn = fieldRadio.sorting_dialog_radio_title
if (currSorting and SORT_BY_DATE_CREATED != 0) {
fieldBtn = fieldRadio.sorting_dialog_radio_date_created
}
if (currSorting and SORT_BY_CUSTOM != 0) {
fieldBtn = fieldRadio.sorting_dialog_radio_custom
}
fieldBtn.isChecked = true
}
@ -60,10 +74,12 @@ class SortChecklistDialog(private val activity: SimpleActivity, private val call
val sortingRadio = view.sorting_dialog_radio_sorting
var sorting = when (sortingRadio.checkedRadioButtonId) {
R.id.sorting_dialog_radio_date_created -> SORT_BY_DATE_CREATED
R.id.sorting_dialog_radio_custom -> SORT_BY_CUSTOM
else -> SORT_BY_TITLE
}
if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
if (sortingRadio.checkedRadioButtonId != R.id.sorting_dialog_radio_custom
&& view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
sorting = sorting or SORT_DESCENDING
}