Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit d3afad00 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #6178 from thundernest/more_menu_cleanup

More menu cleanup
parents 479e1688 cc5fc8e2
Loading
Loading
Loading
Loading
+6 −32
Original line number Diff line number Diff line
@@ -98,7 +98,6 @@ open class MessageList :
    private lateinit var searchView: SearchView
    private var drawer: K9Drawer? = null
    private var openFolderTransaction: FragmentTransaction? = null
    private var menu: Menu? = null
    private var progressBar: ProgressBar? = null
    private var messageViewPlaceHolder: PlaceholderFragment? = null
    private var messageListFragment: MessageListFragment? = null
@@ -335,7 +334,7 @@ open class MessageList :
                val messageListFragment = checkNotNull(this.messageListFragment)

                messageListWasDisplayed = true
                messageListFragment.onListVisible()
                messageListFragment.isActive = true

                messageViewFragment.let { messageViewFragment ->
                    if (messageViewFragment == null) {
@@ -627,7 +626,7 @@ open class MessageList :
        openFolderTransaction!!.commit()
        openFolderTransaction = null

        messageListFragment!!.onListVisible()
        messageListFragment!!.isActive = true

        onMessageListDisplayed()
    }
@@ -919,25 +918,13 @@ open class MessageList :
                goBack()
            }
            return true
        } else if (id == R.id.search_everywhere) {
            searchEverywhere()
            return true
        }

        return super.onOptionsItemSelected(item)
    }

    private fun searchEverywhere() {
        val searchIntent = Intent(this, Search::class.java).apply {
            action = Intent.ACTION_SEARCH
            putExtra(SearchManager.QUERY, intent.getStringExtra(SearchManager.QUERY))
        }
        onNewIntent(searchIntent)
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.message_list_option, menu)
        this.menu = menu

        // setup search view
        val searchItem = menu.findItem(R.id.search)
