Refactor code to configure the message list action mode menu
@@ -1364,15 +1364,21 @@ class MessageListFragment :
}
val isOutbox: Boolean
- get() {
- val currentFolder = currentFolder ?: return false
- return currentFolder.databaseId == account!!.outboxFolderId
- }
+ get() = isSpecialFolder(account?.outboxFolderId)
private val isInbox: Boolean
- get() {
+ get() = isSpecialFolder(account?.inboxFolderId)
+
+ private val isArchiveFolder: Boolean
+ get() = isSpecialFolder(account?.archiveFolderId)
+
+ private val isSpamFolder: Boolean
+ get() = isSpecialFolder(account?.spamFolderId)
+
+ private fun isSpecialFolder(specialFolderId: Long?): Boolean {
+ val folderId = specialFolderId ?: return false
val currentFolder = currentFolder ?: return false
- return currentFolder.databaseId == account!!.inboxFolderId
+ return currentFolder.databaseId == folderId
}
val isRemoteFolder: Boolean
@@ -1775,29 +1781,7 @@ class MessageListFragment :
if (account?.hasSpamFolder() == true) {
menu.findItem(R.id.spam).isVisible = true
}
- } else {
- // hide unsupported
- if (!messagingController.isCopyCapable(account)) {
- menu.findItem(R.id.copy).isVisible = false
- }
-
- if (!messagingController.isMoveCapable(account)) {
- menu.findItem(R.id.move).isVisible = false
- menu.findItem(R.id.archive).isVisible = false
- menu.findItem(R.id.spam).isVisible = false
- }
-
- val hideArchiveAction = isSingleFolderMode && currentFolder!!.databaseId == account.archiveFolderId
- if (hideArchiveAction) {
- menu.findItem(R.id.archive).isVisible = false
- }
-
- val hideSpamAction = isSingleFolderMode && currentFolder!!.databaseId == account.spamFolderId
- if (hideSpamAction) {
- menu.findItem(R.id.spam).isVisible = false
- }
-
- if (isOutbox) {
+ } else if (isOutbox) {
menu.findItem(R.id.mark_as_read).isVisible = false
menu.findItem(R.id.mark_as_unread).isVisible = false
menu.findItem(R.id.archive).isVisible = false
@@ -1813,6 +1797,23 @@ class MessageListFragment :
if (account.hasDraftsFolder()) {
menu.findItem(R.id.move_to_drafts).isVisible = true
}
+ } else {
+ if (!messagingController.isCopyCapable(account)) {
+ menu.findItem(R.id.copy).isVisible = false
+ }
+
+ if (!messagingController.isMoveCapable(account)) {
+ menu.findItem(R.id.move).isVisible = false
+ menu.findItem(R.id.archive).isVisible = false
+ menu.findItem(R.id.spam).isVisible = false
+ } else {
+ if (isArchiveFolder) {
+ menu.findItem(R.id.archive).isVisible = false
+ }
+
+ if (isSpamFolder) {
+ menu.findItem(R.id.spam).isVisible = false
+ }
}
}
}
