From 5ac65308bb6f852f2f379a7e2f4bc2b9264056f6 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 26 Sep 2024 04:52:46 +0200 Subject: [PATCH] Fixed that entering text for amount or reference didn't reduce the autocomplete suggestions --- .../banking/ui/dialogs/TransferMoneyDialog.kt | 4 ++-- .../codinux/banking/ui/service/RecipientFinder.kt | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt index af6854d..d05177a 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt @@ -210,7 +210,7 @@ fun TransferMoneyDialog( paymentReference = it.reference } }, - fetchSuggestions = { recipientFinder.findPaymentDataForIban(recipientAccountIdentifier) } + fetchSuggestions = { query -> recipientFinder.findAmountPaymentDataForIban(recipientAccountIdentifier, query) } ) { paymentDataSuggestion -> Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { Text(formatUtil.formatAmount(paymentDataSuggestion.amount, paymentDataSuggestion.currency), Modifier.widthIn(min = 60.dp), textAlign = TextAlign.End) @@ -230,7 +230,7 @@ fun TransferMoneyDialog( getItemTitle = { suggestion -> suggestion.reference }, onEnteredTextChanged = { paymentReference = it }, onSelectedItemChanged = { paymentReference = it?.reference ?: "" }, - fetchSuggestions = { recipientFinder.findPaymentDataForIban(recipientAccountIdentifier) } + fetchSuggestions = { query -> recipientFinder.findReferencePaymentDataForIban(recipientAccountIdentifier, query) } ) { paymentDataSuggestion -> Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { Text(formatUtil.formatAmount(paymentDataSuggestion.amount, paymentDataSuggestion.currency), Modifier.widthIn(min = 60.dp), textAlign = TextAlign.End) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/RecipientFinder.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/RecipientFinder.kt index 7b01b3a..b7d4763 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/RecipientFinder.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/RecipientFinder.kt @@ -30,6 +30,15 @@ class RecipientFinder(private val bankFinder: BankFinder) { } } + fun findAmountPaymentDataForIban(iban: String, query: String): Collection = + transactionsByIban[iban].orEmpty() + .filter { it.amount.toString().contains(query, true) } + + fun findReferencePaymentDataForIban(iban: String, query: String): Collection = + transactionsByIban[iban].orEmpty() + .filter { it.reference.contains(query, true) } + + suspend fun updateData(transactions: List) { availableRecipients = transactions.mapNotNull { // TODO: also regard userSetOtherPartyName? @@ -51,7 +60,4 @@ class RecipientFinder(private val bankFinder: BankFinder) { }.toSet().sortedByDescending { it.valueDate } } } - fun findPaymentDataForIban(iban: String): Collection = - transactionsByIban[iban] ?: emptySet() - } \ No newline at end of file