Added option to set if amounts should be displayed colored

This commit is contained in:
dankito 2024-09-05 03:53:48 +02:00
parent 66bb794afd
commit b7e693fa22
7 changed files with 21 additions and 6 deletions

View File

@ -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
)
}
}

View File

@ -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 }
}
}

View File

@ -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)
)
}
}

View File

@ -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))

View File

@ -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) {

View File

@ -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
}

View File

@ -11,4 +11,6 @@ class UiSettings : ViewModel() {
val showBankIcons = MutableStateFlow(true)
val showColoredAmounts = MutableStateFlow(true)
}