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

Unverified Commit ba8b457e authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

Add `NavigationDrawer` interface to only expose interaction with `LegacyDrawer` to `MessageList

parent 32871c0c
Loading
Loading
Loading
Loading
+13 −13
Original line number Original line Diff line number Diff line
@@ -64,15 +64,15 @@ private const val EN_SPACE = "\u2000"


@Suppress("MagicNumber", "TooManyFunctions", "LongParameterList")
@Suppress("MagicNumber", "TooManyFunctions", "LongParameterList")
class LegacyDrawer(
class LegacyDrawer(
    savedInstanceState: Bundle?,
    override val parent: AppCompatActivity,
    parent: AppCompatActivity,
    private val openFolders: () -> Unit,
    private val openFolders: () -> Unit,
    private val openUnifiedInbox: () -> Unit,
    private val openUnifiedInbox: () -> Unit,
    private val openFolder: (folderId: Long) -> Unit,
    private val openFolder: (folderId: Long) -> Unit,
    private val openAccount: (account: Account) -> Boolean,
    private val openAccount: (account: Account) -> Boolean,
    private val openSettings: () -> Unit,
    private val openSettings: () -> Unit,
    createDrawerListener: () -> DrawerLayout.DrawerListener,
    createDrawerListener: () -> DrawerLayout.DrawerListener,
) : KoinComponent {
    savedInstanceState: Bundle?,
) : NavigationDrawer, KoinComponent {
    private val foldersViewModel: FoldersViewModel by parent.viewModel()
    private val foldersViewModel: FoldersViewModel by parent.viewModel()
    private val accountsViewModel: AccountsViewModel by parent.viewModel()
    private val accountsViewModel: AccountsViewModel by parent.viewModel()
    private val folderNameFormatter: FolderNameFormatter by inject()
    private val folderNameFormatter: FolderNameFormatter by inject()
@@ -104,7 +104,7 @@ class LegacyDrawer(
    val layout: DrawerLayout
    val layout: DrawerLayout
        get() = drawer
        get() = drawer


    val isOpen: Boolean
    override val isOpen: Boolean
        get() = drawer.isOpen
        get() = drawer.isOpen


    init {
    init {
@@ -309,7 +309,7 @@ class LegacyDrawer(
        return folderNameFormatter.displayName(folder)
        return folderNameFormatter.displayName(folder)
    }
    }


    fun updateUserAccountsAndFolders(account: Account?) {
    override fun updateUserAccountsAndFolders(account: Account?) {
        if (account != null) {
        if (account != null) {
            initializeWithAccountColor(account)
            initializeWithAccountColor(account)
            headerView.setActiveProfile(account.drawerId)
            headerView.setActiveProfile(account.drawerId)
@@ -428,14 +428,14 @@ class LegacyDrawer(
        userFolderDrawerIds.clear()
        userFolderDrawerIds.clear()
    }
    }


    fun selectAccount(accountUuid: String) {
    override fun selectAccount(accountUuid: String) {
        openedAccountUuid = accountUuid
        openedAccountUuid = accountUuid
        headerView.profiles?.firstOrNull { it.accountUuid == accountUuid }?.let { profile ->
        headerView.profiles?.firstOrNull { it.accountUuid == accountUuid }?.let { profile ->
            headerView.activeProfile = profile
            headerView.activeProfile = profile
        }
        }
    }
    }


    fun selectFolder(folderId: Long) {
    override fun selectFolder(folderId: Long) {
        deselect()
        deselect()
        openedFolderId = folderId
        openedFolderId = folderId
        for (drawerId in userFolderDrawerIds) {
        for (drawerId in userFolderDrawerIds) {
@@ -447,13 +447,13 @@ class LegacyDrawer(
        }
        }
    }
    }


    fun deselect() {
    override fun deselect() {
        unifiedInboxSelected = false
        unifiedInboxSelected = false
        openedFolderId = null
        openedFolderId = null
        sliderView.selectExtension.deselect()
        sliderView.selectExtension.deselect()
    }
    }


    fun selectUnifiedInbox() {
    override fun selectUnifiedInbox() {
        headerView.selectionListShown = false
        headerView.selectionListShown = false
        deselect()
        deselect()
        unifiedInboxSelected = true
        unifiedInboxSelected = true
@@ -484,19 +484,19 @@ class LegacyDrawer(
        return if (index == -1) color else darkColors[index]
        return if (index == -1) color else darkColors[index]
    }
    }


    fun open() {
    override fun open() {
        drawer.openDrawer(GravityCompat.START)
        drawer.openDrawer(GravityCompat.START)
    }
    }


    fun close() {
    override fun close() {
        drawer.closeDrawer(GravityCompat.START)
        drawer.closeDrawer(GravityCompat.START)
    }
    }


    fun lock() {
    override fun lock() {
        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
    }
    }


    fun unlock() {
    override fun unlock() {
        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
    }
    }


+27 −0
Original line number Original line Diff line number Diff line
package app.k9mail.feature.navigation.drawer

import androidx.appcompat.app.AppCompatActivity
import app.k9mail.legacy.account.Account

interface NavigationDrawer {
    val parent: AppCompatActivity
    val isOpen: Boolean

    fun updateUserAccountsAndFolders(account: Account?)

    fun selectAccount(accountUuid: String)

    fun selectFolder(folderId: Long)

    fun selectUnifiedInbox()

    fun deselect()

    fun open()

    fun close()

    fun lock()

    fun unlock()
}
+13 −12
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import app.k9mail.core.android.common.contact.ContactRepository
import app.k9mail.core.ui.legacy.designsystem.atom.icon.Icons
import app.k9mail.core.ui.legacy.designsystem.atom.icon.Icons
import app.k9mail.feature.launcher.FeatureLauncherActivity
import app.k9mail.feature.launcher.FeatureLauncherActivity
import app.k9mail.feature.navigation.drawer.LegacyDrawer
import app.k9mail.feature.navigation.drawer.LegacyDrawer
import app.k9mail.feature.navigation.drawer.NavigationDrawer
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.AccountManager
import app.k9mail.legacy.account.AccountManager
import app.k9mail.legacy.message.controller.MessageReference
import app.k9mail.legacy.message.controller.MessageReference
@@ -98,7 +99,7 @@ open class MessageList :
    private var initialSearchViewQuery: String? = null
    private var initialSearchViewQuery: String? = null
    private var initialSearchViewIconified: Boolean = true
    private var initialSearchViewIconified: Boolean = true


    private var drawer: LegacyDrawer? = null
    private var navigationDrawer: NavigationDrawer? = null
    private var openFolderTransaction: FragmentTransaction? = null
    private var openFolderTransaction: FragmentTransaction? = null
    private var progressBar: ProgressBar? = null
    private var progressBar: ProgressBar? = null
    private var messageViewPlaceHolder: PlaceholderFragment? = null
    private var messageViewPlaceHolder: PlaceholderFragment? = null
@@ -181,7 +182,7 @@ open class MessageList :


        if (isDrawerEnabled) {
        if (isDrawerEnabled) {
            configureDrawer()
            configureDrawer()
            drawer!!.updateUserAccountsAndFolders(account)
            navigationDrawer!!.updateUserAccountsAndFolders(account)
        }
        }


        findFragments()
        findFragments()
@@ -224,7 +225,7 @@ open class MessageList :


        if (isDrawerEnabled) {
        if (isDrawerEnabled) {
            configureDrawer()
            configureDrawer()
            drawer!!.updateUserAccountsAndFolders(account)
            navigationDrawer!!.updateUserAccountsAndFolders(account)
        }
        }


        initializeDisplayMode(null)
        initializeDisplayMode(null)
@@ -578,7 +579,7 @@ open class MessageList :
            return
            return
        }
        }


        drawer = LegacyDrawer(
        navigationDrawer = LegacyDrawer(
            parent = this,
            parent = this,
            savedInstanceState = savedInstanceState,
            savedInstanceState = savedInstanceState,
            openFolders = { launchManageFoldersScreen() },
            openFolders = { launchManageFoldersScreen() },
@@ -700,8 +701,8 @@ open class MessageList :
    }
    }


    override fun onBackPressed() {
    override fun onBackPressed() {
        if (isDrawerEnabled && drawer!!.isOpen) {
        if (isDrawerEnabled && navigationDrawer!!.isOpen) {
            drawer!!.close()
            navigationDrawer!!.close()
        } else if (displayMode == DisplayMode.MESSAGE_VIEW) {
        } else if (displayMode == DisplayMode.MESSAGE_VIEW) {
            if (messageViewOnly) {
            if (messageViewOnly) {
                finish()
                finish()
@@ -919,10 +920,10 @@ open class MessageList :
        if (id == android.R.id.home) {
        if (id == android.R.id.home) {
            if (displayMode != DisplayMode.MESSAGE_VIEW && !isAdditionalMessageListDisplayed) {
            if (displayMode != DisplayMode.MESSAGE_VIEW && !isAdditionalMessageListDisplayed) {
                if (isDrawerEnabled) {
                if (isDrawerEnabled) {
                    if (drawer!!.isOpen) {
                    if (navigationDrawer!!.isOpen) {
                        drawer!!.close()
                        navigationDrawer!!.close()
                    } else {
                    } else {
                        drawer!!.open()
                        navigationDrawer!!.open()
                    }
                    }
                } else {
                } else {
                    finish()
                    finish()
@@ -1334,12 +1335,12 @@ open class MessageList :
        get() = supportFragmentManager.backStackEntryCount > 0
        get() = supportFragmentManager.backStackEntryCount > 0


    private fun lockDrawer() {
    private fun lockDrawer() {
        drawer!!.lock()
        navigationDrawer!!.lock()
        actionBar.setHomeAsUpIndicator(Icons.Outlined.ArrowBack)
        actionBar.setHomeAsUpIndicator(Icons.Outlined.ArrowBack)
    }
    }


    private fun unlockDrawer() {
    private fun unlockDrawer() {
        drawer!!.unlock()
        navigationDrawer!!.unlock()
        actionBar.setHomeAsUpIndicator(Icons.Outlined.Menu)
        actionBar.setHomeAsUpIndicator(Icons.Outlined.Menu)
    }
    }


@@ -1383,7 +1384,7 @@ open class MessageList :
    }
    }


    private fun configureDrawer() {
    private fun configureDrawer() {
        val drawer = drawer ?: return
        val drawer = navigationDrawer ?: return
        drawer.selectAccount(account!!.uuid)
        drawer.selectAccount(account!!.uuid)
        when {
        when {
            singleFolderMode -> drawer.selectFolder(search!!.folderIds[0])
            singleFolderMode -> drawer.selectFolder(search!!.folderIds[0])