From b7e693fa22b38cab56d2aa4a145fab4f4a2b0586 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 5 Sep 2024 03:53:48 +0200 Subject: [PATCH] Added option to set if amounts should be displayed colored --- .../codinux/banking/ui/composables/NavigationMenuItem.kt | 4 +++- .../codinux/banking/ui/composables/settings/UiSettings.kt | 4 ++++ .../transactions/GroupedTransactionsListItems.kt | 6 ++++-- .../ui/composables/transactions/TransactionListItem.kt | 4 +++- .../banking/ui/composables/transactions/TransactionsList.kt | 4 +++- .../kotlin/net/codinux/banking/ui/service/FormatUtil.kt | 3 ++- .../kotlin/net/codinux/banking/ui/settings/UiSettings.kt | 2 ++ 7 files changed, 21 insertions(+), 6 deletions(-) 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 f440ff7..ff5f28b 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 @@ -45,6 +45,8 @@ fun NavigationMenuItem( ) { val transactionsFilter by DI.uiState.transactionsFilter.collectAsState() + val showColoredAmounts by DI.uiSettings.showColoredAmounts.collectAsState() + Row( verticalAlignment = Alignment.CenterVertically, modifier = modifier @@ -80,7 +82,7 @@ fun NavigationMenuItem( if (balance != null) { Text( formatUtil.formatAmount(balance, calculator.getTransactionsCurrency(emptyList())), - color = formatUtil.getColorForAmount(balance) + color = if (showColoredAmounts) formatUtil.getColorForAmount(balance) else textColor ) } } 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 07b7f20..1c7188f 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 @@ -19,6 +19,8 @@ fun UiSettings(modifier: Modifier, textColor: Color = Color.Unspecified) { val showBankIcons by uiSettings.showBankIcons.collectAsState() + val showColoredAmounts by uiSettings.showColoredAmounts.collectAsState() + Column(modifier) { BooleanOption("Umsätze gruppieren", groupTransactions, textColor = textColor) { uiSettings.groupTransactions.value = it } @@ -26,6 +28,8 @@ fun UiSettings(modifier: Modifier, textColor: Color = Color.Unspecified) { BooleanOption("Zebra Stripes", zebraStripes, textColor = textColor) { uiSettings.zebraStripes.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 } } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/GroupedTransactionsListItems.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/GroupedTransactionsListItems.kt index aa62330..fe3648b 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/GroupedTransactionsListItems.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/GroupedTransactionsListItems.kt @@ -34,6 +34,8 @@ fun GroupedTransactionsListItems( derivedStateOf { transactionsToDisplay.groupBy { LocalDate(it.valueDate.year, it.valueDate.monthNumber, 1) } } } + val showColoredAmounts by DI.uiSettings.showColoredAmounts.collectAsState() + LazyColumn(modifier) { items(groupedByMonth.keys.sortedDescending()) { month -> @@ -65,7 +67,7 @@ fun GroupedTransactionsListItems( Text( text = formatUtil.formatAmount(calculator.sumIncome(monthTransactions), calculator.getTransactionsCurrency(monthTransactions)), - color = formatUtil.getColorForAmount(Amount.Zero) + color = formatUtil.getColorForAmount(Amount.Zero, showColoredAmounts) ) } @@ -76,7 +78,7 @@ fun GroupedTransactionsListItems( Text( text = formatUtil.formatAmount(calculator.sumExpenses(monthTransactions), calculator.getTransactionsCurrency(monthTransactions)), - color = formatUtil.getColorForAmount(Amount("-1")) + color = formatUtil.getColorForAmount(Amount("-1"), showColoredAmounts) ) } } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionListItem.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionListItem.kt index c4a9df7..026aa41 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionListItem.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionListItem.kt @@ -28,6 +28,8 @@ fun TransactionListItem(userAccount: UserAccount?, transaction: AccountTransacti val showBankIcons by uiSettings.showBankIcons.collectAsState() + val showColoredAmounts by uiSettings.showColoredAmounts.collectAsState() + val backgroundColor = if (zebraStripes && itemIndex % 2 == 1) Colors.Zinc100_50 else Color.White Row( @@ -64,7 +66,7 @@ fun TransactionListItem(userAccount: UserAccount?, transaction: AccountTransacti Column(Modifier.width(90.dp), horizontalAlignment = Alignment.End, verticalArrangement = Arrangement.Center) { Text( text = formatUtil.formatAmount(transaction.amount, transaction.currency), - color = formatUtil.getColorForAmount(transaction.amount) + color = formatUtil.getColorForAmount(transaction.amount, showColoredAmounts) ) Spacer(Modifier.height(6.dp)) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionsList.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionsList.kt index d0de310..eedbb73 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionsList.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionsList.kt @@ -39,6 +39,8 @@ fun TransactionsList(uiState: UiState, uiSettings: UiSettings) { val groupTransactions by uiSettings.groupTransactions.collectAsState() + val showColoredAmounts by DI.uiSettings.showColoredAmounts.collectAsState() + val transactionsListModifier = Modifier.fillMaxSize().padding(bottom = 12.dp) // padding bottom = add the space the FAB sticks into the content area (= 26 - the 16 we add at the bottom of the expenses line) @@ -48,7 +50,7 @@ fun TransactionsList(uiState: UiState, uiSettings: UiSettings) { Spacer(Modifier.weight(1f)) val balance = calculator.calculateBalanceOfDisplayedTransactions(transactionsToDisplay, userAccounts, transactionsFilter) - Text(formatUtil.formatAmount(balance, "EUR"), color = formatUtil.getColorForAmount(balance)) + Text(formatUtil.formatAmount(balance, "EUR"), color = formatUtil.getColorForAmount(balance, showColoredAmounts)) } if (groupTransactions) { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt index 9393b5f..a35af95 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt @@ -55,7 +55,8 @@ class FormatUtil { else -> currency } - fun getColorForAmount(amount: Amount): Color = when { + fun getColorForAmount(amount: Amount, showColoredAmounts: Boolean = true): Color = when { + showColoredAmounts == false -> Color.Unspecified amount.amount.startsWith("-") -> Colors.Red600 else -> Colors.Green600 } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/settings/UiSettings.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/settings/UiSettings.kt index 9fbd2a9..b70efe6 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/settings/UiSettings.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/settings/UiSettings.kt @@ -11,4 +11,6 @@ class UiSettings : ViewModel() { val showBankIcons = MutableStateFlow(true) + val showColoredAmounts = MutableStateFlow(true) + } \ No newline at end of file