Split server certificate error screen into two parts
This commit is contained in:
parent
b9a7d17bba
commit
95ae5180e7
3 changed files with 42 additions and 22 deletions
|
@ -7,16 +7,19 @@ interface ServerCertificateErrorContract {
|
|||
interface ViewModel : UnidirectionalViewModel<State, Event, Effect>
|
||||
|
||||
data class State(
|
||||
val hostname: String = "",
|
||||
val isShowServerCertificate: Boolean = false,
|
||||
val errorText: String = "",
|
||||
)
|
||||
|
||||
sealed interface Event {
|
||||
object OnCertificateAcceptedClicked : Event
|
||||
object OnBackClicked : Event
|
||||
data object OnShowAdvancedClicked : Event
|
||||
data object OnCertificateAcceptedClicked : Event
|
||||
data object OnBackClicked : Event
|
||||
}
|
||||
|
||||
sealed interface Effect {
|
||||
object NavigateCertificateAccepted : Effect
|
||||
object NavigateBack : Effect
|
||||
data object NavigateCertificateAccepted : Effect
|
||||
data object NavigateBack : Effect
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,11 +69,19 @@ fun ServerCertificateErrorScreen(
|
|||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
if (state.value.isShowServerCertificate) {
|
||||
ButtonOutlined(
|
||||
text = "Accept consequences and continue",
|
||||
onClick = { dispatch(Event.OnCertificateAcceptedClicked) },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
} else {
|
||||
ButtonOutlined(
|
||||
text = "Advanced",
|
||||
onClick = { dispatch(Event.OnShowAdvancedClicked) },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -110,20 +118,21 @@ fun ServerCertificateErrorScreen(
|
|||
|
||||
Spacer(modifier = Modifier.height(MainTheme.spacings.quadruple))
|
||||
|
||||
val hostname = state.value.hostname
|
||||
TextBody1(
|
||||
text = "The server presented an invalid TLS certificate. " +
|
||||
"Sometimes, this is because of a server misconfiguration. " +
|
||||
"Sometimes it is because someone is trying to attack you or your mail server. " +
|
||||
"If you're not sure what's up, click \"Go back\" and contact the folks who manage your " +
|
||||
"mail server.",
|
||||
text = "The app detected a potential security threat and did not continue to connect to " +
|
||||
"$hostname. If you continue, attackers could try to steal information like your password or " +
|
||||
"emails.",
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(MainTheme.spacings.quadruple))
|
||||
|
||||
if (state.value.isShowServerCertificate) {
|
||||
TextBody1(state.value.errorText)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
|
@ -23,16 +23,30 @@ class ServerCertificateErrorViewModel(
|
|||
private val serverCertificateError: ServerCertificateError? = certificateErrorRepository.getCertificateError()
|
||||
|
||||
init {
|
||||
setErrorMessage(buildErrorMessage(serverCertificateError))
|
||||
serverCertificateError?.let { serverCertificateError ->
|
||||
updateState {
|
||||
it.copy(
|
||||
hostname = serverCertificateError.hostname,
|
||||
errorText = buildErrorMessage(serverCertificateError),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun event(event: Event) {
|
||||
when (event) {
|
||||
Event.OnShowAdvancedClicked -> showAdvanced()
|
||||
Event.OnCertificateAcceptedClicked -> acceptCertificate()
|
||||
Event.OnBackClicked -> navigateBack()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showAdvanced() {
|
||||
updateState {
|
||||
it.copy(isShowServerCertificate = true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun acceptCertificate() {
|
||||
val certificateError = requireNotNull(serverCertificateError)
|
||||
|
||||
|
@ -96,10 +110,4 @@ class ServerCertificateErrorViewModel(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setErrorMessage(errorText: String) {
|
||||
updateState {
|
||||
it.copy(errorText = errorText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue