Showing selected account

This commit is contained in:
dankito 2024-08-29 00:42:00 +02:00
parent 5832a877c0
commit f221bd2095
2 changed files with 52 additions and 5 deletions

View File

@ -1,19 +1,28 @@
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.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
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.unit.Dp
import androidx.compose.ui.unit.dp
import net.codinux.banking.client.model.UserAccount
import net.codinux.banking.dataaccess.entities.BankAccountEntity
import net.codinux.banking.dataaccess.entities.UserAccountEntity
import net.codinux.banking.ui.config.Colors
import net.codinux.banking.ui.config.DI
import org.jetbrains.compose.resources.DrawableResource
private val filterService = DI.bankAccountFilterService
@Composable
fun NavigationMenuItem(
modifier: Modifier = Modifier,
@ -21,13 +30,28 @@ fun NavigationMenuItem(
textColor: Color = Color.White,
iconSize: Dp = 24.dp,
iconTextSpacing: Dp = 24.dp,
userAccount: UserAccount? = null,
fallbackIcon: DrawableResource? = null,
horizontalPadding: Dp = 8.dp,
userAccount: UserAccountEntity? = null,
bankAccount: BankAccountEntity? = null,
iconResource: DrawableResource? = null,
icon: (@Composable () -> Unit)? = null,
onClick: (() -> Unit)? = null
) {
val accountFilter by DI.uiState.accountFilter.collectAsState()
Row(
modifier.clickable { onClick?.invoke() },
verticalAlignment = Alignment.CenterVertically
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.clickable { onClick?.invoke() }
.let {
if (userAccount != null && filterService.isSelected(userAccount, accountFilter)
|| bankAccount != null && filterService.isSelected(bankAccount, accountFilter)) {
it.background(Colors.Accent)
} else {
it
}
}
.padding(horizontal = horizontalPadding)
) {
BankIcon(userAccount, Modifier.padding(end = iconTextSpacing), Modifier.size(iconSize), fallbackIcon = fallbackIcon)

View File

@ -1,5 +1,7 @@
package net.codinux.banking.ui.service
import net.codinux.banking.dataaccess.entities.BankAccountEntity
import net.codinux.banking.dataaccess.entities.UserAccountEntity
import net.codinux.banking.ui.model.AccountTransactionViewModel
import net.codinux.banking.ui.model.BankAccountFilter
@ -21,4 +23,25 @@ class BankAccountFilterService {
}
}
fun isSelected(userAccount: UserAccountEntity, accountFilter: List<BankAccountFilter>): Boolean {
if (accountFilter.isEmpty()) {
return false
}
val filter = accountFilter.first()
return filter.userAccount == userAccount && filter.bankAccount == null
}
fun isSelected(bankAccount: BankAccountEntity, accountFilter: List<BankAccountFilter>): Boolean {
if (accountFilter.isEmpty()) {
return false
}
val filter = accountFilter.first()
return filter.bankAccount == bankAccount
}
}