From e80a02579a25f2e668360393bb014d71070f0c88 Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 3 Jul 2023 16:58:39 +0200 Subject: [PATCH] Hide password field in incoming server settings when not needed --- .../setup/domain/entity/AuthenticationType.kt | 24 ++++++++++++++----- .../incoming/AccountIncomingConfigContent.kt | 16 +++++++------ .../AccountIncomingConfigStateExtensions.kt | 4 ++++ 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/incoming/AccountIncomingConfigStateExtensions.kt diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/AuthenticationType.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/AuthenticationType.kt index fec2aa066..50939a8ef 100644 --- a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/AuthenticationType.kt +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/AuthenticationType.kt @@ -2,12 +2,24 @@ package app.k9mail.feature.account.setup.domain.entity import kotlinx.collections.immutable.toImmutableList -enum class AuthenticationType { - None, - PasswordCleartext, - PasswordEncrypted, - ClientCertificate, - OAuth2, +enum class AuthenticationType( + val isPasswordRequired: Boolean, +) { + None( + isPasswordRequired = false, + ), + PasswordCleartext( + isPasswordRequired = true, + ), + PasswordEncrypted( + isPasswordRequired = true, + ), + ClientCertificate( + isPasswordRequired = false, + ), + OAuth2( + isPasswordRequired = false, + ), ; companion object { diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/incoming/AccountIncomingConfigContent.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/incoming/AccountIncomingConfigContent.kt index b4771e29a..5665704be 100644 --- a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/incoming/AccountIncomingConfigContent.kt +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/incoming/AccountIncomingConfigContent.kt @@ -155,13 +155,15 @@ internal fun AccountIncomingConfigContent( ) } - item { - PasswordInput( - password = state.password.value, - errorMessage = state.password.error?.toResourceString(resources), - onPasswordChange = { onEvent(Event.PasswordChanged(it)) }, - contentPadding = defaultItemPadding(), - ) + if (state.isPasswordFieldVisible) { + item { + PasswordInput( + password = state.password.value, + errorMessage = state.password.error?.toResourceString(resources), + onPasswordChange = { onEvent(Event.PasswordChanged(it)) }, + contentPadding = defaultItemPadding(), + ) + } } item { diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/incoming/AccountIncomingConfigStateExtensions.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/incoming/AccountIncomingConfigStateExtensions.kt new file mode 100644 index 000000000..55491d2d3 --- /dev/null +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/incoming/AccountIncomingConfigStateExtensions.kt @@ -0,0 +1,4 @@ +package app.k9mail.feature.account.setup.ui.incoming + +internal val AccountIncomingConfigContract.State.isPasswordFieldVisible: Boolean + get() = authenticationType.isPasswordRequired