Implemented searching for multiple terms by separating search terms with ','
This commit is contained in:
parent
5253219565
commit
ded5595dae
|
@ -7,6 +7,9 @@ import net.codinux.banking.ui.model.AccountTransactionViewModel
|
||||||
import net.codinux.banking.ui.model.AccountTransactionsFilter
|
import net.codinux.banking.ui.model.AccountTransactionsFilter
|
||||||
import net.codinux.banking.ui.model.BankAccountFilter
|
import net.codinux.banking.ui.model.BankAccountFilter
|
||||||
|
|
||||||
|
|
||||||
|
private const val SearchTermOrSeparatorSymbol = ','
|
||||||
|
|
||||||
class AccountTransactionsFilterService {
|
class AccountTransactionsFilterService {
|
||||||
|
|
||||||
fun filterAccounts(transactions: List<AccountTransactionViewModel>, filter: AccountTransactionsFilter): List<AccountTransactionViewModel> {
|
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) }
|
appliedAccountFilter = appliedAccountFilter.filter { it.valueDate.year == year && (month == null || it.valueDate.monthNumber == month) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val searchTerm = filter.searchTerm
|
val searchTerms = filter.searchTerm.split(SearchTermOrSeparatorSymbol).filter { it.isNotBlank() }
|
||||||
return if (searchTerm.isBlank()) {
|
return if (searchTerms.isEmpty()) {
|
||||||
appliedAccountFilter
|
appliedAccountFilter
|
||||||
} else {
|
} else {
|
||||||
appliedAccountFilter.filter { matchesSearchTerm(it, searchTerm) }
|
appliedAccountFilter.filter { transaction ->
|
||||||
|
searchTerms.any { matchesSearchTerm(transaction, it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue