mirror of
https://github.com/ouchadam/small-talk.git
synced 2025-02-01 20:16:44 +01:00
providing more details to the import errors via dialog
This commit is contained in:
parent
2e91ae5b67
commit
9ec9797d17
@ -3,6 +3,13 @@ package app.dapk.st.core.extensions
|
||||
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 <reified T> Any.takeAs(): T? {
|
||||
return when (this) {
|
||||
is T -> this
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <T, T1 : T, T2 : T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean, predicate2: (T) -> Boolean): Pair<T1, T2>? {
|
||||
var firstValue: T1? = null
|
||||
|
@ -40,6 +40,7 @@ import app.dapk.st.core.Lce
|
||||
import app.dapk.st.core.StartObserving
|
||||
import app.dapk.st.core.components.CenteredLoading
|
||||
import app.dapk.st.core.components.Header
|
||||
import app.dapk.st.core.extensions.takeAs
|
||||
import app.dapk.st.core.getActivity
|
||||
import app.dapk.st.design.components.*
|
||||
import app.dapk.st.matrix.crypto.ImportResult
|
||||
@ -149,22 +150,21 @@ internal fun SettingsScreen(viewModel: SettingsViewModel, onSignOut: () -> Unit,
|
||||
}
|
||||
|
||||
is ImportResult.Error -> {
|
||||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
val message = when (val type = result.cause) {
|
||||
ImportResult.Error.Type.NoKeysFound -> "No keys found in the file"
|
||||
ImportResult.Error.Type.UnexpectedDecryptionOutput -> "Unable to decrypt file, double check your passphrase"
|
||||
is ImportResult.Error.Type.Unknown -> "${type.cause::class.java.simpleName}: ${type.cause.message}"
|
||||
ImportResult.Error.Type.UnableToOpenFile -> "Unable to open file"
|
||||
ImportResult.Error.Type.InvalidFile -> "Unable to process file"
|
||||
}
|
||||
|
||||
Text(text = "Import failed\n$message", textAlign = TextAlign.Center)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
Button(onClick = { navigator.navigate.upToHome() }) {
|
||||
Text(text = "Close".uppercase())
|
||||
}
|
||||
val message = when (result.cause) {
|
||||
ImportResult.Error.Type.NoKeysFound -> "No keys found in the file"
|
||||
ImportResult.Error.Type.UnexpectedDecryptionOutput -> "Unable to decrypt file, double check your passphrase"
|
||||
is ImportResult.Error.Type.Unknown -> "Unknown error"
|
||||
ImportResult.Error.Type.UnableToOpenFile -> "Unable to open file"
|
||||
ImportResult.Error.Type.InvalidFile -> "Unable to process file"
|
||||
}
|
||||
GenericError(
|
||||
message = message,
|
||||
label = "Close",
|
||||
moreDetails = result.cause.takeAs<ImportResult.Error.Type.Unknown>()?.let {
|
||||
"${it.cause::class.java.simpleName}: ${it.cause.message}"
|
||||
}
|
||||
) {
|
||||
navigator.navigate.upToHome()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user