From 2813224eff39ddeac3838702cb0d491e93b436d3 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 18 Sep 2024 01:42:31 +0200 Subject: [PATCH] Started BankSettingsScreen, but it's not possible to save changes yet or to delete account --- .../ui/composables/NavigationMenuItem.kt | 19 +++- .../banking/ui/composables/StateHandler.kt | 6 + .../net/codinux/banking/ui/config/Colors.kt | 5 + .../codinux/banking/ui/forms/FormListItem.kt | 31 +++++ .../banking/ui/screens/BankSettingsScreen.kt | 107 ++++++++++++++++++ .../net/codinux/banking/ui/state/UiState.kt | 2 + 6 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/FormListItem.kt create mode 100644 composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/NavigationMenuItem.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/NavigationMenuItem.kt index 4ada740..bf3daaf 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/NavigationMenuItem.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/NavigationMenuItem.kt @@ -2,13 +2,13 @@ package net.codinux.banking.ui.composables import androidx.compose.foundation.background import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.ContentAlpha +import androidx.compose.material.Icon import androidx.compose.material.Text +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Settings import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -105,5 +105,16 @@ fun NavigationMenuItem( modifier = Modifier.padding(start = 4.dp) ) } + + if (bank != null) { + if (bankAccount == null) { + Column(Modifier.clickable { DI.uiState.showBankSettingsScreenForBank.value = bank }.padding(start = 8.dp).size(24.dp)) { + Icon(Icons.Outlined.Settings, "Zu Kontoeinstellungen wechseln", tint = textColor, modifier = Modifier.size(24.dp)) + } + } + } + if (bankAccount != null) { // show a place holder to match Settings icon's width + Spacer(Modifier.padding(start = 8.dp).size(24.dp)) + } } } \ No newline at end of file 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 51a5586..74c2313 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 @@ -7,6 +7,7 @@ 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.state.UiState @@ -17,6 +18,7 @@ fun StateHandler(uiState: UiState, snackbarHostState: SnackbarHostState) { val showAddAccountDialog by uiState.showAddAccountDialog.collectAsState() val showTransferMoneyDialogData by uiState.showTransferMoneyDialogData.collectAsState() val showAccountTransactionDetailsScreenForId by uiState.showAccountTransactionDetailsScreenForId.collectAsState() + val showBankSettingsScreenForBank by uiState.showBankSettingsScreenForBank.collectAsState() val showExportScreen by uiState.showExportScreen.collectAsState() val tanChallengeReceived by uiState.tanChallengeReceived.collectAsState() @@ -40,6 +42,10 @@ fun StateHandler(uiState: UiState, snackbarHostState: SnackbarHostState) { } } + showBankSettingsScreenForBank?.let { bank -> + BankSettingsScreen(bank) { uiState.showBankSettingsScreenForBank.value = null } + } + if (showExportScreen) { ExportScreen { uiState.showExportScreen.value = false } } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Colors.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Colors.kt index 36524ad..d6fa56b 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Colors.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Colors.kt @@ -38,6 +38,11 @@ object Colors { val FormValueTextColor = Color(0xFF999999) + val FormListItemTextColor = FormLabelTextColor + + + val DestructiveColor = Color(0xFFff3b30) + val Zinc100 = Color(244, 244, 245) val Zinc100_50 = Zinc100.copy(alpha = 0.5f) 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 new file mode 100644 index 0000000..304315b --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/FormListItem.kt @@ -0,0 +1,31 @@ +package net.codinux.banking.ui.forms + +import androidx.compose.foundation.layout.* +import androidx.compose.material.Icon +import androidx.compose.material.Text +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Check +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.sp +import net.codinux.banking.ui.config.Colors + +@Composable +fun FormListItem(label: String, isSelectable: Boolean = false, isSelected: Boolean = false, selectedIconContentDescription: String? = null) { + + Row(Modifier.fillMaxWidth().height(32.dp).padding(4.dp), verticalAlignment = Alignment.CenterVertically) { + if (isSelectable) { + Column(Modifier.size(24.dp).padding(end = 8.dp)) { + if (isSelected) { + Icon(Icons.Outlined.Check, selectedIconContentDescription ?: "Item ist ausgewählt") + } + } + } + + Text(label, color = Colors.FormListItemTextColor, fontSize = 16.sp, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.fillMaxHeight()) + } + +} \ 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 new file mode 100644 index 0000000..21d59d3 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt @@ -0,0 +1,107 @@ +package net.codinux.banking.ui.screens + +import androidx.compose.foundation.layout.* +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.BankAccessEntity +import net.codinux.banking.ui.extensions.verticalScroll +import net.codinux.banking.ui.forms.* + +@Composable +fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) { + + var enteredBankName by remember { mutableStateOf(bank.displayName) } + + var enteredLoginName by remember { mutableStateOf(bank.loginName) } + + var enteredPassword by remember { mutableStateOf(bank.password ?: "") } + + val hasDataChanged by remember(enteredBankName) { + mutableStateOf( + (enteredBankName != bank.bankName && (bank.userSetDisplayName == null || enteredBankName != bank.userSetDisplayName)) + || enteredLoginName != bank.loginName || enteredPassword != bank.password + ) + } + + + FullscreenViewBase(bank.displayName, onClosed = onClosed) { + Column(Modifier.fillMaxSize().verticalScroll().padding(8.dp)) { + Column { + OutlinedTextField( + label = { Text("Name") }, + value = enteredBankName, + onValueChange = { enteredBankName = it }, + modifier = Modifier.fillMaxWidth() + ) + + SectionHeader("Online-Banking Zugangsdaten") + + OutlinedTextField( + label = { Text("Login Name") }, + value = enteredLoginName, + onValueChange = { enteredLoginName = it }, + modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp) + ) + + PasswordTextField( + password = enteredPassword, + onChange = { enteredPassword = it } + ) + } + + Column { + SectionHeader("Konten") + + Column(Modifier.padding(top = 8.dp)) { + bank.accounts.sortedBy { it.displayIndex }.forEach { account -> + FormListItem(account.displayName) + } + } + } + + Column { + SectionHeader("Bankdaten") + + LabelledValue("Bankleitzahl", bank.domesticBankCode) + + LabelledValue("BIC", bank.bic ?: "") + + LabelledValue("Kontoinhaber", bank.customerName) + + LabelledValue("FinTS Server", bank.serverAddress) + } + + Column { + SectionHeader("TAN Verfahren") + + Column(Modifier.padding(top = 8.dp)) { + bank.tanMethods.sortedBy { it.identifier }.forEach { tanMethod -> + FormListItem(tanMethod.displayName, true, tanMethod == bank.selectedTanMethod, "TAN Verfahren ist ausgewähltes TAN Verfahren") + } + } + } + + if (bank.tanMedia.isNotEmpty()) { + Column { + SectionHeader("TAN Medien") + + Column(Modifier.padding(top = 8.dp)) { + bank.tanMedia.sortedBy { it.status }.forEach { tanMedium -> + FormListItem(tanMedium.displayName, true, tanMedium == bank.selectedTanMedium, "TAN Medium ist ausgewähltes TAN Medium") + } + } + } + } + +// Spacer(Modifier.weight(1f)) +// +// Column(Modifier.padding(top = 18.dp, bottom = 18.dp)) { +// TextButton(modifier = Modifier.fillMaxWidth().height(50.dp), onClick = { }, enabled = false) { +// Text("Konto löschen", color = Colors.DestructiveColor, textAlign = TextAlign.Center) +// } +// } + } + } +} \ No newline at end of file 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 90dbcb9..b000b53 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 @@ -56,6 +56,8 @@ class UiState : ViewModel() { val showAccountTransactionDetailsScreenForId = MutableStateFlow(null) + val showBankSettingsScreenForBank = MutableStateFlow(null) + val showExportScreen = MutableStateFlow(false)