Integrated accountFilter into AccountTransactionsFilter
This commit is contained in:
parent
d0069a0563
commit
c1f4c8674c
|
@ -41,8 +41,6 @@ private val IconWidth = 48.dp
|
||||||
fun BottomBar() {
|
fun BottomBar() {
|
||||||
val userAccounts by uiState.userAccounts.collectAsState()
|
val userAccounts by uiState.userAccounts.collectAsState()
|
||||||
|
|
||||||
val accountFilter by uiState.accountFilter.collectAsState()
|
|
||||||
|
|
||||||
val transactionsFilter by uiState.transactionsFilter.collectAsState()
|
val transactionsFilter by uiState.transactionsFilter.collectAsState()
|
||||||
|
|
||||||
var showSearchbar by remember { mutableStateOf(false) }
|
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) {
|
Column(Modifier.fillMaxHeight().weight(if (showSearchbar) 0.1f else 1f), verticalArrangement = Arrangement.Center) {
|
||||||
if (showSearchbar == false) {
|
if (showSearchbar == false) {
|
||||||
val title = if (accountFilter.isEmpty()) {
|
val selectedAccount = transactionsFilter.selectedAccount
|
||||||
|
|
||||||
|
val title = if (selectedAccount == null) {
|
||||||
"Bankmeister"
|
"Bankmeister"
|
||||||
|
} else if (selectedAccount.bankAccount != null) {
|
||||||
|
selectedAccount.bankAccount.productName ?: selectedAccount.bankAccount.identifier
|
||||||
} else {
|
} else {
|
||||||
val filter = accountFilter.first()
|
selectedAccount.userAccount.bankName
|
||||||
if (filter.bankAccount != null) {
|
|
||||||
filter.bankAccount.productName ?: filter.bankAccount.identifier
|
|
||||||
} else {
|
|
||||||
filter.userAccount.bankName
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(title, color = color, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
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 ->
|
BanksList(iconSize = iconSize, textColor = textColor, itemModifier = itemModifier, itemHorizontalPadding = ItemHorizontalPadding) { userAccount, bankAccount ->
|
||||||
uiState.accountFilter.value = if (userAccount == null) {
|
uiState.transactionsFilter.value.selectedAccountChanged(userAccount, bankAccount)
|
||||||
emptyList()
|
|
||||||
} else {
|
|
||||||
listOf(BankAccountFilter(userAccount, bankAccount))
|
|
||||||
}
|
|
||||||
|
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
drawerState.close()
|
drawerState.close()
|
||||||
|
|
|
@ -38,15 +38,15 @@ fun NavigationMenuItem(
|
||||||
icon: (@Composable () -> Unit)? = null,
|
icon: (@Composable () -> Unit)? = null,
|
||||||
onClick: (() -> Unit)? = null
|
onClick: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
val accountFilter by DI.uiState.accountFilter.collectAsState()
|
val transactionsFilter by DI.uiState.transactionsFilter.collectAsState()
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.clickable { onClick?.invoke() }
|
.clickable { onClick?.invoke() }
|
||||||
.let {
|
.let {
|
||||||
if (userAccount != null && filterService.isSelected(userAccount, accountFilter)
|
if (userAccount != null && filterService.isSelected(userAccount, transactionsFilter)
|
||||||
|| bankAccount != null && filterService.isSelected(bankAccount, accountFilter)) {
|
|| bankAccount != null && filterService.isSelected(bankAccount, transactionsFilter)) {
|
||||||
it.background(Colors.Accent, shape = RoundedCornerShape(4.dp))
|
it.background(Colors.Accent, shape = RoundedCornerShape(4.dp))
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
|
|
|
@ -34,14 +34,12 @@ fun TransactionsList(uiState: UiState) {
|
||||||
derivedStateOf { userAccounts.associateBy { it.id } }
|
derivedStateOf { userAccounts.associateBy { it.id } }
|
||||||
}
|
}
|
||||||
|
|
||||||
val accountFilter by uiState.accountFilter.collectAsState()
|
|
||||||
|
|
||||||
val transactionsFilter by uiState.transactionsFilter.collectAsState()
|
val transactionsFilter by uiState.transactionsFilter.collectAsState()
|
||||||
|
|
||||||
val transactions by uiState.transactions.collectAsState()
|
val transactions by uiState.transactions.collectAsState()
|
||||||
|
|
||||||
val transactionsToDisplay by remember(accountFilter, transactionsFilter, transactions) {
|
val transactionsToDisplay by remember(transactionsFilter, transactions) {
|
||||||
derivedStateOf { filterService.filterAccounts(transactions, accountFilter, transactionsFilter) }
|
derivedStateOf { filterService.filterAccounts(transactions, transactionsFilter) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val groupedByMonth by remember(transactionsToDisplay) {
|
val groupedByMonth by remember(transactionsToDisplay) {
|
||||||
|
|
|
@ -1,8 +1,29 @@
|
||||||
package net.codinux.banking.ui.model
|
package net.codinux.banking.ui.model
|
||||||
|
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
import net.codinux.banking.dataaccess.entities.BankAccountEntity
|
||||||
|
import net.codinux.banking.dataaccess.entities.UserAccountEntity
|
||||||
|
|
||||||
class AccountTransactionsFilter {
|
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("")
|
var searchTerm by mutableStateOf("")
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@ import net.codinux.banking.ui.model.BankAccountFilter
|
||||||
|
|
||||||
class AccountTransactionsFilterService {
|
class AccountTransactionsFilterService {
|
||||||
|
|
||||||
fun filterAccounts(transactions: List<AccountTransactionViewModel>, accountsFilter: List<BankAccountFilter>, transactionsFilter: AccountTransactionsFilter): List<AccountTransactionViewModel> {
|
fun filterAccounts(transactions: List<AccountTransactionViewModel>, transactionsFilter: AccountTransactionsFilter): List<AccountTransactionViewModel> {
|
||||||
val appliedAccountFilter = if (accountsFilter.isEmpty()) {
|
val appliedAccountFilter = if (transactionsFilter.showAllAccounts) {
|
||||||
transactions
|
transactions
|
||||||
} else {
|
} else {
|
||||||
transactions.filter { matchesFilter(it, accountsFilter) }
|
transactions.filter { matchesFilter(it, transactionsFilter.selectedAccounts.value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val searchTerm = transactionsFilter.searchTerm
|
val searchTerm = transactionsFilter.searchTerm
|
||||||
|
@ -37,24 +37,24 @@ class AccountTransactionsFilterService {
|
||||||
|| (transaction.otherPartyName != null && transaction.otherPartyName.contains(searchTerm, true))
|
|| (transaction.otherPartyName != null && transaction.otherPartyName.contains(searchTerm, true))
|
||||||
|
|
||||||
|
|
||||||
fun isSelected(userAccount: UserAccountEntity, accountFilter: List<BankAccountFilter>): Boolean {
|
fun isSelected(userAccount: UserAccountEntity, transactionsFilter: AccountTransactionsFilter): Boolean {
|
||||||
if (accountFilter.isEmpty()) {
|
if (transactionsFilter.showAllAccounts) {
|
||||||
return false
|
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 {
|
fun isSelected(bankAccount: BankAccountEntity, transactionsFilter: AccountTransactionsFilter): Boolean {
|
||||||
if (accountFilter.isEmpty()) {
|
if (transactionsFilter.showAllAccounts) {
|
||||||
return false
|
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 drawerState = MutableStateFlow(DrawerState(DrawerValue.Closed))
|
||||||
|
|
||||||
|
|
||||||
val accountFilter = MutableStateFlow<List<BankAccountFilter>>(emptyList())
|
|
||||||
|
|
||||||
val transactionsFilter = MutableStateFlow(AccountTransactionsFilter())
|
val transactionsFilter = MutableStateFlow(AccountTransactionsFilter())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue