Move message list menu item handling code to MessageListFragment

This commit is contained in:
cketti 2022-07-19 15:32:27 +02:00
parent 9f45fe1d46
commit 42daa056fd
2 changed files with 15 additions and 74 deletions

View file

@ -26,7 +26,6 @@ import androidx.fragment.app.FragmentTransaction
import androidx.fragment.app.commit
import androidx.lifecycle.Observer
import com.fsck.k9.Account
import com.fsck.k9.Account.SortType
import com.fsck.k9.K9
import com.fsck.k9.K9.SplitViewMode
import com.fsck.k9.Preferences
@ -917,45 +916,12 @@ open class MessageList :
goBack()
}
return true
} else if (id == R.id.compose) {
messageListFragment!!.onCompose()
return true
} else if (id == R.id.toggle_message_view_theme) {
onToggleTheme()
return true
} else if (id == R.id.set_sort_date) { // MessageList
messageListFragment!!.changeSort(SortType.SORT_DATE)
return true
} else if (id == R.id.set_sort_arrival) {
messageListFragment!!.changeSort(SortType.SORT_ARRIVAL)
return true
} else if (id == R.id.set_sort_subject) {
messageListFragment!!.changeSort(SortType.SORT_SUBJECT)
return true
} else if (id == R.id.set_sort_sender) {
messageListFragment!!.changeSort(SortType.SORT_SENDER)
return true
} else if (id == R.id.set_sort_flag) {
messageListFragment!!.changeSort(SortType.SORT_FLAGGED)
return true
} else if (id == R.id.set_sort_unread) {
messageListFragment!!.changeSort(SortType.SORT_UNREAD)
return true
} else if (id == R.id.set_sort_attach) {
messageListFragment!!.changeSort(SortType.SORT_ATTACHMENT)
return true
} else if (id == R.id.select_all) {
messageListFragment!!.selectAll()
return true
} else if (id == R.id.search_remote) {
messageListFragment!!.onRemoteSearch()
return true
} else if (id == R.id.search_everywhere) {
searchEverywhere()
return true
} else if (id == R.id.mark_all_as_read) {
messageListFragment!!.confirmMarkAllAsRead()
return true
} else if (id == R.id.next_message) { // MessageView
showNextMessage()
return true
@ -1009,29 +975,7 @@ open class MessageList :
return true
}
if (!singleFolderMode) {
// 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
}
return when (id) {
R.id.send_messages -> {
messageListFragment!!.onSendPendingMessages()
true
}
R.id.expunge -> {
messageListFragment!!.onExpunge()
true
}
R.id.empty_trash -> {
messageListFragment!!.onEmptyTrash()
true
}
else -> {
super.onOptionsItemSelected(item)
}
}
return super.onOptionsItemSelected(item)
}
private fun searchEverywhere() {

View file

@ -115,10 +115,8 @@ class MessageListFragment :
private set
var isSingleAccountMode = false
private set
var isSingleFolderMode = false
private set
var isRemoteSearch = false
private set
private var isSingleFolderMode = false
private var isRemoteSearch = false
private val isUnifiedInbox: Boolean
get() = localSearch.id == SearchAccount.UNIFIED_INBOX
@ -130,8 +128,7 @@ class MessageListFragment :
* `true` after [.onCreate] was executed. Used in [.updateTitle] to
* make sure we don't access member variables before initialization is complete.
*/
var isInitialized = false
private set
private var isInitialized = false
private var isListVisible = false
@ -507,7 +504,7 @@ class MessageListFragment :
}
}
fun changeSort(sortType: SortType) {
private fun changeSort(sortType: SortType) {
val sortAscending = if (this.sortType == sortType) !sortAscending else null
changeSort(sortType, sortAscending)
}
@ -629,17 +626,13 @@ class MessageListFragment :
}
}
fun onExpunge() {
private fun onExpunge() {
currentFolder?.let { folderInfoHolder ->
onExpunge(account, folderInfoHolder.databaseId)
messagingController.expunge(account, folderInfoHolder.databaseId)
}
}
private fun onExpunge(account: Account?, folderId: Long) {
messagingController.expunge(account, folderId)
}
fun onEmptyTrash() {
private fun onEmptyTrash() {
if (isShowingTrashFolder) {
showDialog(R.id.dialog_confirm_empty_trash)
}
@ -746,6 +739,8 @@ class MessageListFragment :
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.search_remote -> onRemoteSearch()
R.id.compose -> onCompose()
R.id.set_sort_date -> changeSort(SortType.SORT_DATE)
R.id.set_sort_arrival -> changeSort(SortType.SORT_ARRIVAL)
R.id.set_sort_subject -> changeSort(SortType.SORT_SUBJECT)
@ -754,7 +749,9 @@ class MessageListFragment :
R.id.set_sort_unread -> changeSort(SortType.SORT_UNREAD)
R.id.set_sort_attach -> changeSort(SortType.SORT_ATTACHMENT)
R.id.select_all -> selectAll()
R.id.mark_all_as_read -> confirmMarkAllAsRead()
R.id.send_messages -> onSendPendingMessages()
R.id.empty_trash -> onEmptyTrash()
R.id.expunge -> onExpunge()
else -> return super.onOptionsItemSelected(item)
}
@ -762,7 +759,7 @@ class MessageListFragment :
return true
}
fun onSendPendingMessages() {
private fun onSendPendingMessages() {
messagingController.sendPendingMessages(account, null)
}
@ -1448,7 +1445,7 @@ class MessageListFragment :
return account.expungePolicy == Expunge.EXPUNGE_MANUALLY && messagingController.supportsExpunge(account)
}
fun onRemoteSearch() {
private fun onRemoteSearch() {
// Remote search is useless without the network.
if (hasConnectivity == true) {
onRemoteSearchRequested()
@ -1579,7 +1576,7 @@ class MessageListFragment :
private val isMarkAllAsReadSupported: Boolean
get() = isSingleAccountMode && isSingleFolderMode && !isOutbox
fun confirmMarkAllAsRead() {
private fun confirmMarkAllAsRead() {
if (K9.isConfirmMarkAllRead) {
showDialog(R.id.dialog_confirm_mark_all_as_read)
} else {