From f221bd2095df061df09f55609e270f1fd8159638 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 29 Aug 2024 00:42:00 +0200 Subject: [PATCH] Showing selected account --- .../ui/composables/NavigationMenuItem.kt | 34 ++++++++++++++++--- .../ui/service/BankAccountFilterService.kt | 23 +++++++++++++ 2 files changed, 52 insertions(+), 5 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 af743ea..055b6e5 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 @@ -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) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankAccountFilterService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankAccountFilterService.kt index 2141648..344d700 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankAccountFilterService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankAccountFilterService.kt @@ -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): Boolean { + if (accountFilter.isEmpty()) { + return false + } + + val filter = accountFilter.first() + + return filter.userAccount == userAccount && filter.bankAccount == null + } + + fun isSelected(bankAccount: BankAccountEntity, accountFilter: List): Boolean { + if (accountFilter.isEmpty()) { + return false + } + + val filter = accountFilter.first() + + return filter.bankAccount == bankAccount + } + } \ No newline at end of file