Implemented also showing total amount in BanksList

This commit is contained in:
dankito 2024-10-04 09:32:14 +02:00
parent 12c9becd17
commit 466ab84c36
2 changed files with 9 additions and 1 deletions

View File

@ -94,6 +94,8 @@ fun NavigationMenuItem(
bankAccount.balance
} else if (bank != null) {
calculator.calculateBalanceOfBankAccess(bank)
} else if (text == "Alle Konten") {
calculator.calculateBalanceOfAllAccounts(DI.uiState.accounts.value)
} else {
null
}
@ -113,7 +115,7 @@ fun NavigationMenuItem(
}
}
}
if (bankAccount != null) { // show a place holder to match Settings icon's width
if (bankAccount != null || bank == null) { // show a place holder to match Settings icon's width
Spacer(Modifier.padding(start = 8.dp).size(24.dp))
}
}

View File

@ -10,9 +10,15 @@ class CalculatorService {
fun sumTransactions(transactions: Collection<AccountTransactionViewModel>): Amount =
transactions.map { it.amount }.sum()
fun calculateBalanceOfAllBank(banks: List<BankAccess>): Amount =
calculateBalanceOfAllAccounts(banks.flatMap { it.accounts })
fun calculateBalanceOfBankAccess(bank: BankAccess): Amount =
sumAmounts(bank.accounts.map { it.balance })
fun calculateBalanceOfAllAccounts(accounts: List<BankAccount>): Amount =
sumAmounts(accounts.map { it.balance })
fun sumAmounts(amounts: Collection<Amount>): Amount =
amounts.sum()