Refactor MessageListFragment.onOptionsItemSelected()

This commit is contained in:
cketti 2022-07-19 15:13:29 +02:00
parent 4486782166
commit 9f45fe1d46

View file

@ -745,50 +745,21 @@ class MessageListFragment :
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
val id = item.itemId when (item.itemId) {
if (id == R.id.set_sort_date) { R.id.set_sort_date -> changeSort(SortType.SORT_DATE)
changeSort(SortType.SORT_DATE) R.id.set_sort_arrival -> changeSort(SortType.SORT_ARRIVAL)
return true R.id.set_sort_subject -> changeSort(SortType.SORT_SUBJECT)
} else if (id == R.id.set_sort_arrival) { R.id.set_sort_sender -> changeSort(SortType.SORT_SENDER)
changeSort(SortType.SORT_ARRIVAL) R.id.set_sort_flag -> changeSort(SortType.SORT_FLAGGED)
return true R.id.set_sort_unread -> changeSort(SortType.SORT_UNREAD)
} else if (id == R.id.set_sort_subject) { R.id.set_sort_attach -> changeSort(SortType.SORT_ATTACHMENT)
changeSort(SortType.SORT_SUBJECT) R.id.select_all -> selectAll()
return true R.id.send_messages -> onSendPendingMessages()
} else if (id == R.id.set_sort_sender) { R.id.expunge -> onExpunge()
changeSort(SortType.SORT_SENDER) else -> return super.onOptionsItemSelected(item)
return true
} else if (id == R.id.set_sort_flag) {
changeSort(SortType.SORT_FLAGGED)
return true
} else if (id == R.id.set_sort_unread) {
changeSort(SortType.SORT_UNREAD)
return true
} else if (id == R.id.set_sort_attach) {
changeSort(SortType.SORT_ATTACHMENT)
return true
} else if (id == R.id.select_all) {
selectAll()
return true
} }
if (!isSingleAccountMode) { return true
// None of the options after this point are "safe" for search results
// TODO: This is not true for "unread" and "starred" searches in regular folders
return false
}
if (id == R.id.send_messages) {
onSendPendingMessages()
return true
} else if (id == R.id.expunge) {
currentFolder?.let { folderInfoHolder ->
onExpunge(account, folderInfoHolder.databaseId)
}
return true
} else {
return super.onOptionsItemSelected(item)
}
} }
fun onSendPendingMessages() { fun onSendPendingMessages() {