diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/BottomBar.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/BottomBar.kt index 630ae9d..311b8c9 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/BottomBar.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/BottomBar.kt @@ -41,8 +41,6 @@ private val IconWidth = 48.dp fun BottomBar() { val userAccounts by uiState.userAccounts.collectAsState() - val accountFilter by uiState.accountFilter.collectAsState() - val transactionsFilter by uiState.transactionsFilter.collectAsState() var showSearchbar by remember { mutableStateOf(false) } @@ -73,15 +71,14 @@ fun BottomBar() { Column(Modifier.fillMaxHeight().weight(if (showSearchbar) 0.1f else 1f), verticalArrangement = Arrangement.Center) { if (showSearchbar == false) { - val title = if (accountFilter.isEmpty()) { + val selectedAccount = transactionsFilter.selectedAccount + + val title = if (selectedAccount == null) { "Bankmeister" + } else if (selectedAccount.bankAccount != null) { + selectedAccount.bankAccount.productName ?: selectedAccount.bankAccount.identifier } else { - val filter = accountFilter.first() - if (filter.bankAccount != null) { - filter.bankAccount.productName ?: filter.bankAccount.identifier - } else { - filter.userAccount.bankName - } + selectedAccount.userAccount.bankName } Text(title, color = color, maxLines = 1, overflow = TextOverflow.Ellipsis) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/SideMenu.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/SideMenu.kt index d169880..fad16c4 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/SideMenu.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/SideMenu.kt @@ -80,11 +80,7 @@ fun SideMenu(appContent: @Composable () -> Unit) { } BanksList(iconSize = iconSize, textColor = textColor, itemModifier = itemModifier, itemHorizontalPadding = ItemHorizontalPadding) { userAccount, bankAccount -> - uiState.accountFilter.value = if (userAccount == null) { - emptyList() - } else { - listOf(BankAccountFilter(userAccount, bankAccount)) - } + uiState.transactionsFilter.value.selectedAccountChanged(userAccount, bankAccount) coroutineScope.launch { drawerState.close() 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 5a74927..96ed576 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 @@ -38,15 +38,15 @@ fun NavigationMenuItem( icon: (@Composable () -> Unit)? = null, onClick: (() -> Unit)? = null ) { - val accountFilter by DI.uiState.accountFilter.collectAsState() + val transactionsFilter by DI.uiState.transactionsFilter.collectAsState() Row( verticalAlignment = Alignment.CenterVertically, modifier = modifier .clickable { onClick?.invoke() } .let { - if (userAccount != null && filterService.isSelected(userAccount, accountFilter) - || bankAccount != null && filterService.isSelected(bankAccount, accountFilter)) { + if (userAccount != null && filterService.isSelected(userAccount, transactionsFilter) + || bankAccount != null && filterService.isSelected(bankAccount, transactionsFilter)) { it.background(Colors.Accent, shape = RoundedCornerShape(4.dp)) } else { it diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/TransactionsList.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/TransactionsList.kt index e0b19b3..2467f6d 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/TransactionsList.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/TransactionsList.kt @@ -34,14 +34,12 @@ fun TransactionsList(uiState: UiState) { derivedStateOf { userAccounts.associateBy { it.id } } } - val accountFilter by uiState.accountFilter.collectAsState() - val transactionsFilter by uiState.transactionsFilter.collectAsState() val transactions by uiState.transactions.collectAsState() - val transactionsToDisplay by remember(accountFilter, transactionsFilter, transactions) { - derivedStateOf { filterService.filterAccounts(transactions, accountFilter, transactionsFilter) } + val transactionsToDisplay by remember(transactionsFilter, transactions) { + derivedStateOf { filterService.filterAccounts(transactions, transactionsFilter) } } val groupedByMonth by remember(transactionsToDisplay) { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionsFilter.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionsFilter.kt index 1c33bd9..b1145bf 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionsFilter.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionsFilter.kt @@ -1,8 +1,29 @@ package net.codinux.banking.ui.model import androidx.compose.runtime.* +import net.codinux.banking.dataaccess.entities.BankAccountEntity +import net.codinux.banking.dataaccess.entities.UserAccountEntity class AccountTransactionsFilter { + + var selectedAccounts = mutableStateOf>(emptyList()) + private set + + val showAllAccounts: Boolean + get() = selectedAccounts.value.isEmpty() + + val selectedAccount: BankAccountFilter? + get() = selectedAccounts.value.firstOrNull() + + fun selectedAccountChanged(userAccount: UserAccountEntity?, bankAccount: BankAccountEntity?) { + selectedAccounts.value = if (userAccount == null) { + emptyList() + } else { + listOf(BankAccountFilter(userAccount, bankAccount)) + } + } + + var searchTerm by mutableStateOf("") private set diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt index e09ddce..5ec14df 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt @@ -8,11 +8,11 @@ import net.codinux.banking.ui.model.BankAccountFilter class AccountTransactionsFilterService { - fun filterAccounts(transactions: List, accountsFilter: List, transactionsFilter: AccountTransactionsFilter): List { - val appliedAccountFilter = if (accountsFilter.isEmpty()) { + fun filterAccounts(transactions: List, transactionsFilter: AccountTransactionsFilter): List { + val appliedAccountFilter = if (transactionsFilter.showAllAccounts) { transactions } else { - transactions.filter { matchesFilter(it, accountsFilter) } + transactions.filter { matchesFilter(it, transactionsFilter.selectedAccounts.value) } } val searchTerm = transactionsFilter.searchTerm @@ -37,24 +37,24 @@ class AccountTransactionsFilterService { || (transaction.otherPartyName != null && transaction.otherPartyName.contains(searchTerm, true)) - fun isSelected(userAccount: UserAccountEntity, accountFilter: List): Boolean { - if (accountFilter.isEmpty()) { + fun isSelected(userAccount: UserAccountEntity, transactionsFilter: AccountTransactionsFilter): Boolean { + if (transactionsFilter.showAllAccounts) { return false } - val filter = accountFilter.first() + val filter = transactionsFilter.selectedAccount - return filter.userAccount == userAccount && filter.bankAccount == null + return filter?.userAccount == userAccount && filter.bankAccount == null } - fun isSelected(bankAccount: BankAccountEntity, accountFilter: List): Boolean { - if (accountFilter.isEmpty()) { + fun isSelected(bankAccount: BankAccountEntity, transactionsFilter: AccountTransactionsFilter): Boolean { + if (transactionsFilter.showAllAccounts) { return false } - val filter = accountFilter.first() + val filter = transactionsFilter.selectedAccount - return filter.bankAccount == bankAccount + return filter?.bankAccount == bankAccount } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt index 1cf54b9..432f3e9 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt @@ -23,8 +23,6 @@ class UiState : ViewModel() { val drawerState = MutableStateFlow(DrawerState(DrawerValue.Closed)) - val accountFilter = MutableStateFlow>(emptyList()) - val transactionsFilter = MutableStateFlow(AccountTransactionsFilter())