providing more details to the import errors via dialog

This commit is contained in:
Adam Brown 2022-10-09 15:30:00 +01:00
parent 2e91ae5b67
commit 9ec9797d17
2 changed files with 22 additions and 15 deletions

View File

@ -3,6 +3,13 @@ package app.dapk.st.core.extensions
inline fun <T> T?.ifNull(block: () -> T): T = this ?: block() inline fun <T> T?.ifNull(block: () -> T): T = this ?: block()
inline fun <T> ifOrNull(condition: Boolean, block: () -> T): T? = if (condition) block() else null inline fun <T> ifOrNull(condition: Boolean, block: () -> T): T? = if (condition) block() else null
inline fun <reified T> Any.takeAs(): T? {
return when (this) {
is T -> this
else -> null
}
}
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
inline fun <T, T1 : T, T2 : T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean, predicate2: (T) -> Boolean): Pair<T1, T2>? { inline fun <T, T1 : T, T2 : T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean, predicate2: (T) -> Boolean): Pair<T1, T2>? {
var firstValue: T1? = null var firstValue: T1? = null

View File

@ -40,6 +40,7 @@ import app.dapk.st.core.Lce
import app.dapk.st.core.StartObserving import app.dapk.st.core.StartObserving
import app.dapk.st.core.components.CenteredLoading import app.dapk.st.core.components.CenteredLoading
import app.dapk.st.core.components.Header import app.dapk.st.core.components.Header
import app.dapk.st.core.extensions.takeAs
import app.dapk.st.core.getActivity import app.dapk.st.core.getActivity
import app.dapk.st.design.components.* import app.dapk.st.design.components.*
import app.dapk.st.matrix.crypto.ImportResult import app.dapk.st.matrix.crypto.ImportResult
@ -149,22 +150,21 @@ internal fun SettingsScreen(viewModel: SettingsViewModel, onSignOut: () -> Unit,
} }
is ImportResult.Error -> { is ImportResult.Error -> {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { val message = when (result.cause) {
Column(horizontalAlignment = Alignment.CenterHorizontally) { ImportResult.Error.Type.NoKeysFound -> "No keys found in the file"
val message = when (val type = result.cause) { ImportResult.Error.Type.UnexpectedDecryptionOutput -> "Unable to decrypt file, double check your passphrase"
ImportResult.Error.Type.NoKeysFound -> "No keys found in the file" is ImportResult.Error.Type.Unknown -> "Unknown error"
ImportResult.Error.Type.UnexpectedDecryptionOutput -> "Unable to decrypt file, double check your passphrase" ImportResult.Error.Type.UnableToOpenFile -> "Unable to open file"
is ImportResult.Error.Type.Unknown -> "${type.cause::class.java.simpleName}: ${type.cause.message}" ImportResult.Error.Type.InvalidFile -> "Unable to process file"
ImportResult.Error.Type.UnableToOpenFile -> "Unable to open file" }
ImportResult.Error.Type.InvalidFile -> "Unable to process file" GenericError(
} message = message,
label = "Close",
Text(text = "Import failed\n$message", textAlign = TextAlign.Center) moreDetails = result.cause.takeAs<ImportResult.Error.Type.Unknown>()?.let {
Spacer(modifier = Modifier.height(12.dp)) "${it.cause::class.java.simpleName}: ${it.cause.message}"
Button(onClick = { navigator.navigate.upToHome() }) {
Text(text = "Close".uppercase())
}
} }
) {
navigator.navigate.upToHome()
} }
} }