Merge pull request #7345 from thunderbird/add_biometric_password_input_to_server_settings

Add biometric password input to server settings form
This commit is contained in:
Wolf-Martell Montwé 2023-11-09 13:38:02 +01:00 committed by GitHub
commit 60cdf1fe39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 5 deletions

View file

@ -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 = {},
)
}
}

View file

@ -7,7 +7,6 @@ import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource 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.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.SelectInput
import app.k9mail.core.ui.compose.designsystem.molecule.input.TextInput import app.k9mail.core.ui.compose.designsystem.molecule.input.TextInput
import app.k9mail.core.ui.compose.theme.MainTheme 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.common.ui.item.defaultItemPadding
import app.k9mail.feature.account.server.settings.R 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.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.common.mapper.toResourceString
import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsContract.Event import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsContract.Event
import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsContract.State import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsContract.State
@ -100,7 +100,8 @@ internal fun LazyListScope.incomingFormItems(
if (state.isPasswordFieldVisible) { if (state.isPasswordFieldVisible) {
item { item {
PasswordInput( ServerSettingsPasswordInput(
mode = mode,
password = state.password.value, password = state.password.value,
errorMessage = state.password.error?.toResourceString(resources), errorMessage = state.password.error?.toResourceString(resources),
onPasswordChange = { onEvent(Event.PasswordChanged(it)) }, onPasswordChange = { onEvent(Event.PasswordChanged(it)) },

View file

@ -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.K9Theme
import app.k9mail.core.ui.compose.theme.MainTheme import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme 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.Event
import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract.State import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract.State
import app.k9mail.feature.account.server.settings.ui.outgoing.content.outgoingFormItems import app.k9mail.feature.account.server.settings.ui.outgoing.content.outgoingFormItems
@Composable @Composable
internal fun OutgoingServerSettingsContent( internal fun OutgoingServerSettingsContent(
mode: InteractionMode,
state: State, state: State,
onEvent: (Event) -> Unit, onEvent: (Event) -> Unit,
contentPadding: PaddingValues, contentPadding: PaddingValues,
@ -45,6 +47,7 @@ internal fun OutgoingServerSettingsContent(
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.default), verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.default),
) { ) {
outgoingFormItems( outgoingFormItems(
mode = mode,
state = state, state = state,
onEvent = onEvent, onEvent = onEvent,
resources = resources, resources = resources,
@ -58,8 +61,9 @@ internal fun OutgoingServerSettingsContent(
internal fun OutgoingServerSettingsContentK9Preview() { internal fun OutgoingServerSettingsContentK9Preview() {
K9Theme { K9Theme {
OutgoingServerSettingsContent( OutgoingServerSettingsContent(
onEvent = { }, mode = InteractionMode.Create,
state = State(), state = State(),
onEvent = { },
contentPadding = PaddingValues(), contentPadding = PaddingValues(),
) )
} }
@ -70,6 +74,7 @@ internal fun OutgoingServerSettingsContentK9Preview() {
internal fun OutgoingServerSettingsContentThunderbirdPreview() { internal fun OutgoingServerSettingsContentThunderbirdPreview() {
ThunderbirdTheme { ThunderbirdTheme {
OutgoingServerSettingsContent( OutgoingServerSettingsContent(
mode = InteractionMode.Create,
onEvent = { }, onEvent = { },
state = State(), state = State(),
contentPadding = PaddingValues(), contentPadding = PaddingValues(),

View file

@ -64,6 +64,7 @@ fun OutgoingServerSettingsScreen(
modifier = modifier, modifier = modifier,
) { innerPadding -> ) { innerPadding ->
OutgoingServerSettingsContent( OutgoingServerSettingsContent(
mode = viewModel.mode,
state = state.value, state = state.value,
onEvent = { dispatch(it) }, onEvent = { dispatch(it) },
contentPadding = innerPadding, contentPadding = innerPadding,

View file

@ -7,15 +7,16 @@ import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource 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.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.SelectInput
import app.k9mail.core.ui.compose.designsystem.molecule.input.TextInput import app.k9mail.core.ui.compose.designsystem.molecule.input.TextInput
import app.k9mail.core.ui.compose.theme.MainTheme 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.AuthenticationType
import app.k9mail.feature.account.common.domain.entity.ConnectionSecurity 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.common.ui.item.defaultItemPadding
import app.k9mail.feature.account.server.settings.R 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.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.common.mapper.toResourceString
import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract.Event 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.OutgoingServerSettingsContract.State
@ -24,6 +25,7 @@ import app.k9mail.feature.account.server.settings.ui.outgoing.isUsernameFieldVis
@Suppress("LongMethod") @Suppress("LongMethod")
internal fun LazyListScope.outgoingFormItems( internal fun LazyListScope.outgoingFormItems(
mode: InteractionMode,
state: State, state: State,
onEvent: (Event) -> Unit, onEvent: (Event) -> Unit,
resources: Resources, resources: Resources,
@ -91,7 +93,8 @@ internal fun LazyListScope.outgoingFormItems(
if (state.isPasswordFieldVisible) { if (state.isPasswordFieldVisible) {
item { item {
PasswordInput( ServerSettingsPasswordInput(
mode = mode,
password = state.password.value, password = state.password.value,
errorMessage = state.password.error?.toResourceString(resources), errorMessage = state.password.error?.toResourceString(resources),
onPasswordChange = { onEvent(Event.PasswordChanged(it)) }, onPasswordChange = { onEvent(Event.PasswordChanged(it)) },