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

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

Add FolderDrawerState to manage the communication between drawer and host

parent e5dbc568
Loading
Loading
Loading
Loading
+36 −6
Original line number Diff line number Diff line
@@ -5,14 +5,24 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.platform.ComposeView
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import app.k9mail.core.ui.theme.api.FeatureThemeProvider
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayUnifiedFolderType
import app.k9mail.feature.navigation.drawer.domain.entity.createDisplayAccountFolderId
import app.k9mail.feature.navigation.drawer.ui.DrawerView
import app.k9mail.legacy.account.Account
import com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

internal data class FolderDrawerState(
    val selectedAccountUuid: String? = null,
    val selectedFolderId: String? = null,
)

class FolderDrawer(
    override val parent: AppCompatActivity,
    private val openAccount: (account: Account) -> Unit,
@@ -30,6 +40,8 @@ class FolderDrawer(
    private val sliderView: MaterialDrawerSliderView = parent.findViewById(R.id.material_drawer_slider)
    private val swipeRefreshLayout: SwipeRefreshLayout = parent.findViewById(R.id.material_drawer_swipe_refresh)

    private val drawerState = MutableStateFlow(FolderDrawerState())

    init {
        sliderView.visibility = View.GONE
        drawerView.visibility = View.VISIBLE
@@ -38,7 +50,10 @@ class FolderDrawer(

        drawerView.setContent {
            themeProvider.WithTheme {
                val state = drawerState.collectAsStateWithLifecycle()

                DrawerView(
                    drawerState = state.value,
                    openAccount = openAccount,
                    openFolder = openFolder,
                    openUnifiedFolder = openUnifiedFolder,
@@ -54,23 +69,38 @@ class FolderDrawer(
        get() = drawer.isOpen

    override fun updateUserAccountsAndFolders(account: Account?) {
        // TODO("Not yet implemented")
        // no-op
    }

    override fun selectAccount(accountUuid: String) {
        // TODO("Not yet implemented")
        drawerState.update {
            it.copy(selectedAccountUuid = accountUuid)
        }
    }

    override fun selectFolder(folderId: Long) {
        // TODO("Not yet implemented")
    override fun selectFolder(accountUuid: String, folderId: Long) {
        drawerState.update {
            it.copy(
                selectedAccountUuid = accountUuid,
                selectedFolderId = createDisplayAccountFolderId(accountUuid, folderId),
            )
        }
    }

    override fun selectUnifiedInbox() {
        // TODO("Not yet implemented")
        drawerState.update {
            it.copy(
                selectedFolderId = DisplayUnifiedFolderType.INBOX.id,
            )
        }
    }

    override fun deselect() {
        // TODO("Not yet implemented")
        drawerState.update {
            it.copy(
                selectedFolderId = null,
            )
        }
    }

    override fun open() {
+1 −1
Original line number Diff line number Diff line
@@ -437,7 +437,7 @@ class LegacyDrawer(
        }
    }

    override fun selectFolder(folderId: Long) {
    override fun selectFolder(accountUuid: String, folderId: Long) {
        deselect()
        openedFolderId = folderId
        for (drawerId in userFolderDrawerIds) {
+2 −1
Original line number Diff line number Diff line
@@ -7,11 +7,12 @@ interface NavigationDrawer {
    val parent: AppCompatActivity
    val isOpen: Boolean

    // TODO: remove once LegacyDrawer is removed
    fun updateUserAccountsAndFolders(account: Account?)

    fun selectAccount(accountUuid: String)

    fun selectFolder(folderId: Long)
    fun selectFolder(accountUuid: String, folderId: Long)

    fun selectUnifiedInbox()

+5 −1
Original line number Diff line number Diff line
@@ -9,5 +9,9 @@ internal data class DisplayAccountFolder(
    override val unreadMessageCount: Int,
    override val starredMessageCount: Int,
) : DisplayFolder {
    override val id: String = "${accountUuid}_${folder.id}"
    override val id: String = createDisplayAccountFolderId(accountUuid, folder.id)
}

fun createDisplayAccountFolderId(accountUuid: String, folderId: Long): String {
    return "${accountUuid}_$folderId"
}
+9 −2
Original line number Diff line number Diff line
package app.k9mail.feature.navigation.drawer.domain.entity

internal enum class DisplayUnifiedFolderType {
    INBOX,
/**
 * Represents a unified folder in the drawer.
 *
 * The id is unique for each unified folder type.
 */
internal enum class DisplayUnifiedFolderType(
    val id: String,
) {
    INBOX("unified_inbox"),
}
Loading