Implemented searching banks by bic

This commit is contained in:
dankito 2024-09-09 20:33:34 +02:00
parent b1b84ce8f6
commit a257223543
3 changed files with 14 additions and 13 deletions

View File

@ -97,7 +97,7 @@ fun AddAccountDialog(
Column {
AutocompleteTextField(
label = "Bank (Suche mit Name, Bankleitzahl oder Ort)",
label = "Bank (Suche mit Name, Ort, BIC oder Bankleitzahl)",
value = enteredBankSearchQuery,
onEnteredTextChanged = { enteredBankSearchQuery = it },
onSelectedItemChanged = {

View File

@ -17,7 +17,7 @@ class BankFinder {
return bankList.take(maxItems ?: Int.MAX_VALUE)
}
suspend fun findBankByNameBankCodeOrCity(query: String?, maxItems: Int? = null): List<BankInfo> {
suspend fun findBankByNameBicBankCodeOrCity(query: String?, maxItems: Int? = null): List<BankInfo> {
if (query.isNullOrBlank()) {
return getBankList(maxItems)
}
@ -26,7 +26,8 @@ class BankFinder {
return findBankByBankCode(query, maxItems)
}
return findBankByNameBankCodeOrCityForNonEmptyQuery(query, maxItems)
// we already checked for BankCode above, so there's no need to do this again in method below
return findBankByNameBicOrCityForNonEmptyQuery(query, maxItems)
}
@ -77,18 +78,18 @@ class BankFinder {
}
}
suspend fun findBankByNameBankCodeOrCityForNonEmptyQuery(query: String, maxItems: Int?): List<BankInfo> {
private suspend fun findBankByNameBicOrCityForNonEmptyQuery(query: String, maxItems: Int?): List<BankInfo> {
val queryPartsLowerCase = query.lowercase().split(" ", "-")
return getBankList().asSequence().filter { bankInfo ->
checkIfAllQueryPartsMatchBankNameBankCodeOrCity(queryPartsLowerCase, bankInfo)
checkIfAllQueryPartsMatchBankNameBicOrCity(queryPartsLowerCase, bankInfo)
}
.max(maxItems)
}
private fun checkIfAllQueryPartsMatchBankNameBankCodeOrCity(queryPartsLowerCase: List<String>, bankInfo: BankInfo): Boolean {
private fun checkIfAllQueryPartsMatchBankNameBicOrCity(queryPartsLowerCase: List<String>, bankInfo: BankInfo): Boolean {
for (queryPartLowerCase in queryPartsLowerCase) {
if (checkIfQueryMatchesBankNameBankCodeOrCity(bankInfo, queryPartLowerCase) == false) {
if (checkIfQueryMatchesBankNameBicOrCity(bankInfo, queryPartLowerCase) == false) {
return false
}
}
@ -96,11 +97,11 @@ class BankFinder {
return true
}
private fun checkIfQueryMatchesBankNameBankCodeOrCity(bankInfo: BankInfo, queryLowerCase: String): Boolean {
return bankInfo.name.lowercase().contains(queryLowerCase)
|| bankInfo.bankCode.startsWith(queryLowerCase)
|| bankInfo.city.lowercase().startsWith(queryLowerCase)
|| bankInfo.branchesInOtherCities.any { it.lowercase().startsWith(queryLowerCase) }
private fun checkIfQueryMatchesBankNameBicOrCity(bankInfo: BankInfo, queryLowerCase: String): Boolean {
return bankInfo.name.contains(queryLowerCase, true)
|| bankInfo.bic.startsWith(queryLowerCase, true)
|| bankInfo.city.startsWith(queryLowerCase, true)
|| bankInfo.branchesInOtherCities.any { it.startsWith(queryLowerCase, true) }
}
fun Sequence<BankInfo>.max(maxItems: Int? = null): List<BankInfo> =

View File

@ -69,7 +69,7 @@ class BankingService(
suspend fun findBanks(query: String): List<BankInfo> =
bankFinder.findBankByNameBankCodeOrCity(query, 25)
bankFinder.findBankByNameBicBankCodeOrCity(query, 25)
suspend fun addAccount(bank: BankInfo, loginName: String, password: String, retrieveAllTransactions: Boolean = false): Boolean {
try {