From 1520d19625624316a252f9217472ed4a75588e47 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 3 Oct 2024 21:32:37 +0200 Subject: [PATCH] Implemented selecting account for which EPC QR code should get generated --- .../ui/screens/CreateEpcQrCodeScreen.kt | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) 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 fce88e7..e16b8c9 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 @@ -9,13 +9,18 @@ import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.ui.composables.BankIcon import net.codinux.banking.ui.composables.tan.ImageSizeControls import net.codinux.banking.ui.config.Colors 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.service.createImageBitmap private val epcQrCodeService = DI.epcQrCodeService @@ -23,6 +28,22 @@ private val epcQrCodeService = DI.epcQrCodeService @Composable fun CreateEpcQrCodeScreen(onClosed: () -> Unit) { + val banks = DI.uiState.banks.collectAsState().value + + val accountsWithIban: List = buildList { + add(null) + addAll(DI.uiState.accounts.collectAsState().value.filter { it.iban != null }) + } + + var selectedAccount by remember { mutableStateOf(null) } + + val bankOfSelectedAccount by remember(selectedAccount) { + derivedStateOf { banks.firstOrNull { it.id == selectedAccount?.bankId } } + } + + val amountFocus = remember { FocusRequester() } + + var receiverName by remember { mutableStateOf("") } var iban by remember { mutableStateOf("") } @@ -65,6 +86,33 @@ fun CreateEpcQrCodeScreen(onClosed: () -> Unit) { } + Select( + "Für Konto", + accountsWithIban, + selectedAccount, + { account -> + selectedAccount = account + + if (account != null) { + iban = account.iban ?: "" + bic = banks.firstOrNull { it.id == selectedAccount?.bankId }?.bic ?: "" + receiverName = account.accountHolderName + + amountFocus.requestFocus() + } + }, + { account -> account?.displayName ?: "" }, + leadingIcon = bankOfSelectedAccount?.let { { BankIcon(bankOfSelectedAccount) } }, + dropDownItemContent = { account -> + Row(verticalAlignment = Alignment.CenterVertically) { + BankIcon(banks.firstOrNull { it.id == account?.bankId }, Modifier.padding(end = 6.dp)) + + Text(account?.displayName ?: "") + } + }, + modifier = Modifier.fillMaxWidth().padding(top = 16.dp, bottom = 8.dp) + ) + OutlinedTextField( label = { Text("Empfänger*in") }, value = receiverName, @@ -93,7 +141,7 @@ fun CreateEpcQrCodeScreen(onClosed: () -> Unit) { label = { Text("Betrag (optional)") }, value = amount, onValueChange = { amount = it }, - modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp), + modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp).focusRequester(amountFocus), keyboardOptions = KeyboardOptions.ImeNext )