From ded5595dae78a17f6c2223c244b161f60bcdbadb Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 12 Sep 2024 20:09:54 +0200 Subject: [PATCH] Implemented searching for multiple terms by separating search terms with ',' --- .../ui/service/AccountTransactionsFilterService.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt index a377438..2b9f00a 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt @@ -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, filter: AccountTransactionsFilter): List { @@ -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) } + } } }