Repository: thunderbird/thunderbird-android
File: legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.kt (Kotlin)

Code before:
        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 drawableId = if (isMessageRead) {
                Icons.Outlined.MarkEmailUnread
            } else {
                Icons.Outlined.MarkEmailRead
            }

            val drawable = ContextCompat.getDrawable(requireContext(), drawableId)
            menu.findItem(R.id.toggle_unread).icon = drawable
        }

        if (isMoveCapable) {
            val canMessageBeArchived = canMessageBeArchived()
            val canMessageBeMovedToSpam = canMessageBeMovedToSpam()

            menu.findItem(R.id.move).isVisible = generalSettingsManager.getConfig().display
                .visualSettings.isMessageViewMoveActionVisible
            menu.findItem(R.id.archive).isVisible =
                canMessageBeArchived &&
                generalSettingsManager.getConfig().display.visualSettings.isMessageViewArchiveActionVisible
            menu.findItem(R.id.spam).isVisible = canMessageBeMovedToSpam &&
                generalSettingsManager
                    .getConfig().display.visualSettings.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
        }

        menu.findItem(R.id.set_format_plain).isVisible = !isRenderPlainFormat()
        menu.findItem(R.id.set_format_html).isVisible = isRenderPlainFormat()

        if (isCopyCapable) {

Review comment (bug):
Bit of a nitpick, but I do think this might look better broken up after the assignment operator, then a second time after the &&. Also, typically we indent four spaces after the && 

Code after:
        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 drawableId = if (isMessageRead) {
                Icons.Outlined.MarkEmailUnread
            } else {
                Icons.Outlined.MarkEmailRead
            }

            val drawable = ContextCompat.getDrawable(requireContext(), drawableId)
            menu.findItem(R.id.toggle_unread).icon = drawable
        }

        if (isMoveCapable) {
            val canMessageBeArchived = canMessageBeArchived()
            val canMessageBeMovedToSpam = canMessageBeMovedToSpam()
            menu.findItem(R.id.move).isVisible =
                generalSettingsManager.getConfig().display.visualSettings.isMessageViewMoveActionVisible

            menu.findItem(R.id.archive).isVisible =
                canMessageBeArchived &&
                generalSettingsManager.getConfig()
                    .display
                    .visualSettings
                    .isMessageViewArchiveActionVisible

            menu.findItem(R.id.spam).isVisible =
                canMessageBeMovedToSpam &&
                generalSettingsManager.getConfig()
                    .display
                    .visualSettings
                    .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