adding ability to show the raw exception information on login errors

This commit is contained in:
Adam Brown 2022-09-30 21:38:45 +01:00
parent 7f6f01987a
commit 04b6cf5375
1 changed files with 22 additions and 2 deletions

View File

@ -1,15 +1,16 @@
package app.dapk.st.login package app.dapk.st.login
import android.widget.Toast import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Visibility import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material.icons.filled.Web import androidx.compose.material.icons.filled.Web
import androidx.compose.material.icons.outlined.Lock import androidx.compose.material.icons.outlined.Lock
import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -49,10 +50,27 @@ fun LoginScreen(loginViewModel: LoginViewModel, onLoggedIn: () -> Unit) {
when (val state = loginViewModel.state) { when (val state = loginViewModel.state) {
is Error -> { is Error -> {
val openDetailsDialog = remember { mutableStateOf(false) }
if (openDetailsDialog.value) {
AlertDialog(
onDismissRequest = { openDetailsDialog.value = false },
confirmButton = {
Button(onClick = { openDetailsDialog.value = false }) {
Text("OK")
}
},
title = { Text("Details") },
text = {
Text(state.cause.message ?: "Unknown")
}
)
}
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) { Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
Column(horizontalAlignment = Alignment.CenterHorizontally) { Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Something went wrong") Text("Something went wrong")
Spacer(modifier = Modifier.height(6.dp)) Text("Tap for more details".uppercase(), fontSize = 12.sp, modifier = Modifier.clickable { openDetailsDialog.value = true }.padding(12.dp))
Spacer(modifier = Modifier.height(12.dp))
Button(onClick = { Button(onClick = {
loginViewModel.start() loginViewModel.start()
}) { }) {
@ -61,11 +79,13 @@ fun LoginScreen(loginViewModel: LoginViewModel, onLoggedIn: () -> Unit) {
} }
} }
} }
Loading -> { Loading -> {
Box(contentAlignment = Alignment.Center) { Box(contentAlignment = Alignment.Center) {
CircularProgressIndicator() CircularProgressIndicator()
} }
} }
is Content -> is Content ->
Row { Row {
Spacer(modifier = Modifier.weight(0.1f)) Spacer(modifier = Modifier.weight(0.1f))