Implemented searching for multiple terms by separating search terms with ','

This commit is contained in:
dankito 2024-09-12 20:09:54 +02:00
parent 5253219565
commit ded5595dae
1 changed files with 8 additions and 3 deletions

View File

@ -7,6 +7,9 @@ import net.codinux.banking.ui.model.AccountTransactionViewModel
import net.codinux.banking.ui.model.AccountTransactionsFilter
import net.codinux.banking.ui.model.BankAccountFilter
private const val SearchTermOrSeparatorSymbol = ','
class AccountTransactionsFilterService {
fun filterAccounts(transactions: List<AccountTransactionViewModel>, filter: AccountTransactionsFilter): List<AccountTransactionViewModel> {
@ -22,11 +25,13 @@ class AccountTransactionsFilterService {
appliedAccountFilter = appliedAccountFilter.filter { it.valueDate.year == year && (month == null || it.valueDate.monthNumber == month) }
}
val searchTerm = filter.searchTerm
return if (searchTerm.isBlank()) {
val searchTerms = filter.searchTerm.split(SearchTermOrSeparatorSymbol).filter { it.isNotBlank() }
return if (searchTerms.isEmpty()) {
appliedAccountFilter
} else {
appliedAccountFilter.filter { matchesSearchTerm(it, searchTerm) }
appliedAccountFilter.filter { transaction ->
searchTerms.any { matchesSearchTerm(transaction, it) }
}
}
}