From bf41bde90ab950f6e46da4d908bf197b5991f92d Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 5 Jun 2020 13:33:08 +0200 Subject: [PATCH] Implemented displaying remittee's bank name --- .../banking/bankfinder/BankFinderBase.kt | 18 ++++++++++++++++++ .../banking/bankfinder/InMemoryBankFinder.kt | 5 +++++ .../banking/bankfinder/LuceneBankFinder.kt | 11 ++++++++++- .../ui/android/adapter/RemitteeListAdapter.kt | 2 ++ .../adapter/viewholder/RemitteeViewHolder.kt | 2 ++ .../src/main/res/layout/list_item_remittee.xml | 11 ++++++++++- .../src/main/res/values/dimens.xml | 4 ++-- .../cashtransfer/RemitteeListCellFragment.kt | 11 +++++++---- .../dialogs/cashtransfer/RemitteeViewModel.kt | 2 ++ .../dankito/banking/bankfinder/IBankFinder.kt | 2 ++ .../net/dankito/banking/search/Remittee.kt | 3 ++- .../banking/ui/presenter/BankingPresenter.kt | 8 +++++++- 12 files changed, 69 insertions(+), 10 deletions(-) diff --git a/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/BankFinderBase.kt b/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/BankFinderBase.kt index 1604d7b6..fdc9241a 100644 --- a/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/BankFinderBase.kt +++ b/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/BankFinderBase.kt @@ -15,6 +15,11 @@ abstract class BankFinderBase : IBankFinder { protected abstract fun findBankByNameOrCityForNonEmptyQuery(query: String): List + abstract fun searchBankByBic(bic: String): BankInfo? + + + protected val cachedBanksByBic = mutableMapOf() + override fun findBankByNameBankCodeOrCity(query: String?): List { if (query.isNullOrBlank()) { @@ -29,6 +34,19 @@ abstract class BankFinderBase : IBankFinder { } + override fun findBankByBic(bic: String): BankInfo? { + cachedBanksByBic[bic]?.let { + return it + } + + val bankForBic = searchBankByBic(bic) + + cachedBanksByBic[bic] = bankForBic + + return bankForBic + } + + protected open fun loadBankListFile(): List { try { val bankListString = readBankListFile() diff --git a/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/InMemoryBankFinder.kt b/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/InMemoryBankFinder.kt index 1e0077df..a1063f5e 100644 --- a/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/InMemoryBankFinder.kt +++ b/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/InMemoryBankFinder.kt @@ -43,6 +43,11 @@ open class InMemoryBankFinder() : BankFinderBase(), IBankFinder { } + override fun searchBankByBic(bic: String): BankInfo? { + return getBankList().firstOrNull { it.bic == bic } + } + + override fun preloadBankList() { findBankByBankCode("1") } diff --git a/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/LuceneBankFinder.kt b/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/LuceneBankFinder.kt index ce702c26..af75a17d 100644 --- a/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/LuceneBankFinder.kt +++ b/tools/BankFinder/src/main/kotlin/net/dankito/banking/bankfinder/LuceneBankFinder.kt @@ -104,6 +104,15 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder { return getBanksFromQuery(luceneQuery) } + override fun searchBankByBic(bic: String): BankInfo? { + (bankFinderWhileUpdatingIndex as? BankFinderBase)?.let { + return it.searchBankByBic(bic) + } + + return getBanksFromQuery(queries.exact(BankInfoBicFieldName, bic)).firstOrNull() + } + + override fun getBankList(): List { bankFinderWhileUpdatingIndex?.let { return it.getBankList() @@ -178,10 +187,10 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder { return writer.createDocumentForNonNullFields( fields.fullTextSearchField(BankInfoNameFieldName, bank.name, true), fields.keywordField(BankInfoBankCodeFieldName, bank.bankCode, true), + fields.keywordField(BankInfoBicFieldName, bank.bic, true), fields.fullTextSearchField(BankInfoCityIndexedFieldName, bank.city, true), fields.storedField(BankInfoCityStoredFieldName, bank.city), - fields.storedField(BankInfoBicFieldName, bank.bic), fields.storedField(BankInfoPostalCodeFieldName, bank.postalCode), fields.storedField(BankInfoChecksumMethodFieldName, bank.checksumMethod), fields.nullableStoredField(BankInfoPinTanServerAddressFieldName, bank.pinTanAddress), diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/RemitteeListAdapter.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/RemitteeListAdapter.kt index 6e3e0069..cd0b7658 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/RemitteeListAdapter.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/RemitteeListAdapter.kt @@ -18,6 +18,8 @@ open class RemitteeListAdapter(protected val itemClicked: ((Remittee) -> Unit)? override fun bindItemToView(viewHolder: RemitteeViewHolder, item: Remittee) { viewHolder.txtvwRemitteeName.text = item.name + viewHolder.txtvwRemitteeBankName.text = item.bankName + viewHolder.txtvwRemitteeBankCode.text = item.iban viewHolder.itemView.setOnClickListener { diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/RemitteeViewHolder.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/RemitteeViewHolder.kt index 0d30644e..bc05b78a 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/RemitteeViewHolder.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/RemitteeViewHolder.kt @@ -10,6 +10,8 @@ open class RemitteeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView val txtvwRemitteeName: TextView = itemView.txtvwRemitteeName + val txtvwRemitteeBankName: TextView = itemView.txtvwRemitteeBankName + val txtvwRemitteeBankCode: TextView = itemView.txtvwRemitteeBankCode } \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/layout/list_item_remittee.xml b/ui/BankingAndroidApp/src/main/res/layout/list_item_remittee.xml index bf790571..929f7272 100644 --- a/ui/BankingAndroidApp/src/main/res/layout/list_item_remittee.xml +++ b/ui/BankingAndroidApp/src/main/res/layout/list_item_remittee.xml @@ -16,11 +16,20 @@ android:textSize="@dimen/list_item_bank_info_bank_name_text_size" /> + + 8dp 13sp - 60dp - 6dp + 80dp + 4dp 6dp 40dp diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/RemitteeListCellFragment.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/RemitteeListCellFragment.kt index e43d362c..f75049b7 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/RemitteeListCellFragment.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/RemitteeListCellFragment.kt @@ -1,10 +1,7 @@ package net.dankito.banking.ui.javafx.dialogs.cashtransfer import net.dankito.banking.search.Remittee -import tornadofx.ListCellFragment -import tornadofx.bindTo -import tornadofx.label -import tornadofx.vbox +import tornadofx.* open class RemitteeListCellFragment : ListCellFragment() { @@ -15,6 +12,12 @@ open class RemitteeListCellFragment : ListCellFragment() { override val root = vbox { label(remittee.name) + label(remittee.bankName) { + vboxConstraints { + marginTopBottom(6.0) + } + } + label(remittee.iban) } diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/RemitteeViewModel.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/RemitteeViewModel.kt index 05920da8..c739c62e 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/RemitteeViewModel.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/RemitteeViewModel.kt @@ -9,6 +9,8 @@ open class RemitteeViewModel : ItemViewModel() { val name = bind { SimpleStringProperty(item?.name) } + val bankName = bind { SimpleStringProperty(item?.bankName) } + val iban = bind { SimpleStringProperty(item?.iban) } } \ No newline at end of file diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/bankfinder/IBankFinder.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/bankfinder/IBankFinder.kt index 036ccbad..a4851cfc 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/bankfinder/IBankFinder.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/bankfinder/IBankFinder.kt @@ -9,6 +9,8 @@ interface IBankFinder { fun findBankByNameBankCodeOrCity(query: String?): List + fun findBankByBic(bic: String): BankInfo? + fun preloadBankList() } \ No newline at end of file diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/search/Remittee.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/search/Remittee.kt index 7252ef94..0db330c5 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/search/Remittee.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/search/Remittee.kt @@ -4,7 +4,8 @@ package net.dankito.banking.search data class Remittee( val name: String, val iban: String?, - val bic: String? + val bic: String?, + var bankName: String? = null ) { diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt index 2d9e7e86..e2a5fedc 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -414,7 +414,13 @@ open class BankingPresenter( } open fun findRemitteesForName(name: String): List { - return remitteeSearcher.findRemittees(name) + return remitteeSearcher.findRemittees(name).map { remittee -> + remittee.bic?.let { bic -> + remittee.bankName = bankFinder.findBankByBic(bic)?.name + } + + remittee + } }