Move code to prepare the message view menu to MessageViewFragment
This commit is contained in:
parent
52f9b9dd9f
commit
03de64e84c
3 changed files with 97 additions and 120 deletions
|
@ -1011,126 +1011,6 @@ open class MessageList :
|
|||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
configureMenu(menu)
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide menu items not appropriate for the current context.
|
||||
*
|
||||
* **Note:**
|
||||
* Please adjust the comments in `res/menu/message_list_option.xml` if you change the visibility of a menu item
|
||||
* in this method.
|
||||
*/
|
||||
private fun configureMenu(menu: Menu?) {
|
||||
if (menu == null) return
|
||||
|
||||
// Set visibility of menu items related to the message view
|
||||
if (displayMode == DisplayMode.MESSAGE_LIST || messageViewFragment == null ||
|
||||
!messageViewFragment!!.isInitialized
|
||||
) {
|
||||
menu.findItem(R.id.next_message).isVisible = false
|
||||
menu.findItem(R.id.previous_message).isVisible = false
|
||||
menu.findItem(R.id.single_message_options).isVisible = false
|
||||
menu.findItem(R.id.delete).isVisible = false
|
||||
menu.findItem(R.id.compose).isVisible = false
|
||||
menu.findItem(R.id.archive).isVisible = false
|
||||
menu.findItem(R.id.move).isVisible = false
|
||||
menu.findItem(R.id.copy).isVisible = false
|
||||
menu.findItem(R.id.spam).isVisible = false
|
||||
menu.findItem(R.id.refile).isVisible = false
|
||||
menu.findItem(R.id.toggle_unread).isVisible = false
|
||||
menu.findItem(R.id.toggle_message_view_theme).isVisible = false
|
||||
menu.findItem(R.id.unsubscribe).isVisible = false
|
||||
menu.findItem(R.id.show_headers).isVisible = false
|
||||
} else {
|
||||
// hide prev/next buttons in split mode
|
||||
if (displayMode != DisplayMode.MESSAGE_VIEW) {
|
||||
menu.findItem(R.id.next_message).isVisible = false
|
||||
menu.findItem(R.id.previous_message).isVisible = false
|
||||
} else {
|
||||
val ref = messageViewFragment!!.messageReference
|
||||
val initialized = messageListFragment != null &&
|
||||
messageListFragment!!.isLoadFinished
|
||||
val canDoPrev = initialized && !messageListFragment!!.isFirst(ref)
|
||||
val canDoNext = initialized && !messageListFragment!!.isLast(ref)
|
||||
val prev = menu.findItem(R.id.previous_message)
|
||||
prev.isEnabled = canDoPrev
|
||||
prev.icon.alpha = if (canDoPrev) 255 else 127
|
||||
val next = menu.findItem(R.id.next_message)
|
||||
next.isEnabled = canDoNext
|
||||
next.icon.alpha = if (canDoNext) 255 else 127
|
||||
}
|
||||
|
||||
val toggleTheme = menu.findItem(R.id.toggle_message_view_theme)
|
||||
if (generalSettingsManager.getSettings().fixedMessageViewTheme) {
|
||||
toggleTheme.isVisible = false
|
||||
} else {
|
||||
// Set title of menu item to switch to dark/light theme
|
||||
if (themeManager.messageViewTheme === Theme.DARK) {
|
||||
toggleTheme.setTitle(R.string.message_view_theme_action_light)
|
||||
} else {
|
||||
toggleTheme.setTitle(R.string.message_view_theme_action_dark)
|
||||
}
|
||||
toggleTheme.isVisible = true
|
||||
}
|
||||
|
||||
if (messageViewFragment!!.isOutbox) {
|
||||
menu.findItem(R.id.toggle_unread).isVisible = false
|
||||
} else {
|
||||
// Set title of menu item to toggle the read state of the currently displayed message
|
||||
val drawableAttr = if (messageViewFragment!!.isMessageRead) {
|
||||
menu.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_unread_action)
|
||||
intArrayOf(R.attr.iconActionMarkAsUnread)
|
||||
} else {
|
||||
menu.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_read_action)
|
||||
intArrayOf(R.attr.iconActionMarkAsRead)
|
||||
}
|
||||
val typedArray = obtainStyledAttributes(drawableAttr)
|
||||
menu.findItem(R.id.toggle_unread).icon = typedArray.getDrawable(0)
|
||||
typedArray.recycle()
|
||||
}
|
||||
|
||||
menu.findItem(R.id.delete).isVisible = K9.isMessageViewDeleteActionVisible
|
||||
|
||||
// Set visibility of copy, move, archive, spam in action bar and refile submenu
|
||||
if (messageViewFragment!!.isCopyCapable) {
|
||||
menu.findItem(R.id.copy).isVisible = K9.isMessageViewCopyActionVisible
|
||||
menu.findItem(R.id.refile_copy).isVisible = true
|
||||
} else {
|
||||
menu.findItem(R.id.copy).isVisible = false
|
||||
menu.findItem(R.id.refile_copy).isVisible = false
|
||||
}
|
||||
|
||||
if (messageViewFragment!!.isMoveCapable) {
|
||||
val canMessageBeArchived = messageViewFragment!!.canMessageBeArchived()
|
||||
val canMessageBeMovedToSpam = messageViewFragment!!.canMessageBeMovedToSpam()
|
||||
|
||||
menu.findItem(R.id.move).isVisible = K9.isMessageViewMoveActionVisible
|
||||
menu.findItem(R.id.archive).isVisible = canMessageBeArchived && K9.isMessageViewArchiveActionVisible
|
||||
menu.findItem(R.id.spam).isVisible = canMessageBeMovedToSpam && K9.isMessageViewSpamActionVisible
|
||||
|
||||
menu.findItem(R.id.refile_move).isVisible = true
|
||||
menu.findItem(R.id.refile_archive).isVisible = canMessageBeArchived
|
||||
menu.findItem(R.id.refile_spam).isVisible = canMessageBeMovedToSpam
|
||||
} else {
|
||||
menu.findItem(R.id.move).isVisible = false
|
||||
menu.findItem(R.id.archive).isVisible = false
|
||||
menu.findItem(R.id.spam).isVisible = false
|
||||
|
||||
menu.findItem(R.id.refile).isVisible = false
|
||||
}
|
||||
|
||||
if (messageViewFragment!!.isOutbox) {
|
||||
menu.findItem(R.id.move_to_drafts).isVisible = true
|
||||
}
|
||||
|
||||
menu.findItem(R.id.unsubscribe).isVisible = messageViewFragment!!.canMessageBeUnsubscribed()
|
||||
}
|
||||
}
|
||||
|
||||
fun setActionBarTitle(title: String, subtitle: String? = null) {
|
||||
actionBar.title = title
|
||||
actionBar.subtitle = subtitle
|
||||
|
|
|
@ -11,15 +11,19 @@ import android.os.Parcelable
|
|||
import android.os.SystemClock
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.withStyledAttributes
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.K9
|
||||
import com.fsck.k9.activity.MessageCompose
|
||||
import com.fsck.k9.activity.MessageList
|
||||
import com.fsck.k9.activity.MessageLoaderHelper
|
||||
import com.fsck.k9.activity.MessageLoaderHelper.MessageLoaderCallbacks
|
||||
import com.fsck.k9.activity.MessageLoaderHelperFactory
|
||||
|
@ -36,7 +40,9 @@ import com.fsck.k9.mailstore.AttachmentViewInfo
|
|||
import com.fsck.k9.mailstore.LocalMessage
|
||||
import com.fsck.k9.mailstore.MessageViewInfo
|
||||
import com.fsck.k9.preferences.AccountManager
|
||||
import com.fsck.k9.preferences.GeneralSettingsManager
|
||||
import com.fsck.k9.ui.R
|
||||
import com.fsck.k9.ui.base.Theme
|
||||
import com.fsck.k9.ui.base.ThemeManager
|
||||
import com.fsck.k9.ui.choosefolder.ChooseFolderActivity
|
||||
import com.fsck.k9.ui.messageview.CryptoInfoDialog.OnClickShowCryptoKeyListener
|
||||
|
@ -60,6 +66,7 @@ class MessageViewFragment :
|
|||
private val accountManager: AccountManager by inject()
|
||||
private val messagingController: MessagingController by inject()
|
||||
private val shareIntentBuilder: ShareIntentBuilder by inject()
|
||||
private val generalSettingsManager: GeneralSettingsManager by inject()
|
||||
|
||||
private lateinit var messageTopView: MessageTopView
|
||||
|
||||
|
@ -180,6 +187,83 @@ class MessageViewFragment :
|
|||
}
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
menu.findItem(R.id.delete).isVisible = K9.isMessageViewDeleteActionVisible
|
||||
|
||||
val showToggleUnread = !isOutbox
|
||||
menu.findItem(R.id.toggle_unread).isVisible = showToggleUnread
|
||||
|
||||
if (showToggleUnread) {
|
||||
// Set title of menu item to toggle the read state of the currently displayed message
|
||||
if (isMessageRead) {
|
||||
menu.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_unread_action)
|
||||
} else {
|
||||
menu.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_read_action)
|
||||
}
|
||||
|
||||
val drawableAttr = if (isMessageRead) {
|
||||
intArrayOf(R.attr.iconActionMarkAsUnread)
|
||||
} else {
|
||||
intArrayOf(R.attr.iconActionMarkAsRead)
|
||||
}
|
||||
|
||||
requireContext().withStyledAttributes(attrs = drawableAttr) {
|
||||
menu.findItem(R.id.toggle_unread).icon = getDrawable(0)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Remove previous/next actions
|
||||
menu.findItem(R.id.next_message).isVisible = false
|
||||
menu.findItem(R.id.previous_message).isVisible = false
|
||||
|
||||
if (isMoveCapable) {
|
||||
val canMessageBeArchived = canMessageBeArchived()
|
||||
val canMessageBeMovedToSpam = canMessageBeMovedToSpam()
|
||||
|
||||
menu.findItem(R.id.move).isVisible = K9.isMessageViewMoveActionVisible
|
||||
menu.findItem(R.id.archive).isVisible = canMessageBeArchived && K9.isMessageViewArchiveActionVisible
|
||||
menu.findItem(R.id.spam).isVisible = canMessageBeMovedToSpam && K9.isMessageViewSpamActionVisible
|
||||
|
||||
menu.findItem(R.id.refile_move).isVisible = true
|
||||
menu.findItem(R.id.refile_archive).isVisible = canMessageBeArchived
|
||||
menu.findItem(R.id.refile_spam).isVisible = canMessageBeMovedToSpam
|
||||
|
||||
menu.findItem(R.id.refile).isVisible = true
|
||||
} else {
|
||||
menu.findItem(R.id.move).isVisible = false
|
||||
menu.findItem(R.id.archive).isVisible = false
|
||||
menu.findItem(R.id.spam).isVisible = false
|
||||
|
||||
menu.findItem(R.id.refile).isVisible = false
|
||||
}
|
||||
|
||||
if (isCopyCapable) {
|
||||
menu.findItem(R.id.copy).isVisible = K9.isMessageViewCopyActionVisible
|
||||
menu.findItem(R.id.refile_copy).isVisible = true
|
||||
} else {
|
||||
menu.findItem(R.id.copy).isVisible = false
|
||||
menu.findItem(R.id.refile_copy).isVisible = false
|
||||
}
|
||||
|
||||
menu.findItem(R.id.move_to_drafts).isVisible = isOutbox
|
||||
menu.findItem(R.id.single_message_options).isVisible = true
|
||||
menu.findItem(R.id.unsubscribe).isVisible = canMessageBeUnsubscribed()
|
||||
menu.findItem(R.id.show_headers).isVisible = true
|
||||
|
||||
val toggleTheme = menu.findItem(R.id.toggle_message_view_theme)
|
||||
if (generalSettingsManager.getSettings().fixedMessageViewTheme) {
|
||||
toggleTheme.isVisible = false
|
||||
} else {
|
||||
// Set title of menu item to switch to dark/light theme
|
||||
if (themeManager.messageViewTheme === Theme.DARK) {
|
||||
toggleTheme.setTitle(R.string.message_view_theme_action_light)
|
||||
} else {
|
||||
toggleTheme.setTitle(R.string.message_view_theme_action_dark)
|
||||
}
|
||||
toggleTheme.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun showMessage(messageViewInfo: MessageViewInfo) {
|
||||
hideKeyboard()
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/archive"
|
||||
android:visible="false"
|
||||
android:icon="?attr/iconActionArchive"
|
||||
app:showAsAction="always"
|
||||
android:title="@string/archive_action"/>
|
||||
|
@ -37,6 +38,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/delete"
|
||||
android:visible="false"
|
||||
android:icon="?attr/iconActionDelete"
|
||||
app:showAsAction="always"
|
||||
android:title="@string/delete_action"/>
|
||||
|
@ -44,6 +46,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/toggle_unread"
|
||||
android:visible="false"
|
||||
android:icon="?attr/iconActionMarkAsUnread"
|
||||
app:showAsAction="always"
|
||||
android:title="@string/mark_as_unread_action"/>
|
||||
|
@ -51,6 +54,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/previous_message"
|
||||
android:visible="false"
|
||||
android:title="@string/previous_action"
|
||||
android:icon="?attr/iconActionPreviousMessage"
|
||||
app:showAsAction="always" />
|
||||
|
@ -58,6 +62,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/next_message"
|
||||
android:visible="false"
|
||||
android:title="@string/next_action"
|
||||
android:icon="?attr/iconActionNextMessage"
|
||||
app:showAsAction="always"
|
||||
|
@ -66,6 +71,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/spam"
|
||||
android:visible="false"
|
||||
android:icon="?attr/iconActionSpam"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/spam_action"/>
|
||||
|
@ -73,6 +79,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/move"
|
||||
android:visible="false"
|
||||
android:icon="?attr/iconActionMove"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/move_action"/>
|
||||
|
@ -80,6 +87,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/copy"
|
||||
android:visible="false"
|
||||
android:icon="?attr/iconActionCopy"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/copy_action"/>
|
||||
|
@ -94,6 +102,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/single_message_options"
|
||||
android:visible="false"
|
||||
android:icon="?attr/iconActionSingleMessageOptions"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/single_message_options_action">
|
||||
|
@ -122,6 +131,7 @@
|
|||
<!-- MessageView -->
|
||||
<item
|
||||
android:id="@+id/refile"
|
||||
android:visible="false"
|
||||
android:icon="?attr/iconActionSingleMessageOptions"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/refile_action">
|
||||
|
@ -148,10 +158,12 @@
|
|||
</item>
|
||||
|
||||
<item android:id="@+id/unsubscribe"
|
||||
android:visible="false"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/unsubscribe_action"/>
|
||||
|
||||
<item android:id="@+id/show_headers"
|
||||
android:visible="false"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/show_headers_action"/>
|
||||
|
||||
|
@ -227,6 +239,7 @@
|
|||
|
||||
<!-- MessageView -->
|
||||
<item
|
||||
android:visible="false"
|
||||
android:id="@+id/toggle_message_view_theme"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/message_view_theme_action_dark"/>
|
||||
|
|
Loading…
Reference in a new issue