@@ -1032,7 +1019,7 @@ open class MessageList :

    override fun onBackStackChanged() {
        findFragments()
        messageListFragment?.onListVisible()
        messageListFragment?.isActive = true

        if (isDrawerEnabled && !isAdditionalMessageListDisplayed) {
            unlockDrawer()
@@ -1041,8 +1028,6 @@ open class MessageList :
        if (displayMode == DisplayMode.SPLIT_VIEW) {
            showMessageViewPlaceHolder()
        }

        invalidateMenu()
    }

    private fun addMessageListFragment(fragment: MessageListFragment) {
@@ -1059,7 +1044,7 @@ open class MessageList :
        }

        messageListFragment = fragment
        fragment.onListVisible()
        fragment.isActive = true

        if (isDrawerEnabled) {
            lockDrawer()
@@ -1134,11 +1119,6 @@ open class MessageList :
        fragmentTransaction.commit()
    }

    override fun remoteSearchStarted() {
        // Remove action button for remote search
        invalidateMenu()
    }

    override fun goBack() {
        val fragmentManager = supportFragmentManager
        when {
@@ -1206,13 +1186,12 @@ open class MessageList :
        viewSwitcher!!.showFirstView()

        messageViewFragment?.isActive = false
        messageListFragment!!.onListVisible()
        messageListFragment!!.isActive = true
        messageListFragment!!.setActiveMessage(null)

        setDrawerLockState()

        showDefaultTitleView()
        invalidateMenu()

        onMessageListDisplayed()
    }
@@ -1231,7 +1210,7 @@ open class MessageList :
        val messageViewFragment = checkNotNull(this.messageViewFragment)

        displayMode = DisplayMode.MESSAGE_VIEW
        messageListFragment?.onListHidden()
        messageListFragment?.isActive = false
        messageViewFragment.isActive = true

        if (!messageListWasDisplayed) {
@@ -1244,11 +1223,6 @@ open class MessageList :
        }

        showMessageTitleView()
        invalidateMenu()
    }

    override fun disableDeleteAction() {
        menu!!.findItem(R.id.delete).isEnabled = false
    }

    private fun showDefaultTitleView() {
+32 −20
Original line number Diff line number Diff line
package com.fsck.k9.fragment

import android.app.Activity
import android.app.SearchManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
@@ -28,6 +29,7 @@ import com.fsck.k9.Clock
import com.fsck.k9.K9
import com.fsck.k9.Preferences
import com.fsck.k9.activity.FolderInfoHolder
import com.fsck.k9.activity.Search
import com.fsck.k9.activity.misc.ContactPicture
import com.fsck.k9.controller.MessageReference
import com.fsck.k9.controller.MessagingController
@@ -109,8 +111,6 @@ class MessageListFragment :
    private var isThreadDisplay = false
    private var activeMessage: MessageReference? = null

    var isLoadFinished = false
        private set
    lateinit var localSearch: LocalSearch
        private set
    var isSingleAccountMode = false
@@ -130,7 +130,17 @@ class MessageListFragment :
     */
    private var isInitialized = false

    private var isListVisible = false
    /**
     * 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
            resetActionMode()
            invalidateMenu()
        }

    override fun onAttach(context: Context) {
        super.onAttach(context)
@@ -526,7 +536,7 @@ class MessageListFragment :
            activityListener
        )

        fragmentListener.remoteSearchStarted()
        invalidateMenu()
    }

    /**
@@ -698,7 +708,7 @@ class MessageListFragment :
    }

    override fun onPrepareOptionsMenu(menu: Menu) {
        if (isListVisible) {
        if (isActive) {
            prepareMenu(menu)
        } else {
            hideMenu(menu)
@@ -755,12 +765,27 @@ class MessageListFragment :
            R.id.send_messages -> onSendPendingMessages()
            R.id.empty_trash -> onEmptyTrash()
            R.id.expunge -> onExpunge()
            R.id.search_everywhere -> onSearchEverywhere()
            else -> return super.onOptionsItemSelected(item)
        }

        return true
    }

    private fun onSearchEverywhere() {
        val searchQuery = requireActivity().intent.getStringExtra(SearchManager.QUERY)

        val searchIntent = Intent(requireContext(), Search::class.java).apply {
            action = Intent.ACTION_SEARCH
            putExtra(SearchManager.QUERY, searchQuery)

            addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
            addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        }

        startActivity(searchIntent)
    }

    private fun onSendPendingMessages() {
        messagingController.sendPendingMessages(account, null)
    }
@@ -1497,8 +1522,6 @@ class MessageListFragment :
        computeBatchDirection()
        computeSelectAllVisibility()

        isLoadFinished = true

        if (savedListState != null) {
            handler.restoreListPosition(savedListState)
            savedListState = null
@@ -1524,7 +1547,7 @@ class MessageListFragment :
    private fun resetActionMode() {
        if (!isResumed) return

        if (!isListVisible || selected.isEmpty()) {
        if (!isActive || selected.isEmpty()) {
            actionMode?.finish()
            actionMode = null
            return
@@ -1592,18 +1615,8 @@ class MessageListFragment :
        }
    }

    fun onListVisible() {
        isListVisible = true
        resetActionMode()
    }

    fun onListHidden() {
        isListVisible = false
        resetActionMode()
    }

    private fun invalidateMenu() {
        requireActivity().invalidateMenu()
        activity?.invalidateMenu()
    }

    private val isCheckMailSupported: Boolean
@@ -1962,7 +1975,6 @@ class MessageListFragment :
        fun setMessageListTitle(title: String, subtitle: String?)
        fun onCompose(account: Account?)
        fun startSearch(query: String, account: Account?, folderId: Long?): Boolean
        fun remoteSearchStarted()
        fun goBack()
        fun onFolderNotFoundError()

+11 −4
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ class MessageViewFragment :
    lateinit var messageReference: MessageReference

    private var currentAttachmentViewInfo: AttachmentViewInfo? = null
    private var isDeleteMenuItemDisabled: Boolean = false

    /**
     * Set this to `true` when the fragment should be considered active. When active, the fragment adds its actions to
@@ -192,7 +193,10 @@ class MessageViewFragment :
    override fun onPrepareOptionsMenu(menu: Menu) {
        if (!isActive) return

        menu.findItem(R.id.delete).isVisible = K9.isMessageViewDeleteActionVisible
        menu.findItem(R.id.delete).apply {
            isVisible = K9.isMessageViewDeleteActionVisible
            isEnabled = !isDeleteMenuItemDisabled
        }

        val showToggleUnread = !isOutbox
        menu.findItem(R.id.toggle_unread).isVisible = showToggleUnread
@@ -378,14 +382,18 @@ class MessageViewFragment :
    }

    private fun delete() {
        // Disable the delete button after it has been tapped (to try to prevent accidental clicks)
        fragmentListener.disableDeleteAction()
        disableDeleteMenuItem()

        fragmentListener.showNextMessageOrReturn()

        messagingController.deleteMessage(messageReference)
    }

    private fun disableDeleteMenuItem() {
        isDeleteMenuItemDisabled = true
        invalidateMenu()
    }

    private fun onRefile(destinationFolderId: Long?) {
        if (destinationFolderId == null || !messagingController.isMoveCapable(account)) {
            return
@@ -799,7 +807,6 @@ class MessageViewFragment :
        fun onForward(messageReference: MessageReference, decryptionResultForReply: Parcelable?)
        fun onForwardAsAttachment(messageReference: MessageReference, decryptionResultForReply: Parcelable?)
        fun onEditAsNewMessage(messageReference: MessageReference)
        fun disableDeleteAction()
        fun onReplyAll(messageReference: MessageReference, decryptionResultForReply: Parcelable?)
        fun onReply(messageReference: MessageReference, decryptionResultForReply: Parcelable?)
        fun setProgress(enable: Boolean)