Implemented filtering holdings
This commit is contained in:
parent
5029a2c3cb
commit
5253219565
|
@ -41,8 +41,7 @@ fun TransactionsList(uiState: UiState, uiSettings: UiSettings, isMobile: Boolean
|
|||
val holdings by uiState.holdings.collectAsState()
|
||||
|
||||
val holdingsToDisplay by remember(transactionsFilter, holdings) {
|
||||
// derivedStateOf { filterService.filterAccounts(transactions, transactionsFilter) } // TODO: filter which holdings to display
|
||||
derivedStateOf { holdings }
|
||||
derivedStateOf { filterService.filterHoldings(holdings, transactionsFilter) }
|
||||
}
|
||||
|
||||
val showBalance by uiSettings.showBalance.collectAsState()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.codinux.banking.ui.service
|
||||
|
||||
import net.codinux.banking.dataaccess.entities.BankAccountEntity
|
||||
import net.codinux.banking.dataaccess.entities.HoldingEntity
|
||||
import net.codinux.banking.dataaccess.entities.UserEntity
|
||||
import net.codinux.banking.ui.model.AccountTransactionViewModel
|
||||
import net.codinux.banking.ui.model.AccountTransactionsFilter
|
||||
|
@ -43,6 +44,40 @@ class AccountTransactionsFilterService {
|
|||
|| (transaction.otherPartyName != null && transaction.otherPartyName.contains(searchTerm, true))
|
||||
|
||||
|
||||
fun filterHoldings(holdings: List<HoldingEntity>, filter: AccountTransactionsFilter): List<HoldingEntity> {
|
||||
if (filter.year != null) { // TODO: check if it's current year (and month)
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
var appliedHoldingFilter = if (filter.showAllAccounts) {
|
||||
holdings
|
||||
} else {
|
||||
holdings.filter { matchesFilter(it, filter.selectedAccounts.value) }
|
||||
}
|
||||
|
||||
val searchTerm = filter.searchTerm
|
||||
return if (searchTerm.isBlank()) {
|
||||
appliedHoldingFilter
|
||||
} else {
|
||||
appliedHoldingFilter.filter { matchesSearchTerm(it, searchTerm) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun matchesFilter(holding: HoldingEntity, filter: List<BankAccountFilter>): Boolean =
|
||||
filter.any { (user, bankAccount) ->
|
||||
if (bankAccount != null) {
|
||||
holding.bankAccountId == bankAccount.id
|
||||
} else {
|
||||
holding.userId == user.id
|
||||
}
|
||||
}
|
||||
|
||||
private fun matchesSearchTerm(holding: HoldingEntity, searchTerm: String): Boolean =
|
||||
holding.name.contains(searchTerm, true)
|
||||
|| holding.isin?.contains(searchTerm, true) == true
|
||||
|| holding.wkn?.contains(searchTerm, true) == true
|
||||
|
||||
|
||||
fun isSelected(user: UserEntity, transactionsFilter: AccountTransactionsFilter): Boolean {
|
||||
if (transactionsFilter.showAllAccounts) {
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue