Skip to content

Commit

Permalink
Add AccountTopAppBarWithBackButton
Browse files Browse the repository at this point in the history
  • Loading branch information
wmontwe committed Oct 12, 2023
1 parent b4231b8 commit 52cf0f3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.k9mail.core.ui.compose.common.DevicePreviews
import app.k9mail.core.ui.compose.designsystem.organism.TopAppBar
import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
import app.k9mail.feature.account.common.R

/**
* Top app bar for the account screens.
*
* @param title The title of the screen.
* @param modifier Modifier for styling.
*/
@Composable
fun AccountTopAppBar(
title: String,
Expand All @@ -28,18 +33,8 @@ fun AccountTopAppBar(

@DevicePreviews
@Composable
internal fun AccountTopAppBarK9Preview() {
K9Theme {
AccountTopAppBar(
title = "Title",
)
}
}

@DevicePreviews
@Composable
internal fun AccountTopAppBarThunderbirdPreview() {
ThunderbirdTheme {
internal fun AccountTopAppBarPreview() {
PreviewWithThemes {
AccountTopAppBar(
title = "Title",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package app.k9mail.feature.account.common.ui

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.k9mail.core.ui.compose.common.DevicePreviews
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonIcon
import app.k9mail.core.ui.compose.designsystem.organism.TopAppBar
import app.k9mail.core.ui.compose.theme.Icons
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
import app.k9mail.feature.account.common.R

/**
* Top app bar for the account screens with a back button.
*
* @param title The title of the screen.
* @param modifier Modifier for styling.
* @param onBackClicked Callback for when the back button is clicked.
*/
@Composable
fun AccountTopAppBarWithBackButton(
title: String,
modifier: Modifier = Modifier,
onBackClicked: () -> Unit,
) {
TopAppBar(
title = title,
modifier = modifier,
subtitle = stringResource(id = R.string.account_common_title),
titleContentPadding = PaddingValues(
start = MainTheme.spacings.default,
),
navigationIcon = {
ButtonIcon(
onClick = onBackClicked,
imageVector = Icons.Outlined.arrowBack,
)
},
)
}

@DevicePreviews
@Composable
internal fun AccountTopAppBarWithBackButtonPreview() {
PreviewWithThemes {
AccountTopAppBarWithBackButton(
title = "Title",
onBackClicked = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme
import app.k9mail.feature.account.common.domain.entity.InteractionMode
import app.k9mail.feature.account.common.ui.AccountTopAppBar
import app.k9mail.feature.account.common.ui.AccountTopAppBarWithBackButton
import app.k9mail.feature.account.common.ui.WizardNavigationBar
import app.k9mail.feature.account.common.ui.preview.PreviewAccountStateRepository
import app.k9mail.feature.account.server.settings.R
Expand Down Expand Up @@ -43,9 +44,16 @@ fun IncomingServerSettingsScreen(

Scaffold(
topBar = {
AccountTopAppBar(
title = stringResource(id = R.string.account_server_settings_incoming_top_bar_title),
)
if (viewModel.mode == InteractionMode.Edit) {
AccountTopAppBarWithBackButton(
title = stringResource(id = R.string.account_server_settings_incoming_top_bar_title),
onBackClicked = { dispatch(Event.OnBackClicked) },
)
} else {
AccountTopAppBar(
title = stringResource(id = R.string.account_server_settings_incoming_top_bar_title),
)
}
},
bottomBar = {
WizardNavigationBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme
import app.k9mail.feature.account.common.domain.entity.InteractionMode
import app.k9mail.feature.account.common.ui.AccountTopAppBar
import app.k9mail.feature.account.common.ui.AccountTopAppBarWithBackButton
import app.k9mail.feature.account.common.ui.WizardNavigationBar
import app.k9mail.feature.account.common.ui.preview.PreviewAccountStateRepository
import app.k9mail.feature.account.server.settings.R
Expand Down Expand Up @@ -43,9 +44,16 @@ fun OutgoingServerSettingsScreen(

Scaffold(
topBar = {
AccountTopAppBar(
title = stringResource(id = R.string.account_server_settings_outgoing_top_bar_title),
)
if (viewModel.mode == InteractionMode.Edit) {
AccountTopAppBarWithBackButton(
title = stringResource(id = R.string.account_server_settings_outgoing_top_bar_title),
onBackClicked = { dispatch(Event.OnBackClicked) },
)
} else {
AccountTopAppBar(
title = stringResource(id = R.string.account_server_settings_outgoing_top_bar_title),
)
}
},
bottomBar = {
WizardNavigationBar(
Expand Down

0 comments on commit 52cf0f3

Please sign in to comment.