From c89220bc0ca2841e8412dc982d5af48897e090a1 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 3 Oct 2024 21:42:45 +0200 Subject: [PATCH] Implemented catching and displaying EPC QR Code generation errors --- .../banking/ui/screens/CreateEpcQrCodeScreen.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/CreateEpcQrCodeScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/CreateEpcQrCodeScreen.kt index 5405605..e4c6c15 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/CreateEpcQrCodeScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/CreateEpcQrCodeScreen.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll +import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment @@ -21,7 +22,9 @@ import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.extensions.ImeNext import net.codinux.banking.ui.forms.OutlinedTextField import net.codinux.banking.ui.forms.Select +import net.codinux.banking.ui.model.Config.NewLine import net.codinux.banking.ui.service.createImageBitmap +import net.codinux.log.Log private val epcQrCodeService = DI.epcQrCodeService @@ -57,10 +60,18 @@ fun CreateEpcQrCodeScreen(onClosed: () -> Unit) { var informationForUser by remember { mutableStateOf("") } + var epcQrCodeGeneratingError by remember { mutableStateOf(null) } + val epcQrCodeBytes by remember(receiverName, iban, bic, amount, reference, informationForUser) { derivedStateOf { if (receiverName.isNotBlank() && iban.isNotBlank()) { - epcQrCodeService.generateEpcQrCode(receiverName, iban, bic.takeUnless { it.isBlank() }, amount.takeUnless { it.isBlank() }, reference.takeUnless { it.isBlank() }, informationForUser.takeUnless { it.isBlank() }) + try { + epcQrCodeService.generateEpcQrCode(receiverName, iban, bic.takeUnless { it.isBlank() }, amount.takeUnless { it.isBlank() }, reference.takeUnless { it.isBlank() }, informationForUser.takeUnless { it.isBlank() }) + } catch (e: Throwable) { + Log.error(e) { "Could not generate EPC QR Code" } + epcQrCodeGeneratingError = e.message + null + } } else { null } @@ -74,7 +85,9 @@ fun CreateEpcQrCodeScreen(onClosed: () -> Unit) { FullscreenViewBase("EPC QR Code erstellen", "Schließen", onClosed = onClosed) { Column(Modifier.fillMaxWidth().verticalScroll(rememberScrollState())) { - if (epcQrCodeBytes == null) { + if (epcQrCodeGeneratingError != null) { + Text("QR Code konnte nicht erstellt werden:${NewLine}$epcQrCodeGeneratingError", color = MaterialTheme.colors.error, modifier = Modifier.padding(vertical = 8.dp)) + } else if (epcQrCodeBytes == null) { Text("Mit EPC QR Codes, welche als GiroCode, scan2code, ... vermarktet werden, können Überweisungsdaten ganz einfach von Banking Apps eingelesen werden.") Text("Hier können Sie Ihren eigenen erstellen, so dass jemand Ihre Überweisungsdaten einlesen und Ihnen ganz schnell Geld überweisen kann.") } else {