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

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

Add AccountList

parent 794ee9cf
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
package app.k9mail.feature.navigation.drawer.ui.account

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.designsystem.PreviewWithTheme
import app.k9mail.feature.navigation.drawer.ui.FakeData.DISPLAY_ACCOUNT
import kotlinx.collections.immutable.persistentListOf

@Composable
@Preview(showBackground = true)
fun AccountListPreview() {
    PreviewWithTheme {
        AccountList(
            accounts = persistentListOf(
                DISPLAY_ACCOUNT,
            ),
            selectedAccount = null,
            onAccountClick = { },
            onSettingsClick = { },
        )
    }
}

@Composable
@Preview(showBackground = true)
fun AccountListWithSelectedPreview() {
    PreviewWithTheme {
        AccountList(
            accounts = persistentListOf(
                DISPLAY_ACCOUNT,
            ),
            selectedAccount = DISPLAY_ACCOUNT,
            onAccountClick = { },
            onSettingsClick = { },
        )
    }
}
+35 −16
Original line number Diff line number Diff line
package app.k9mail.feature.navigation.drawer.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@@ -9,6 +11,7 @@ import app.k9mail.core.ui.compose.designsystem.atom.DividerHorizontal
import app.k9mail.core.ui.compose.designsystem.atom.Surface
import app.k9mail.feature.navigation.drawer.ui.DrawerContract.Event
import app.k9mail.feature.navigation.drawer.ui.DrawerContract.State
import app.k9mail.feature.navigation.drawer.ui.account.AccountList
import app.k9mail.feature.navigation.drawer.ui.account.AccountView
import app.k9mail.feature.navigation.drawer.ui.folder.FolderList
import app.k9mail.feature.navigation.drawer.ui.setting.SettingList
@@ -38,6 +41,22 @@ fun DrawerContent(

                DividerHorizontal()
            }
            Row {
                AnimatedVisibility(
                    visible = state.showAccountSelector,
                ) {
                    AccountList(
                        accounts = state.accounts,
                        selectedAccount = state.selectedAccount,
                        onAccountClick = { onEvent(Event.OnAccountClick(it)) },
                        onSettingsClick = { onEvent(Event.OnSettingsClick) },
                    )
                }
                Column(
                    modifier = Modifier
                        .weight(1f)
                        .fillMaxSize(),
                ) {
                    FolderList(
                        folders = state.folders,
                        selectedFolder = state.selectedFolder,
@@ -47,7 +66,6 @@ fun DrawerContent(
                        showStarredCount = state.config.showStarredCount,
                        modifier = Modifier.weight(1f),
                    )
            Column {
                    DividerHorizontal()
                    SettingList(
                        onAccountSelectorClick = { onEvent(Event.OnAccountSelectorClick) },
@@ -58,3 +76,4 @@ fun DrawerContent(
            }
        }
    }
}
+59 −0
Original line number Diff line number Diff line
package app.k9mail.feature.navigation.drawer.ui.account

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.k9mail.core.ui.compose.designsystem.atom.Surface
import app.k9mail.core.ui.compose.theme2.MainTheme
import app.k9mail.feature.navigation.drawer.R
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccount
import app.k9mail.feature.navigation.drawer.ui.setting.SettingItem
import kotlinx.collections.immutable.ImmutableList

@Composable
fun AccountList(
    accounts: ImmutableList<DisplayAccount>,
    selectedAccount: DisplayAccount?,
    onAccountClick: (DisplayAccount) -> Unit,
    onSettingsClick: () -> Unit,
    modifier: Modifier = Modifier,
) {
    Surface(
        modifier = modifier,
        color = MainTheme.colors.surfaceContainer,
    ) {
        Column(
            modifier = Modifier
                .fillMaxHeight()
                .width(MainTheme.sizes.large),
        ) {
            LazyColumn(
                modifier = Modifier.weight(1f),
                contentPadding = PaddingValues(vertical = MainTheme.spacings.default),
            ) {
                items(
                    items = accounts,
                    key = { account -> account.account.uuid },
                ) { account ->
                    if (selectedAccount != null && account == selectedAccount) {
                        return@items
                    }
                    AccountListItem(
                        account = account,
                        onClick = { onAccountClick(account) },
                    )
                }
            }
            SettingItem(
                label = stringResource(id = R.string.navigation_drawer_action_settings),
                onClick = onSettingsClick,
            )
        }
    }
}