Showing balance of accounts in side menu
This commit is contained in:
parent
4911152846
commit
e41edd392a
|
@ -43,7 +43,7 @@ private val ItemHeight = 48.dp
|
|||
|
||||
private val ItemHorizontalPadding = 8.dp
|
||||
|
||||
private val itemModifier = Modifier.height(ItemHeight).widthIn(min = 300.dp)
|
||||
private val itemModifier = Modifier.height(ItemHeight).widthIn(min = 350.dp)
|
||||
|
||||
private val iconSize = 24.dp
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import androidx.compose.runtime.getValue
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.codinux.banking.dataaccess.entities.BankAccountEntity
|
||||
|
@ -24,6 +25,10 @@ import org.jetbrains.compose.resources.DrawableResource
|
|||
|
||||
private val filterService = DI.accountTransactionsFilterService
|
||||
|
||||
private val calculator = DI.calculator
|
||||
|
||||
private val formatUtil = DI.formatUtil
|
||||
|
||||
@Composable
|
||||
fun NavigationMenuItem(
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -62,6 +67,21 @@ fun NavigationMenuItem(
|
|||
BankIcon(userAccount, Modifier.padding(end = iconTextSpacing), Modifier.size(iconSize), iconResource = iconResource)
|
||||
}
|
||||
|
||||
Text(text, color = textColor)
|
||||
Text(text, color = textColor, modifier = Modifier.weight(1f), maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
|
||||
val balance = if (bankAccount != null) {
|
||||
bankAccount.balance
|
||||
} else if (userAccount != null) {
|
||||
calculator.calculateBalanceOfUserAccount(userAccount)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
if (balance != null) {
|
||||
Text(
|
||||
formatUtil.formatAmount(balance, calculator.getTransactionsCurrency(emptyList())),
|
||||
color = formatUtil.getColorForAmount(balance)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,13 +19,12 @@ import net.codinux.banking.client.model.Amount
|
|||
import net.codinux.banking.ui.config.Colors
|
||||
import net.codinux.banking.ui.config.DI
|
||||
import net.codinux.banking.ui.forms.RoundedCornersCard
|
||||
import net.codinux.banking.ui.service.CalculatorService
|
||||
import net.codinux.banking.ui.state.UiState
|
||||
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||
|
||||
private val filterService = DI.accountTransactionsFilterService
|
||||
|
||||
private val calculator = CalculatorService()
|
||||
private val calculator = DI.calculator
|
||||
|
||||
private val formatUtil = DI.formatUtil
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ object DI {
|
|||
|
||||
val bankIconService = BankIconService()
|
||||
|
||||
val calculator = CalculatorService()
|
||||
|
||||
val accountTransactionsFilterService = AccountTransactionsFilterService()
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.codinux.banking.ui.service
|
||||
|
||||
import net.codinux.banking.client.model.Amount
|
||||
import net.codinux.banking.client.model.UserAccount
|
||||
import net.codinux.banking.dataaccess.entities.UserAccountEntity
|
||||
import net.codinux.banking.ui.extensions.toBigDecimal
|
||||
import net.codinux.banking.ui.model.AccountTransactionViewModel
|
||||
|
@ -12,6 +13,9 @@ class CalculatorService {
|
|||
// TODO: find a better solution
|
||||
Amount(transactions.sumOf { it.amount.toBigDecimal() }.toString())
|
||||
|
||||
fun calculateBalanceOfUserAccount(userAccount: UserAccount): Amount =
|
||||
sumAmounts(userAccount.accounts.map { it.balance })
|
||||
|
||||
fun sumAmounts(amounts: Collection<Amount>): Amount =
|
||||
// TODO: find a better solution
|
||||
Amount(amounts.sumOf { it.toBigDecimal() }.toString())
|
||||
|
@ -35,7 +39,7 @@ class CalculatorService {
|
|||
if (selectedAccount.bankAccount != null) {
|
||||
selectedAccount.bankAccount.balance
|
||||
} else {
|
||||
sumAmounts(selectedAccount.userAccount.accounts.map { it.balance })
|
||||
calculateBalanceOfUserAccount(selectedAccount.userAccount)
|
||||
}
|
||||
} else {
|
||||
sumTransactions(transactions)
|
||||
|
|
Loading…
Reference in New Issue