diff --git a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/common/ServerSettingsPasswordInput.kt b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/common/ServerSettingsPasswordInput.kt new file mode 100644 index 000000000..fba8f5304 --- /dev/null +++ b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/common/ServerSettingsPasswordInput.kt @@ -0,0 +1,63 @@ +package app.k9mail.feature.account.server.settings.ui.common + +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import app.k9mail.core.ui.compose.designsystem.molecule.input.PasswordInput +import app.k9mail.core.ui.compose.designsystem.molecule.input.inputContentPadding +import app.k9mail.core.ui.compose.theme.PreviewWithThemes +import app.k9mail.feature.account.common.domain.entity.InteractionMode + +@Composable +fun ServerSettingsPasswordInput( + mode: InteractionMode, + onPasswordChange: (String) -> Unit, + modifier: Modifier = Modifier, + password: String = "", + isRequired: Boolean = false, + errorMessage: String? = null, + contentPadding: PaddingValues = inputContentPadding(), +) { + if (mode == InteractionMode.Create) { + PasswordInput( + onPasswordChange = onPasswordChange, + modifier = modifier, + password = password, + isRequired = isRequired, + errorMessage = errorMessage, + contentPadding = contentPadding, + ) + } else { + BiometricPasswordInput( + onPasswordChange = onPasswordChange, + modifier = modifier, + password = password, + isRequired = isRequired, + errorMessage = errorMessage, + contentPadding = contentPadding, + ) + } +} + +@Preview(showBackground = true) +@Composable +internal fun ServerSettingsPasswordInputCreatePreview() { + PreviewWithThemes { + ServerSettingsPasswordInput( + mode = InteractionMode.Create, + onPasswordChange = {}, + ) + } +} + +@Preview(showBackground = true) +@Composable +internal fun ServerSettingsPasswordInputEditPreview() { + PreviewWithThemes { + ServerSettingsPasswordInput( + mode = InteractionMode.Edit, + onPasswordChange = {}, + ) + } +} diff --git a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/incoming/content/IncomingFormItems.kt b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/incoming/content/IncomingFormItems.kt index ce72ce3b6..d02861561 100644 --- a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/incoming/content/IncomingFormItems.kt +++ b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/incoming/content/IncomingFormItems.kt @@ -7,7 +7,6 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import app.k9mail.core.ui.compose.designsystem.molecule.input.NumberInput -import app.k9mail.core.ui.compose.designsystem.molecule.input.PasswordInput import app.k9mail.core.ui.compose.designsystem.molecule.input.SelectInput import app.k9mail.core.ui.compose.designsystem.molecule.input.TextInput import app.k9mail.core.ui.compose.theme.MainTheme @@ -17,6 +16,7 @@ import app.k9mail.feature.account.common.domain.entity.InteractionMode import app.k9mail.feature.account.common.ui.item.defaultItemPadding import app.k9mail.feature.account.server.settings.R import app.k9mail.feature.account.server.settings.ui.common.ClientCertificateInput +import app.k9mail.feature.account.server.settings.ui.common.ServerSettingsPasswordInput import app.k9mail.feature.account.server.settings.ui.common.mapper.toResourceString import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsContract.Event import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsContract.State @@ -100,7 +100,8 @@ internal fun LazyListScope.incomingFormItems( if (state.isPasswordFieldVisible) { item { - PasswordInput( + ServerSettingsPasswordInput( + mode = mode, password = state.password.value, errorMessage = state.password.error?.toResourceString(resources), onPasswordChange = { onEvent(Event.PasswordChanged(it)) }, diff --git a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/OutgoingServerSettingsContent.kt b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/OutgoingServerSettingsContent.kt index a07e96951..7b402bc19 100644 --- a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/OutgoingServerSettingsContent.kt +++ b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/OutgoingServerSettingsContent.kt @@ -17,12 +17,14 @@ import app.k9mail.core.ui.compose.designsystem.template.ResponsiveWidthContainer 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.feature.account.common.domain.entity.InteractionMode import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract.Event import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract.State import app.k9mail.feature.account.server.settings.ui.outgoing.content.outgoingFormItems @Composable internal fun OutgoingServerSettingsContent( + mode: InteractionMode, state: State, onEvent: (Event) -> Unit, contentPadding: PaddingValues, @@ -45,6 +47,7 @@ internal fun OutgoingServerSettingsContent( verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.default), ) { outgoingFormItems( + mode = mode, state = state, onEvent = onEvent, resources = resources, @@ -58,8 +61,9 @@ internal fun OutgoingServerSettingsContent( internal fun OutgoingServerSettingsContentK9Preview() { K9Theme { OutgoingServerSettingsContent( - onEvent = { }, + mode = InteractionMode.Create, state = State(), + onEvent = { }, contentPadding = PaddingValues(), ) } @@ -70,6 +74,7 @@ internal fun OutgoingServerSettingsContentK9Preview() { internal fun OutgoingServerSettingsContentThunderbirdPreview() { ThunderbirdTheme { OutgoingServerSettingsContent( + mode = InteractionMode.Create, onEvent = { }, state = State(), contentPadding = PaddingValues(), diff --git a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/OutgoingServerSettingsScreen.kt b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/OutgoingServerSettingsScreen.kt index 467d48a68..f4d9adbd3 100644 --- a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/OutgoingServerSettingsScreen.kt +++ b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/OutgoingServerSettingsScreen.kt @@ -64,6 +64,7 @@ fun OutgoingServerSettingsScreen( modifier = modifier, ) { innerPadding -> OutgoingServerSettingsContent( + mode = viewModel.mode, state = state.value, onEvent = { dispatch(it) }, contentPadding = innerPadding, diff --git a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/content/OutgoingFormItems.kt b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/content/OutgoingFormItems.kt index ff579bb41..5196e702a 100644 --- a/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/content/OutgoingFormItems.kt +++ b/feature/account/server/settings/src/main/kotlin/app/k9mail/feature/account/server/settings/ui/outgoing/content/OutgoingFormItems.kt @@ -7,15 +7,16 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import app.k9mail.core.ui.compose.designsystem.molecule.input.NumberInput -import app.k9mail.core.ui.compose.designsystem.molecule.input.PasswordInput import app.k9mail.core.ui.compose.designsystem.molecule.input.SelectInput import app.k9mail.core.ui.compose.designsystem.molecule.input.TextInput import app.k9mail.core.ui.compose.theme.MainTheme import app.k9mail.feature.account.common.domain.entity.AuthenticationType import app.k9mail.feature.account.common.domain.entity.ConnectionSecurity +import app.k9mail.feature.account.common.domain.entity.InteractionMode import app.k9mail.feature.account.common.ui.item.defaultItemPadding import app.k9mail.feature.account.server.settings.R import app.k9mail.feature.account.server.settings.ui.common.ClientCertificateInput +import app.k9mail.feature.account.server.settings.ui.common.ServerSettingsPasswordInput import app.k9mail.feature.account.server.settings.ui.common.mapper.toResourceString import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract.Event import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract.State @@ -24,6 +25,7 @@ import app.k9mail.feature.account.server.settings.ui.outgoing.isUsernameFieldVis @Suppress("LongMethod") internal fun LazyListScope.outgoingFormItems( + mode: InteractionMode, state: State, onEvent: (Event) -> Unit, resources: Resources, @@ -91,7 +93,8 @@ internal fun LazyListScope.outgoingFormItems( if (state.isPasswordFieldVisible) { item { - PasswordInput( + ServerSettingsPasswordInput( + mode = mode, password = state.password.value, errorMessage = state.password.error?.toResourceString(resources), onPasswordChange = { onEvent(Event.PasswordChanged(it)) },