Set MessageViewFragment to "active" when its menu should be displayed

This commit is contained in:
cketti 2022-07-20 18:38:55 +02:00
parent 59aac05a8c
commit 9c8ac61ed6
2 changed files with 37 additions and 12 deletions

View file

@ -332,16 +332,21 @@ open class MessageList :
showMessageView()
}
DisplayMode.SPLIT_VIEW -> {
val messageListFragment = checkNotNull(this.messageListFragment)
messageListWasDisplayed = true
messageListFragment?.onListVisible()
if (messageViewFragment == null) {
showMessageViewPlaceHolder()
} else {
val activeMessage = messageViewFragment!!.messageReference
if (activeMessage != null) {
messageListFragment!!.setActiveMessage(activeMessage)
messageListFragment.onListVisible()
messageViewFragment.let { messageViewFragment ->
if (messageViewFragment == null) {
showMessageViewPlaceHolder()
} else {
messageViewFragment.isActive = true
val activeMessage = messageViewFragment.messageReference
messageListFragment.setActiveMessage(activeMessage)
}
}
setDrawerLockState()
onMessageListDisplayed()
}
@ -987,12 +992,15 @@ open class MessageList :
}
val fragment = MessageViewFragment.newInstance(messageReference)
val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.message_view_container, fragment, FRAGMENT_TAG_MESSAGE_VIEW)
fragmentTransaction.commit()
supportFragmentManager.commit {
replace(R.id.message_view_container, fragment, FRAGMENT_TAG_MESSAGE_VIEW)
}
messageViewFragment = fragment
if (displayMode != DisplayMode.SPLIT_VIEW) {
if (displayMode == DisplayMode.SPLIT_VIEW) {
fragment.isActive = true
} else {
showMessageView()
}
}
@ -1195,6 +1203,7 @@ open class MessageList :
displayMode = DisplayMode.MESSAGE_LIST
viewSwitcher!!.showFirstView()
messageViewFragment?.isActive = false
messageListFragment!!.onListVisible()
messageListFragment!!.setActiveMessage(null)
@ -1217,8 +1226,11 @@ open class MessageList :
}
private fun showMessageView() {
val messageViewFragment = checkNotNull(this.messageViewFragment)
displayMode = DisplayMode.MESSAGE_VIEW
messageListFragment?.onListHidden()
messageViewFragment.isActive = true
if (!messageListWasDisplayed) {
viewSwitcher!!.animateFirstView = false

View file

@ -89,6 +89,17 @@ class MessageViewFragment :
private var currentAttachmentViewInfo: AttachmentViewInfo? = null
/**
* Set this to `true` when the fragment should be considered active. When active, the fragment adds its actions to
* the toolbar. When inactive, the fragment won't add its actions to the toolbar, even it is still visible, e.g. as
* part of an animation.
*/
var isActive: Boolean = false
set(value) {
field = value
invalidateMenu()
}
override fun onAttach(context: Context) {
super.onAttach(context)
@ -179,6 +190,8 @@ class MessageViewFragment :
}
override fun onPrepareOptionsMenu(menu: Menu) {
if (!isActive) return
menu.findItem(R.id.delete).isVisible = K9.isMessageViewDeleteActionVisible
val showToggleUnread = !isOutbox
@ -890,7 +903,7 @@ class MessageViewFragment :
}
private fun invalidateMenu() {
requireActivity().invalidateMenu()
activity?.invalidateMenu()
}
private enum class FolderOperation {