From db8d4a7dcdea24a73fa9e3d786a53dbf03772b41 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 18 Sep 2024 02:24:04 +0200 Subject: [PATCH] Started BankAccountSettingsScreen, but it's not possible to save changes yet --- .../banking/ui/composables/StateHandler.kt | 9 ++- .../ui/composables/settings/UiSettings.kt | 8 +- .../banking/ui/config/Internationalization.kt | 14 ++++ .../codinux/banking/ui/forms/FormListItem.kt | 17 +++- .../ui/screens/BankAccountSettingsScreen.kt | 78 +++++++++++++++++++ .../banking/ui/screens/BankSettingsScreen.kt | 5 +- .../net/codinux/banking/ui/state/UiState.kt | 3 + 7 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankAccountSettingsScreen.kt diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/StateHandler.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/StateHandler.kt index 74c2313..efd3255 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/StateHandler.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/StateHandler.kt @@ -6,9 +6,7 @@ import androidx.compose.runtime.* import kotlinx.coroutines.launch import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.dialogs.* -import net.codinux.banking.ui.screens.AccountTransactionDetailsScreen -import net.codinux.banking.ui.screens.BankSettingsScreen -import net.codinux.banking.ui.screens.ExportScreen +import net.codinux.banking.ui.screens.* import net.codinux.banking.ui.state.UiState private val formatUtil = DI.formatUtil @@ -19,6 +17,7 @@ fun StateHandler(uiState: UiState, snackbarHostState: SnackbarHostState) { val showTransferMoneyDialogData by uiState.showTransferMoneyDialogData.collectAsState() val showAccountTransactionDetailsScreenForId by uiState.showAccountTransactionDetailsScreenForId.collectAsState() val showBankSettingsScreenForBank by uiState.showBankSettingsScreenForBank.collectAsState() + val showBankAccountSettingsScreenForAccount by uiState.showBankAccountSettingsScreenForAccount.collectAsState() val showExportScreen by uiState.showExportScreen.collectAsState() val tanChallengeReceived by uiState.tanChallengeReceived.collectAsState() @@ -46,6 +45,10 @@ fun StateHandler(uiState: UiState, snackbarHostState: SnackbarHostState) { BankSettingsScreen(bank) { uiState.showBankSettingsScreenForBank.value = null } } + showBankAccountSettingsScreenForAccount?.let { account -> + BankAccountSettingsScreen(account) { uiState.showBankAccountSettingsScreenForAccount.value = null } + } + if (showExportScreen) { ExportScreen { uiState.showExportScreen.value = false } } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/settings/UiSettings.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/settings/UiSettings.kt index 61bead8..dcb87a5 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/settings/UiSettings.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/settings/UiSettings.kt @@ -31,13 +31,13 @@ fun UiSettings(modifier: Modifier, textColor: Color = Color.Unspecified) { Column(modifier) { - BooleanOption("Kontostand anzeigen", showBalance, textColor = textColor) { uiSettings.showBalance.value = it } + BooleanOption("Kontostand anzeigen", showBalance, textColor = textColor) { uiSettings.showBalance.value = it } - BooleanOption("Umsätze in alternierenden Farben anzeigen", showTransactionsInAlternatingColors, textColor = textColor) { uiSettings.showTransactionsInAlternatingColors.value = it } + BooleanOption("Umsätze in alternierenden Farben anzeigen", showTransactionsInAlternatingColors, textColor = textColor) { uiSettings.showTransactionsInAlternatingColors.value = it } - BooleanOption("Bank Icons anzeigen", showBankIcons, textColor = textColor) { uiSettings.showBankIcons.value = it } + BooleanOption("Bank Icons anzeigen", showBankIcons, textColor = textColor) { uiSettings.showBankIcons.value = it } - BooleanOption("Umsätze farbig anzeigen", showColoredAmounts, textColor = textColor) { uiSettings.showColoredAmounts.value = it } + BooleanOption("Umsätze farbig anzeigen", showColoredAmounts, textColor = textColor) { uiSettings.showColoredAmounts.value = it } Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { Text("Umsätze gruppieren", color = textColor) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt index 76cf02c..2b3c965 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt @@ -1,5 +1,6 @@ package net.codinux.banking.ui.config +import net.codinux.banking.client.model.BankAccountType import net.codinux.banking.client.model.tan.ActionRequiringTan import net.codinux.banking.ui.model.TransactionsGrouping @@ -30,4 +31,17 @@ object Internationalization { TransactionsGrouping.None -> "Nicht gruppieren" } + fun translate(accountType: BankAccountType): String = when (accountType) { + BankAccountType.CheckingAccount -> "Girokonto" + BankAccountType.SavingsAccount -> "Sparkonto" + BankAccountType.FixedTermDepositAccount -> "Festgeldkonto" + BankAccountType.SecuritiesAccount -> "Wertpapierdepot" + BankAccountType.LoanAccount -> "Darlehenskonto" + BankAccountType.CreditCardAccount -> "Kreditkartenkonto" + BankAccountType.FundDeposit -> "Fondsdepot" + BankAccountType.BuildingLoanContract -> "Bausparvertrag" + BankAccountType.InsuranceContract -> "Versicherungsvertrag" + BankAccountType.Other -> "Sonstige" + } + } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/FormListItem.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/FormListItem.kt index 304315b..cd87fdd 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/FormListItem.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/FormListItem.kt @@ -1,5 +1,6 @@ package net.codinux.banking.ui.forms +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.material.Icon import androidx.compose.material.Text @@ -9,18 +10,26 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import net.codinux.banking.ui.config.Colors @Composable -fun FormListItem(label: String, isSelectable: Boolean = false, isSelected: Boolean = false, selectedIconContentDescription: String? = null) { +fun FormListItem( + label: String, + isSelectable: Boolean = false, + isSelected: Boolean = false, + selectedIconContentDescription: String? = null, + itemHeight: Dp = 32.dp, + onClick: (() -> Unit)? = null +) { - Row(Modifier.fillMaxWidth().height(32.dp).padding(4.dp), verticalAlignment = Alignment.CenterVertically) { + Row(Modifier.fillMaxWidth().height(itemHeight).clickable { onClick?.invoke() }.padding(4.dp), verticalAlignment = Alignment.CenterVertically) { if (isSelectable) { - Column(Modifier.size(24.dp).padding(end = 8.dp)) { + Column(Modifier.padding(end = 8.dp).size(24.dp)) { if (isSelected) { - Icon(Icons.Outlined.Check, selectedIconContentDescription ?: "Item ist ausgewählt") + Icon(Icons.Outlined.Check, selectedIconContentDescription ?: "Item ist ausgewählt", tint = Colors.FormListItemTextColor) } } } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankAccountSettingsScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankAccountSettingsScreen.kt new file mode 100644 index 0000000..263dd8a --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankAccountSettingsScreen.kt @@ -0,0 +1,78 @@ +package net.codinux.banking.ui.screens + +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.text.selection.SelectionContainer +import androidx.compose.material.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import net.codinux.banking.dataaccess.entities.BankAccountEntity +import net.codinux.banking.ui.config.Internationalization +import net.codinux.banking.ui.extensions.verticalScroll +import net.codinux.banking.ui.forms.* + +@Composable +fun BankAccountSettingsScreen(account: BankAccountEntity, onClosed: () -> Unit) { + + var enteredAccountName by remember { mutableStateOf(account.displayName) } + + var selectedIncludeInAutomaticAccountsUpdate by remember { mutableStateOf(account.includeInAutomaticAccountsUpdate) } + + var selectedHideAccount by remember { mutableStateOf(account.hideAccount) } + + val hasDataChanged by remember(enteredAccountName) { + mutableStateOf( + enteredAccountName != account.displayName + || selectedIncludeInAutomaticAccountsUpdate != account.includeInAutomaticAccountsUpdate + || selectedHideAccount != account.hideAccount + ) + } + + + FullscreenViewBase(account.displayName, onClosed = onClosed) { + Column(Modifier.fillMaxSize().verticalScroll().padding(8.dp)) { + Column { + SectionHeader("Einstellungen", false) + + OutlinedTextField( + label = { Text("Name") }, + value = enteredAccountName, + onValueChange = { enteredAccountName = it }, + modifier = Modifier.fillMaxWidth().padding(top = 8.dp, bottom = 8.dp) + ) + +// BooleanOption("Bei Kontoaktualisierung einbeziehen", selectedIncludeInAutomaticAccountsUpdate) { selectedIncludeInAutomaticAccountsUpdate = it } +// +// BooleanOption("Konto ausblenden", selectedHideAccount) { selectedHideAccount = it } + } + + SelectionContainer { + Column { + SectionHeader("Kontodaten") // TODO: add a share icon to copy data + + LabelledValue("Kontoinhaber", account.accountHolderName) + + LabelledValue("Kontonummer", account.identifier) + + LabelledValue("Unterkontenmerkmal", account.subAccountNumber) + + LabelledValue("IBAN", account.iban ?: "") + + LabelledValue("Typ", Internationalization.translate(account.type)) + } + } + + Column { + SectionHeader("Unterstützt") + + Column(Modifier.padding(top = 8.dp)) { + FormListItem("Kontostand abrufen", true, account.supportsBalanceRetrieval, "Unterstützt das Abrufen des Kontostandes") + FormListItem("Kontoumsätze abrufen", true, account.supportsTransactionRetrieval, "Unterstützt das Abrufen der Kontoumsätze") + FormListItem("Überweisen", true, account.supportsMoneyTransfer, "Unterstützt Überweisungen") + FormListItem("Echtzeitüberweisung", true, account.supportsInstantTransfer, "Unterstützt Echtzeitüberweisungen") + } + } + } + } + +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt index 21d59d3..3627243 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt @@ -6,6 +6,7 @@ import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.extensions.verticalScroll import net.codinux.banking.ui.forms.* @@ -56,7 +57,9 @@ fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) { Column(Modifier.padding(top = 8.dp)) { bank.accounts.sortedBy { it.displayIndex }.forEach { account -> - FormListItem(account.displayName) + FormListItem(account.displayName, itemHeight = 42.dp) { + DI.uiState.showBankAccountSettingsScreenForAccount.value = account + } } } } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt index b000b53..7957156 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt @@ -9,6 +9,7 @@ import net.codinux.banking.client.model.tan.EnterTanResult import net.codinux.banking.client.model.tan.TanChallenge import net.codinux.banking.dataaccess.entities.HoldingEntity import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.dataaccess.entities.BankAccountEntity import net.codinux.banking.ui.model.* import net.codinux.banking.ui.model.error.ApplicationError import net.codinux.banking.ui.model.error.BankingClientError @@ -58,6 +59,8 @@ class UiState : ViewModel() { val showBankSettingsScreenForBank = MutableStateFlow(null) + val showBankAccountSettingsScreenForAccount = MutableStateFlow(null) + val showExportScreen = MutableStateFlow(false)