fix toast spam in layout editor

This commit is contained in:
Helium314 2025-02-20 18:24:59 +01:00
parent 31f7ef6182
commit 4efc33dba4

View file

@ -41,7 +41,6 @@ fun LayoutEditDialog(
) { ) {
val ctx = LocalContext.current val ctx = LocalContext.current
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
var job: Job? = null
val startIsCustom = LayoutUtilsCustom.isCustomLayout(initialLayoutName) val startIsCustom = LayoutUtilsCustom.isCustomLayout(initialLayoutName)
var displayNameValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { var displayNameValue by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(TextFieldValue( mutableStateOf(TextFieldValue(
@ -57,7 +56,7 @@ fun LayoutEditDialog(
TextInputDialog( TextInputDialog(
onDismissRequest = { onDismissRequest = {
job?.cancel() errorJob?.cancel()
onDismissRequest() onDismissRequest()
}, },
onConfirmed = { onConfirmed = {
@ -84,10 +83,9 @@ fun LayoutEditDialog(
}, },
checkTextValid = { checkTextValid = {
val valid = LayoutUtilsCustom.checkLayout(it, ctx) val valid = LayoutUtilsCustom.checkLayout(it, ctx)
job?.cancel() errorJob?.cancel()
if (!valid) { if (!valid) {
job = scope.launch { errorJob = scope.launch {
// todo: this can end up in toast-spam
val message = Log.getLog(10) val message = Log.getLog(10)
.lastOrNull { it.tag == "LayoutUtilsCustom" }?.message .lastOrNull { it.tag == "LayoutUtilsCustom" }?.message
?.split("\n")?.take(2)?.joinToString("\n") ?.split("\n")?.take(2)?.joinToString("\n")
@ -103,3 +101,6 @@ fun LayoutEditDialog(
reducePadding = true, reducePadding = true,
) )
} }
// the job is here to make sure old jobs are canceled
private var errorJob: Job? = null