Change account server certificate feature to theme 2

MainTheme.colors.onBackgroundSecondary does not exist and needs a design review
This commit is contained in:
Wolf-Martell Montwé 2024-04-22 17:09:12 +02:00
parent 041330ae1f
commit 19a7c07be3
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
6 changed files with 168 additions and 156 deletions

View file

@ -0,0 +1,49 @@
package app.k9mail.feature.account.server.certificate.ui
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.rememberScrollState
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import app.k9mail.core.ui.compose.common.koin.koinPreview
import app.k9mail.core.ui.compose.designsystem.PreviewWithTheme
import app.k9mail.feature.account.server.certificate.domain.entity.FormattedServerCertificateError
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateProperties
import okio.ByteString.Companion.decodeHex
@Composable
@Preview(showBackground = true)
internal fun ServerCertificateErrorContentPreview() {
val state = ServerCertificateErrorContract.State(
isShowServerCertificate = true,
certificateError = FormattedServerCertificateError(
hostname = "mail.domain.example",
serverCertificateProperties = ServerCertificateProperties(
subjectAlternativeNames = listOf("*.domain.example", "domain.example"),
notValidBefore = "January 1, 2023, 12:00 AM",
notValidAfter = "December 31, 2023, 11:59 PM",
subject = "CN=*.domain.example",
issuer = "CN=test, O=MZLA",
fingerprintSha1 = "33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d".decodeHex(),
fingerprintSha256 = "1894a19c85ba153acbf743ac4e43fc004c891604b26f8c69e1e83ea2afc7c48f".decodeHex(),
fingerprintSha512 = (
"81381f1dacd4824a6c503fd07057763099c12b8309d0abcec4000c9060cbbfa6" +
"7988b2ada669ab4837fcd3d4ea6e2b8db2b9da9197d5112fb369fd006da545de"
).decodeHex(),
),
),
)
koinPreview {
factory<ServerNameFormatter> { DefaultServerNameFormatter() }
factory<FingerprintFormatter> { DefaultFingerprintFormatter() }
} WithContent {
PreviewWithTheme {
ServerCertificateErrorContent(
innerPadding = PaddingValues(all = 0.dp),
state = state,
scrollState = rememberScrollState(),
)
}
}
}

View file

