list: fix sort dialog allowing invalid sorts

If you changed the mode but disabled the direction, you would wind up
with an outright invalid sort that you could still save. Fix that.
This commit is contained in:
Alexander Capehart 2024-10-22 22:02:40 -06:00
parent 97b0a8aa68
commit 018e142ee9
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -96,17 +96,17 @@ abstract class SortDialog :
private fun updateButtons() { private fun updateButtons() {
val binding = requireBinding() val binding = requireBinding()
binding.sortSave.isEnabled = getCurrentSort() != getInitialSort() binding.sortSave.isEnabled = getCurrentSort().let { it != null && it != getInitialSort() }
} }
private fun getCurrentSort(): Sort? { private fun getCurrentSort(): Sort? {
val initial = getInitialSort() val initial = getInitialSort()
val mode = modeAdapter.currentMode ?: initial?.mode ?: return null val mode = modeAdapter.currentMode ?: return null
val direction = val direction =
when (requireBinding().sortDirectionGroup.checkedButtonId) { when (requireBinding().sortDirectionGroup.checkedButtonId) {
R.id.sort_direction_asc -> Sort.Direction.ASCENDING R.id.sort_direction_asc -> Sort.Direction.ASCENDING
R.id.sort_direction_dsc -> Sort.Direction.DESCENDING R.id.sort_direction_dsc -> Sort.Direction.DESCENDING
else -> initial?.direction ?: return null else -> return null
} }
return Sort(mode, direction) return Sort(mode, direction)
} }