Integrated accountFilter into AccountTransactionsFilter
This commit is contained in:
parent
d0069a0563
commit
c1f4c8674c
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<List<BankAccountFilter>>(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
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ import net.codinux.banking.ui.model.BankAccountFilter
|
|||
|
||||
class AccountTransactionsFilterService {
|
||||
|
||||
fun filterAccounts(transactions: List<AccountTransactionViewModel>, accountsFilter: List<BankAccountFilter>, transactionsFilter: AccountTransactionsFilter): List<AccountTransactionViewModel> {
|
||||
val appliedAccountFilter = if (accountsFilter.isEmpty()) {
|
||||
fun filterAccounts(transactions: List<AccountTransactionViewModel>, transactionsFilter: AccountTransactionsFilter): List<AccountTransactionViewModel> {
|
||||
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<BankAccountFilter>): 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<BankAccountFilter>): 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
|
||||
}
|
||||
|
||||
}
|
|
@ -23,8 +23,6 @@ class UiState : ViewModel() {
|
|||
val drawerState = MutableStateFlow(DrawerState(DrawerValue.Closed))
|
||||
|
||||
|
||||
val accountFilter = MutableStateFlow<List<BankAccountFilter>>(emptyList())
|
||||
|
||||
val transactionsFilter = MutableStateFlow(AccountTransactionsFilter())
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue