Skip to content
Snippets Groups Projects
Commit 88a29775 authored by Jonas Broeckmann's avatar Jonas Broeckmann
Browse files

Improve device logout confirmation flow

parent 71ddc989
No related branches found
No related tags found
No related merge requests found
Pipeline #1654583 failed
......@@ -335,19 +335,112 @@ private fun ConfirmLogoutDeviceDialog(
onDismiss: () -> Unit,
onConfirm: () -> Unit,
modifier: Modifier = Modifier
) = AlertDialog(
onDismissRequest = onDismiss,
confirmButton = {
Button(onClick = onConfirm) { Text("Ausloggen") }
},
modifier,
dismissButton = {
TextButton(onClick = onDismiss) { Text("Abbrechen") }
},
text = {
Text("Möchtest du das Gerät wirklich ausloggen?")
) {
val toasts = remember { ToastsState() }
Toasts(toasts)
val target = 42
val minSolution = -10
val maxSolution = 10
fun newRandomEquation() = randomEquation(
target = target,
minSolution = minSolution,
maxSolution = maxSolution
)
var equationAndSolution by remember {
mutableStateOf(newRandomEquation())
}
)
val (equation, solution) = equationAndSolution
var userAnswer by remember { mutableStateOf<Float?>(null) }
var userAnswerIncorrect by remember { mutableStateOf(false) }
fun submitUserAnswer() {
if (userAnswer?.toInt() == solution) {
onConfirm()
} else {
userAnswerIncorrect = true
}
}
AlertDialog(
onDismissRequest = onDismiss,
confirmButton = {
Button(
onClick = { submitUserAnswer() },
enabled = userAnswer != null
) { Text("Ausloggen") }
},
modifier,
dismissButton = {
TextButton(onClick = onDismiss) { Text("Abbrechen") }
},
icon = {
Icon(Icons.Rounded.Warning, "Achtung")
},
title = {
Text("Gerät wirklich ausloggen?")
},
text = {
ColumnCenter(Modifier.width(IntrinsicSize.Max)) {
Text("Bitte löse die folgende Gleichung, um fortzufahren:")
Box(Modifier.fillMaxWidth()) {
Text(
text = equation,
modifier = Modifier.padding(24.dp).align(Alignment.Center),
style = MaterialTheme.typography.titleMedium.copy(
fontFamily = FontFamily.Serif
)
)
IconButton(
onClick = {
equationAndSolution = newRandomEquation()
userAnswer = null
userAnswerIncorrect = false
},
modifier = Modifier.align(Alignment.CenterEnd)
) {
Icon(Icons.Default.Refresh, "Neue Gleichung")
}
}
var currentInput by remember { mutableStateOf("") }
LaunchedEffect(userAnswer) {
if (currentInput.toIntOrNull() != userAnswer?.toInt()) {
currentInput = "${userAnswer?.toInt() ?: ""}"
}
}
OutlinedTextField(
value = currentInput,
onValueChange = {
val sanitized = it.filter { c -> c.isDigit() || c in setOf('-', '+', '.', ',') }
currentInput = sanitized
userAnswer = sanitized.toIntOrNull()?.toFloat()
userAnswerIncorrect = false
},
modifier = Modifier.defaultMinSize(minWidth = 1.dp),
textStyle = LocalTextStyle.current.copy(
fontFamily = FontFamily.Serif
),
placeholder = { Text("?") },
prefix = {
Text("x = ", fontFamily = FontFamily.Serif)
},
isError = userAnswerIncorrect || (currentInput.isNotEmpty() && userAnswer == null),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions(onDone = { submitUserAnswer() })
)
}
},
iconContentColor = MaterialTheme.colorScheme.error
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment