Skip to content

Commit

Permalink
Merge pull request #7345 from thunderbird/add_biometric_password_inpu…
Browse files Browse the repository at this point in the history
…t_to_server_settings

Add biometric password input to server settings form
  • Loading branch information
wmontwe authored Nov 9, 2023
2 parents f0adce3 + 566d2a7 commit 60cdf1f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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 = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -45,6 +47,7 @@ internal fun OutgoingServerSettingsContent(
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.default),
) {
outgoingFormItems(
mode = mode,
state = state,
onEvent = onEvent,
resources = resources,
Expand All @@ -58,8 +61,9 @@ internal fun OutgoingServerSettingsContent(
internal fun OutgoingServerSettingsContentK9Preview() {
K9Theme {
OutgoingServerSettingsContent(
onEvent = { },
mode = InteractionMode.Create,
state = State(),
onEvent = { },
contentPadding = PaddingValues(),
)
}
Expand All @@ -70,6 +74,7 @@ internal fun OutgoingServerSettingsContentK9Preview() {
internal fun OutgoingServerSettingsContentThunderbirdPreview() {
ThunderbirdTheme {
OutgoingServerSettingsContent(
mode = InteractionMode.Create,
onEvent = { },
state = State(),
contentPadding = PaddingValues(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fun OutgoingServerSettingsScreen(
modifier = modifier,
) { innerPadding ->
OutgoingServerSettingsContent(
mode = viewModel.mode,
state = state.value,
onEvent = { dispatch(it) },
contentPadding = innerPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)) },
Expand Down

0 comments on commit 60cdf1f

Please sign in to comment.