Add error strings
This commit is contained in:
parent
5b9d08fe8b
commit
7b8107d2bc
6 changed files with 28 additions and 7 deletions
|
@ -46,7 +46,7 @@ internal fun AccountOAuthContent(
|
||||||
item(key = "error") {
|
item(key = "error") {
|
||||||
ErrorItem(
|
ErrorItem(
|
||||||
title = stringResource(id = R.string.account_oauth_loading_error),
|
title = stringResource(id = R.string.account_oauth_loading_error),
|
||||||
// message = state.error.toResourceString(resources),
|
message = state.error.toResourceString(resources),
|
||||||
onRetry = { onEvent(Event.OnRetryClicked) },
|
onRetry = { onEvent(Event.OnRetryClicked) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ interface AccountOAuthContract {
|
||||||
|
|
||||||
sealed interface Error {
|
sealed interface Error {
|
||||||
object NotSupported : Error
|
object NotSupported : Error
|
||||||
object Cancelled : Error
|
object Canceled : Error
|
||||||
|
|
||||||
object BrowserNotAvailable : Error
|
object BrowserNotAvailable : Error
|
||||||
data class Unknown(val error: Exception) : Error
|
data class Unknown(val error: Exception) : Error
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package app.k9mail.feature.account.oauth.ui
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
|
import app.k9mail.feature.account.oauth.R
|
||||||
|
|
||||||
|
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Error
|
||||||
|
|
||||||
|
internal fun Error.toResourceString(resources: Resources): String {
|
||||||
|
return when (this) {
|
||||||
|
Error.BrowserNotAvailable -> resources.getString(R.string.account_oauth_error_browser_not_available)
|
||||||
|
Error.Canceled -> resources.getString(R.string.account_oauth_error_canceled)
|
||||||
|
Error.NotSupported -> resources.getString(R.string.account_oauth_error_not_supported)
|
||||||
|
is Error.Unknown -> resources.getString(R.string.account_oauth_error_failed, error.message)
|
||||||
|
}
|
||||||
|
}
|
|
@ -80,7 +80,7 @@ class AccountOAuthViewModel(
|
||||||
finishSignIn(data)
|
finishSignIn(data)
|
||||||
} else {
|
} else {
|
||||||
updateState { state ->
|
updateState { state ->
|
||||||
state.copy(error = Error.Cancelled)
|
state.copy(error = Error.Canceled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ class AccountOAuthViewModel(
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
when (val result = finishOAuthSignIn.execute(state.value.authorizationState, data)) {
|
when (val result = finishOAuthSignIn.execute(state.value.authorizationState, data)) {
|
||||||
AuthorizationResult.BrowserNotAvailable -> updateErrorState(Error.BrowserNotAvailable)
|
AuthorizationResult.BrowserNotAvailable -> updateErrorState(Error.BrowserNotAvailable)
|
||||||
AuthorizationResult.Canceled -> updateErrorState(Error.Cancelled)
|
AuthorizationResult.Canceled -> updateErrorState(Error.Canceled)
|
||||||
is AuthorizationResult.Failure -> updateErrorState(Error.Unknown(result.error))
|
is AuthorizationResult.Failure -> updateErrorState(Error.Unknown(result.error))
|
||||||
is AuthorizationResult.Success -> {
|
is AuthorizationResult.Success -> {
|
||||||
updateState { state ->
|
updateState { state ->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||||
<string name="account_oauth_title">K-9 Mail</string>
|
<string name="account_oauth_title">K-9 Mail</string>
|
||||||
<string name="account_oauth_button_next">Next</string>
|
<string name="account_oauth_button_next">Next</string>
|
||||||
<string name="account_oauth_button_back">Back</string>
|
<string name="account_oauth_button_back">Back</string>
|
||||||
|
@ -10,4 +10,10 @@
|
||||||
<string name="account_oauth_sign_in_with_google_button_loading">Signing in with Google …</string>
|
<string name="account_oauth_sign_in_with_google_button_loading">Signing in with Google …</string>
|
||||||
<string name="account_oauth_loading_message">Signing in using OAuth</string>
|
<string name="account_oauth_loading_message">Signing in using OAuth</string>
|
||||||
<string name="account_oauth_loading_error">OAuth sign in failed</string>
|
<string name="account_oauth_loading_error">OAuth sign in failed</string>
|
||||||
|
|
||||||
|
<string name="account_oauth_error_canceled">Authorization canceled</string>
|
||||||
|
<string name="account_oauth_error_failed">Authorization failed with the following error: <xliff:g id="error">%s</xliff:g></string>
|
||||||
|
<string name="account_oauth_error_not_supported">OAuth 2.0 is currently not supported with this provider.</string>
|
||||||
|
<string name="account_oauth_error_browser_not_available">The app couldn\'t find a browser to use for granting access to your account.</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -232,7 +232,7 @@ class AccountOAuthViewModelTest {
|
||||||
testSubject.event(Event.OnOAuthResult(resultCode = Activity.RESULT_CANCELED, data = intent))
|
testSubject.event(Event.OnOAuthResult(resultCode = Activity.RESULT_CANCELED, data = intent))
|
||||||
|
|
||||||
val failureState = initialState.copy(
|
val failureState = initialState.copy(
|
||||||
error = Error.Cancelled,
|
error = Error.Canceled,
|
||||||
)
|
)
|
||||||
|
|
||||||
assertThatAndTurbinesConsumed(
|
assertThatAndTurbinesConsumed(
|
||||||
|
@ -275,7 +275,7 @@ class AccountOAuthViewModelTest {
|
||||||
|
|
||||||
val failureState = loadingState.copy(
|
val failureState = loadingState.copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
error = Error.Cancelled,
|
error = Error.Canceled,
|
||||||
)
|
)
|
||||||
|
|
||||||
assertThatAndTurbinesConsumed(
|
assertThatAndTurbinesConsumed(
|
||||||
|
|
Loading…
Reference in a new issue