@ -0,0 +1,74 @@
package app.k9mail.feature.account.server.certificate.ui
import androidx.compose.runtime.Composable
import app.k9mail.core.ui.compose.common.annotation.PreviewDevices
import app.k9mail.core.ui.compose.common.koin.koinPreview
import app.k9mail.core.ui.compose.designsystem.PreviewWithTheme
import app.k9mail.feature.account.server.certificate.data.InMemoryServerCertificateErrorRepository
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.server.certificate.domain.usecase.FormatServerCertificateError
import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate
@Composable
@PreviewDevices
internal fun ServerCertificateErrorScreenPreview() {
val inputStream = """
-----BEGIN CERTIFICATE-----
MIIE8jCCA9qgAwIBAgISA3bsPKY1eoe/RiBO2t8fUvh1MA0GCSqGSIb3DQEBCwUA
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
EwJSMzAeFw0yMzA3MjEyMDU1MTJaFw0yMzEwMTkyMDU1MTFaMBcxFTATBgNVBAMM
DCouYmFkc3NsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJgw
o/dYmPaujmm7sqIuZCe5/kyMwDYKo/pWeeXSvQxRXhxiVvd2Xu9PG0ZXW2R0xOSr
BpaRWm6MXxEnNqNr+n22j9US6M62zJpcuU4tQ0J8xRyIGL6rM53z59rEnCdkF9HQ
+7y7PBlVXCm0jrw51h3Bg5qryvTFyimIbqGw0UJhM7m/NaVJWZyBRwHp7emXxRJC
kC7pdX462c+m/7rQ06iohqUt6mf0DkUH1QjpaVbZm8CBs/GSiLB3LdMHj1uvrXgH
z8dp0nQ3eVRCjuD1xVcZnFoeEa/W3a9ZdcBj1phr9XOwaqYMeAv64g2w40G6fXMH
9DpHuFarRtleQusiPAMCAwEAAaOCAhswggIXMA4GA1UdDwEB/wQEAwIFoDAdBgNV
HSUEFjAUBggrB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Indent().byteInputStream()
val certificateFactory = CertificateFactory.getInstance("X.509")
val certificate = certificateFactory.generateCertificate(inputStream) as X509Certificate
val serverCertificateError = ServerCertificateError(
hostname = "mail.domain.example",
port = 143,
certificateChain = listOf(certificate),
)
koinPreview {
factory<ServerNameFormatter> { DefaultServerNameFormatter() }
factory<FingerprintFormatter> { DefaultFingerprintFormatter() }
} WithContent {
PreviewWithTheme {
ServerCertificateErrorScreen(
onCertificateAccepted = {},
onBack = {},
viewModel = ServerCertificateErrorViewModel(
addServerCertificateException = { _, _, _ -> },
certificateErrorRepository = InMemoryServerCertificateErrorRepository(serverCertificateError),
formatServerCertificateError = FormatServerCertificateError(),
initialState = ServerCertificateErrorContract.State(isShowServerCertificate = false),
),
)
}
}
}

View file

@ -0,0 +1,41 @@
package app.k9mail.feature.account.server.certificate.ui
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.common.koin.koinPreview
import app.k9mail.core.ui.compose.designsystem.PreviewWithTheme
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateProperties
import okio.ByteString.Companion.decodeHex
@Composable
@Preview(showBackground = true)
internal fun ServerCertificateViewPreview() {
val serverCertificateProperties = ServerCertificateProperties(
subjectAlternativeNames = listOf(
"*.domain.example",
"domain.example",
"quite.the.long.domain.name.that.hopefully.exceeds.the.available.width.example",
),
notValidBefore = "January 1, 2023, 12:00 AM",
notValidAfter = "December 31, 2023, 11:59 PM",
subject = "CN=*.domain.example",
issuer = "CN=test, O=MZLA",
fingerprintSha1 = "33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d".decodeHex(),
fingerprintSha256 = "1894a19c85ba153acbf743ac4e43fc004c891604b26f8c69e1e83ea2afc7c48f".decodeHex(),
fingerprintSha512 = (
"81381f1dacd4824a6c503fd07057763099c12b8309d0abcec4000c9060cbbfa6" +
"7988b2ada669ab4837fcd3d4ea6e2b8db2b9da9197d5112fb369fd006da545de"
).decodeHex(),
)
koinPreview {
factory<ServerNameFormatter> { DefaultServerNameFormatter() }
factory<FingerprintFormatter> { DefaultFingerprintFormatter() }
} WithContent {
PreviewWithTheme {
ServerCertificateView(
serverCertificateProperties = serverCertificateProperties,
)
}
}
}

View file

@ -9,15 +9,11 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import app.k9mail.core.ui.compose.common.baseline.withBaseline
import app.k9mail.core.ui.compose.common.koin.koinPreview
import app.k9mail.core.ui.compose.common.resources.annotatedStringResource
import app.k9mail.core.ui.compose.common.text.bold
import app.k9mail.core.ui.compose.designsystem.atom.icon.Icon
@ -26,13 +22,10 @@ import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodyLarge
import app.k9mail.core.ui.compose.designsystem.atom.text.TextHeadlineMedium
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleMedium
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.theme2.MainTheme
import app.k9mail.feature.account.server.certificate.R
import app.k9mail.feature.account.server.certificate.domain.entity.FormattedServerCertificateError
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateProperties
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.State
import okio.ByteString.Companion.decodeHex
import org.koin.compose.koinInject
@Composable
@ -113,40 +106,3 @@ private fun CertificateErrorDescription(
),
)
}
@Composable
@Preview(showBackground = true)
internal fun ServerCertificateErrorContentPreview() {
val state = State(
isShowServerCertificate = true,
certificateError = FormattedServerCertificateError(
hostname = "mail.domain.example",
serverCertificateProperties = ServerCertificateProperties(
subjectAlternativeNames = listOf("*.domain.example", "domain.example"),
notValidBefore = "January 1, 2023, 12:00 AM",
notValidAfter = "December 31, 2023, 11:59 PM",
subject = "CN=*.domain.example",
issuer = "CN=test, O=MZLA",
fingerprintSha1 = "33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d".decodeHex(),
fingerprintSha256 = "1894a19c85ba153acbf743ac4e43fc004c891604b26f8c69e1e83ea2afc7c48f".decodeHex(),
fingerprintSha512 = (
"81381f1dacd4824a6c503fd07057763099c12b8309d0abcec4000c9060cbbfa6" +
"7988b2ada669ab4837fcd3d4ea6e2b8db2b9da9197d5112fb369fd006da545de"
).decodeHex(),
),
),
)
koinPreview {
factory<ServerNameFormatter> { DefaultServerNameFormatter() }
factory<FingerprintFormatter> { DefaultFingerprintFormatter() }
} WithContent {
K9Theme {
ServerCertificateErrorContent(
innerPadding = PaddingValues(all = 0.dp),
state = state,
scrollState = rememberScrollState(),
)
}
}
}

View file

@ -14,26 +14,18 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.k9mail.core.ui.compose.common.annotation.PreviewDevices
import app.k9mail.core.ui.compose.common.koin.koinPreview
import app.k9mail.core.ui.compose.common.mvi.observe
import app.k9mail.core.ui.compose.designsystem.atom.Surface
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonFilled
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonOutlined
import app.k9mail.core.ui.compose.designsystem.template.ResponsiveWidthContainer
import app.k9mail.core.ui.compose.designsystem.template.Scaffold
import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme2.MainTheme
import app.k9mail.feature.account.server.certificate.R
import app.k9mail.feature.account.server.certificate.data.InMemoryServerCertificateErrorRepository
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.server.certificate.domain.usecase.FormatServerCertificateError
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.Effect
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.Event
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.State
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.ViewModel
import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate
import org.koin.androidx.compose.koinViewModel
@Composable
@ -126,66 +118,3 @@ private fun ButtonBar(
}
}
}
@Composable
@PreviewDevices
internal fun ServerCertificateErrorScreenK9Preview() {
val inputStream = """
-----BEGIN CERTIFICATE-----
MIIE8jCCA9qgAwIBAgISA3bsPKY1eoe/RiBO2t8fUvh1MA0GCSqGSIb3DQEBCwUA
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
EwJSMzAeFw0yMzA3MjEyMDU1MTJaFw0yMzEwMTkyMDU1MTFaMBcxFTATBgNVBAMM
DCouYmFkc3NsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJgw
o/dYmPaujmm7sqIuZCe5/kyMwDYKo/pWeeXSvQxRXhxiVvd2Xu9PG0ZXW2R0xOSr
BpaRWm6MXxEnNqNr+n22j9US6M62zJpcuU4tQ0J8xRyIGL6rM53z59rEnCdkF9HQ
+7y7PBlVXCm0jrw51h3Bg5qryvTFyimIbqGw0UJhM7m/NaVJWZyBRwHp7emXxRJC
kC7pdX462c+m/7rQ06iohqUt6mf0DkUH1QjpaVbZm8CBs/GSiLB3LdMHj1uvrXgH
z8dp0nQ3eVRCjuD1xVcZnFoeEa/W3a9ZdcBj1phr9XOwaqYMeAv64g2w40G6fXMH
9DpHuFarRtleQusiPAMCAwEAAaOCAhswggIXMA4GA1UdDwEB/wQEAwIFoDAdBgNV
HSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4E
FgQU1M4J2vX/9DWJnsAtofmT+94js/YwHwYDVR0jBBgwFoAUFC6zF7dYVsuuUAlA
5h+vnYsUwsYwVQYIKwYBBQUHAQEESTBHMCEGCCsGAQUFBzABhhVodHRwOi8vcjMu
by5sZW5jci5vcmcwIgYIKwYBBQUHMAKGFmh0dHA6Ly9yMy5pLmxlbmNyLm9yZy8w
IwYDVR0RBBwwGoIMKi5iYWRzc2wuY29tggpiYWRzc2wuY29tMBMGA1UdIAQMMAow
CAYGZ4EMAQIBMIIBBQYKKwYBBAHWeQIEAgSB9gSB8wDxAHYAtz77JN+cTbp18jnF
ulj0bF38Qs96nzXEnh0JgSXttJkAAAGJenMebAAABAMARzBFAiAH7A3OWC1AKOcO
jsOP39nzkyoIdrwYFHOOW1qKkLrk9gIhAJD0xFn5FwJvag3K6mTXAlW1EvIy9joA
okiPniKVBIztAHcAejKMVNi3LbYg6jjgUh7phBZwMhOFTTvSK8E6V6NS61IAAAGJ
enMehwAABAMASDBGAiEAvRyLnINSJQ0WyfcU8L0PY5z7//Gq8P9i2HJvZJvnfBkC
IQCHslQMJaOg+rn9+2WW4KKgYW/yDrvBbiVABW5CcYWR0DANBgkqhkiG9w0BAQsF
AAOCAQEAB/JpXHqRnGmCFz3f0hx7mJYY/auSNWnOgpdRpc3JXzcOHHUd+569UGtu
TSMAFEGNXYTbXrG52iGBCrdfe1kkRokg7/KtUvFRelkoNt4FN/4/zVjBxINXVIMb
/7toq4OxBF/sz4SU+eXanmwJyOMmNQzM94zqDwrEmMNuNLYshdWn7XyJCXIM4X+6
8M/anh/pi2AviLHH9pszkeuH3AjGJR68cPf+QKC4XcFloR08fhx0jKl8LBa4A6Nm
o7IlPgdD9rzZCsbYe+VNBQWY3358u7ifOJG8r2jXzyHKgUC+OBXgz3kjrClzJfl1
pjcJhNU1UQtIVERwmxI9F5oQqUyxvA==
-----END CERTIFICATE-----
""".trimIndent().byteInputStream()
val certificateFactory = CertificateFactory.getInstance("X.509")
val certificate = certificateFactory.generateCertificate(inputStream) as X509Certificate
val serverCertificateError = ServerCertificateError(
hostname = "mail.domain.example",
port = 143,
certificateChain = listOf(certificate),
)
koinPreview {
factory<ServerNameFormatter> { DefaultServerNameFormatter() }
factory<FingerprintFormatter> { DefaultFingerprintFormatter() }
} WithContent {
K9Theme {
ServerCertificateErrorScreen(
onCertificateAccepted = {},
onBack = {},
viewModel = ServerCertificateErrorViewModel(
addServerCertificateException = { _, _, _ -> },
certificateErrorRepository = InMemoryServerCertificateErrorRepository(serverCertificateError),
formatServerCertificateError = FormatServerCertificateError(),
initialState = State(isShowServerCertificate = false),
),
)
}
}
}

View file

@ -8,18 +8,14 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.common.koin.koinPreview
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodyLarge
import app.k9mail.core.ui.compose.designsystem.atom.text.TextLabelSmall
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleLarge
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleSmall
import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme2.MainTheme
import app.k9mail.feature.account.server.certificate.R
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateProperties
import okio.ByteString
import okio.ByteString.Companion.decodeHex
import org.koin.compose.koinInject
@Composable
@ -85,7 +81,7 @@ private fun Fingerprint(
) {
val formattedFingerprint = fingerprintFormatter.format(
fingerprint,
separatorColor = MainTheme.colors.onBackgroundSecondary,
separatorColor = MainTheme.colors.onSurfaceVariant,
)
Column {
@ -105,36 +101,3 @@ private fun BulletedListItem(text: String) {
TextBodyLarge(text = text)
}
}
@Composable
@Preview(showBackground = true)
internal fun ServerCertificateViewPreview() {
val serverCertificateProperties = ServerCertificateProperties(
subjectAlternativeNames = listOf(
"*.domain.example",
"domain.example",
"quite.the.long.domain.name.that.hopefully.exceeds.the.available.width.example",
),
notValidBefore = "January 1, 2023, 12:00 AM",
notValidAfter = "December 31, 2023, 11:59 PM",
subject = "CN=*.domain.example",
issuer = "CN=test, O=MZLA",
fingerprintSha1 = "33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d".decodeHex(),
fingerprintSha256 = "1894a19c85ba153acbf743ac4e43fc004c891604b26f8c69e1e83ea2afc7c48f".decodeHex(),
fingerprintSha512 = (
"81381f1dacd4824a6c503fd07057763099c12b8309d0abcec4000c9060cbbfa6" +
"7988b2ada669ab4837fcd3d4ea6e2b8db2b9da9197d5112fb369fd006da545de"
).decodeHex(),
)
koinPreview {
factory<ServerNameFormatter> { DefaultServerNameFormatter() }
factory<FingerprintFormatter> { DefaultFingerprintFormatter() }
} WithContent {
K9Theme {
ServerCertificateView(
serverCertificateProperties = serverCertificateProperties,
)
}
}
}