From 57d7dac61378029ab891ebbc23a202e5d3f47510 Mon Sep 17 00:00:00 2001 From: dankl Date: Tue, 31 Dec 2019 01:27:02 +0100 Subject: [PATCH] Moved filtering banks to MainWindowPresenter; added preloading banks --- .../android/ui/MainWindowPresenter.kt | 18 +++++++++++++++--- .../android/ui/adapter/BankListAdapter.kt | 6 +++--- .../ui/adapter/filter/BankInfoFilter.kt | 16 +++++----------- .../android/ui/dialogs/AddAccountDialog.kt | 5 ++++- .../android/ui/dialogs/BankTransferDialog.kt | 2 +- .../src/main/res/layout/dialog_add_account.xml | 5 +---- .../net/dankito/fints/banks/BankFinder.kt | 8 ++++++++ 7 files changed, 37 insertions(+), 23 deletions(-) diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt index c35237ce..3273faa6 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt @@ -154,16 +154,28 @@ open class MainWindowPresenter(protected val base64Service: IBase64Service, } - open fun searchForBankAsync(enteredBankCode: String, callback: (List) -> Unit) { + open fun preloadBanksAsync() { + searchBanksByBankCodeAsync("1") { } + } + + open fun searchBanksByBankCodeAsync(enteredBankCode: String, callback: (List) -> Unit) { threadPool.runAsync { - callback(searchForBank(enteredBankCode)) + callback(searchBanksByBankCode(enteredBankCode)) } } - open fun searchForBank(enteredBankCode: String): List { + open fun searchBanksByBankCode(enteredBankCode: String): List { return bankFinder.findBankByBankCode(enteredBankCode) } + open fun searchBanksByNameBankCodeOrCity(query: String?): List { + if (query == null || query.isEmpty()) { + return bankFinder.getBankList() + } + + return bankFinder.findBankByNameBankCodeOrCity(query) + } + open fun searchAccountTransactions(query: String): List { val queryLowercase = query.trim().toLowerCase() diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/BankListAdapter.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/BankListAdapter.kt index ee546231..c1680be9 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/BankListAdapter.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/BankListAdapter.kt @@ -8,14 +8,14 @@ import android.widget.Filter import android.widget.Filterable import kotlinx.android.synthetic.main.list_item_bank_info.view.* import net.dankito.banking.fints4java.android.R +import net.dankito.banking.fints4java.android.ui.MainWindowPresenter import net.dankito.banking.fints4java.android.ui.adapter.filter.BankInfoFilter -import net.dankito.fints.banks.BankFinder import net.dankito.fints.model.BankInfo import net.dankito.utils.android.extensions.setTintColor import net.dankito.utils.android.ui.adapter.ListAdapter -open class BankListAdapter(protected val bankFinder: BankFinder = BankFinder()) : ListAdapter(), Filterable { +open class BankListAdapter(protected val presenter: MainWindowPresenter) : ListAdapter(), Filterable { override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? { @@ -46,7 +46,7 @@ open class BankListAdapter(protected val bankFinder: BankFinder = BankFinder()) override fun getFilter(): Filter { - return BankInfoFilter(bankFinder) { + return BankInfoFilter(presenter) { this.setItems(it) } } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/filter/BankInfoFilter.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/filter/BankInfoFilter.kt index b116c11e..931c263b 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/filter/BankInfoFilter.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/filter/BankInfoFilter.kt @@ -1,25 +1,19 @@ package net.dankito.banking.fints4java.android.ui.adapter.filter import android.widget.Filter -import net.dankito.fints.banks.BankFinder +import net.dankito.banking.fints4java.android.ui.MainWindowPresenter import net.dankito.fints.model.BankInfo -open class BankInfoFilter(protected val bankFinder: BankFinder, +open class BankInfoFilter(protected val presenter: MainWindowPresenter, protected val publishResultsCallback: (List) -> Unit) : Filter() { override fun performFiltering(constraint: CharSequence?): FilterResults { + val filteredBanks = presenter.searchBanksByNameBankCodeOrCity(constraint?.toString()) + val results = FilterResults() - - constraint?.let { - results.values = bankFinder.findBankByNameBankCodeOrCity(it.toString()) - } - ?: run { - results.values = bankFinder.getBankList() - } - - results.count = (results.values as List<*>).size + results.values = filteredBanks return results } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/AddAccountDialog.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/AddAccountDialog.kt index adf4e3ed..5c3bff2d 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/AddAccountDialog.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/AddAccountDialog.kt @@ -34,7 +34,7 @@ open class AddAccountDialog : DialogFragment() { protected lateinit var presenter: MainWindowPresenter - protected val adapter = BankListAdapter() // TODO: set BankFinder + protected lateinit var adapter: BankListAdapter protected var selectedBank: BankInfo? = null @@ -42,6 +42,9 @@ open class AddAccountDialog : DialogFragment() { fun show(activity: AppCompatActivity, presenter: MainWindowPresenter, fullscreen: Boolean = false) { this.presenter = presenter + presenter.preloadBanksAsync() + this.adapter = BankListAdapter(presenter) + val style = if(fullscreen) R.style.FullscreenDialogWithStatusBar else R.style.Dialog setStyle(STYLE_NORMAL, style) diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/BankTransferDialog.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/BankTransferDialog.kt index 79a6998d..810e2946 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/BankTransferDialog.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/BankTransferDialog.kt @@ -177,7 +177,7 @@ open class BankTransferDialog : DialogFragment() { protected open fun tryToGetBicFromIban(enteredText: CharSequence) { if (enteredText.length >= 12) { // first two characters are country code, 3rd and 4th character are checksum if (enteredText.startsWith("DE", true)) { - presenter.searchForBankAsync(enteredText.substring(4)) { foundBanks -> + presenter.searchBanksByBankCodeAsync(enteredText.substring(4)) { foundBanks -> if (foundBanks.isNotEmpty()) { context?.asActivity()?.runOnUiThread { edtxtRemitteeBic.setText(foundBanks.first().bic) diff --git a/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml b/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml index 9c2709c9..bd1805bf 100644 --- a/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml +++ b/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml @@ -18,10 +18,7 @@ android:layout_width="match_parent" android:layout_height="@dimen/dialog_add_account_edit_text_height" android:inputType="text" - > - - - + /> diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/banks/BankFinder.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/banks/BankFinder.kt index a3eb91e2..a17262b2 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/banks/BankFinder.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/banks/BankFinder.kt @@ -16,10 +16,18 @@ open class BankFinder { open fun findBankByBankCode(query: String): List { + if (query.isEmpty()) { + return getBankList() + } + return getBankList().filter { it.bankCode.startsWith(query) } } open fun findBankByNameBankCodeOrCity(query: String): List { + if (query.isEmpty()) { + return getBankList() + } + val queryLowerCase = query.toLowerCase() return getBankList().filter {