Moved filtering banks to MainWindowPresenter; added preloading banks
This commit is contained in:
parent
149d409dbc
commit
57d7dac613
|
@ -154,16 +154,28 @@ open class MainWindowPresenter(protected val base64Service: IBase64Service,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open fun searchForBankAsync(enteredBankCode: String, callback: (List<BankInfo>) -> Unit) {
|
open fun preloadBanksAsync() {
|
||||||
|
searchBanksByBankCodeAsync("1") { }
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun searchBanksByBankCodeAsync(enteredBankCode: String, callback: (List<BankInfo>) -> Unit) {
|
||||||
threadPool.runAsync {
|
threadPool.runAsync {
|
||||||
callback(searchForBank(enteredBankCode))
|
callback(searchBanksByBankCode(enteredBankCode))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun searchForBank(enteredBankCode: String): List<BankInfo> {
|
open fun searchBanksByBankCode(enteredBankCode: String): List<BankInfo> {
|
||||||
return bankFinder.findBankByBankCode(enteredBankCode)
|
return bankFinder.findBankByBankCode(enteredBankCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun searchBanksByNameBankCodeOrCity(query: String?): List<BankInfo> {
|
||||||
|
if (query == null || query.isEmpty()) {
|
||||||
|
return bankFinder.getBankList()
|
||||||
|
}
|
||||||
|
|
||||||
|
return bankFinder.findBankByNameBankCodeOrCity(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
open fun searchAccountTransactions(query: String): List<AccountTransaction> {
|
open fun searchAccountTransactions(query: String): List<AccountTransaction> {
|
||||||
val queryLowercase = query.trim().toLowerCase()
|
val queryLowercase = query.trim().toLowerCase()
|
||||||
|
|
|
@ -8,14 +8,14 @@ import android.widget.Filter
|
||||||
import android.widget.Filterable
|
import android.widget.Filterable
|
||||||
import kotlinx.android.synthetic.main.list_item_bank_info.view.*
|
import kotlinx.android.synthetic.main.list_item_bank_info.view.*
|
||||||
import net.dankito.banking.fints4java.android.R
|
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.banking.fints4java.android.ui.adapter.filter.BankInfoFilter
|
||||||
import net.dankito.fints.banks.BankFinder
|
|
||||||
import net.dankito.fints.model.BankInfo
|
import net.dankito.fints.model.BankInfo
|
||||||
import net.dankito.utils.android.extensions.setTintColor
|
import net.dankito.utils.android.extensions.setTintColor
|
||||||
import net.dankito.utils.android.ui.adapter.ListAdapter
|
import net.dankito.utils.android.ui.adapter.ListAdapter
|
||||||
|
|
||||||
|
|
||||||
open class BankListAdapter(protected val bankFinder: BankFinder = BankFinder()) : ListAdapter<BankInfo>(), Filterable {
|
open class BankListAdapter(protected val presenter: MainWindowPresenter) : ListAdapter<BankInfo>(), Filterable {
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
|
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 {
|
override fun getFilter(): Filter {
|
||||||
return BankInfoFilter(bankFinder) {
|
return BankInfoFilter(presenter) {
|
||||||
this.setItems(it)
|
this.setItems(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,19 @@
|
||||||
package net.dankito.banking.fints4java.android.ui.adapter.filter
|
package net.dankito.banking.fints4java.android.ui.adapter.filter
|
||||||
|
|
||||||
import android.widget.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
|
import net.dankito.fints.model.BankInfo
|
||||||
|
|
||||||
|
|
||||||
open class BankInfoFilter(protected val bankFinder: BankFinder,
|
open class BankInfoFilter(protected val presenter: MainWindowPresenter,
|
||||||
protected val publishResultsCallback: (List<BankInfo>) -> Unit) : Filter() {
|
protected val publishResultsCallback: (List<BankInfo>) -> Unit) : Filter() {
|
||||||
|
|
||||||
|
|
||||||
override fun performFiltering(constraint: CharSequence?): FilterResults {
|
override fun performFiltering(constraint: CharSequence?): FilterResults {
|
||||||
|
val filteredBanks = presenter.searchBanksByNameBankCodeOrCity(constraint?.toString())
|
||||||
|
|
||||||
val results = FilterResults()
|
val results = FilterResults()
|
||||||
|
results.values = filteredBanks
|
||||||
constraint?.let {
|
|
||||||
results.values = bankFinder.findBankByNameBankCodeOrCity(it.toString())
|
|
||||||
}
|
|
||||||
?: run {
|
|
||||||
results.values = bankFinder.getBankList()
|
|
||||||
}
|
|
||||||
|
|
||||||
results.count = (results.values as List<*>).size
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ open class AddAccountDialog : DialogFragment() {
|
||||||
|
|
||||||
protected lateinit var presenter: MainWindowPresenter
|
protected lateinit var presenter: MainWindowPresenter
|
||||||
|
|
||||||
protected val adapter = BankListAdapter() // TODO: set BankFinder
|
protected lateinit var adapter: BankListAdapter
|
||||||
|
|
||||||
protected var selectedBank: BankInfo? = null
|
protected var selectedBank: BankInfo? = null
|
||||||
|
|
||||||
|
@ -42,6 +42,9 @@ open class AddAccountDialog : DialogFragment() {
|
||||||
fun show(activity: AppCompatActivity, presenter: MainWindowPresenter, fullscreen: Boolean = false) {
|
fun show(activity: AppCompatActivity, presenter: MainWindowPresenter, fullscreen: Boolean = false) {
|
||||||
this.presenter = presenter
|
this.presenter = presenter
|
||||||
|
|
||||||
|
presenter.preloadBanksAsync()
|
||||||
|
this.adapter = BankListAdapter(presenter)
|
||||||
|
|
||||||
val style = if(fullscreen) R.style.FullscreenDialogWithStatusBar else R.style.Dialog
|
val style = if(fullscreen) R.style.FullscreenDialogWithStatusBar else R.style.Dialog
|
||||||
setStyle(STYLE_NORMAL, style)
|
setStyle(STYLE_NORMAL, style)
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ open class BankTransferDialog : DialogFragment() {
|
||||||
protected open fun tryToGetBicFromIban(enteredText: CharSequence) {
|
protected open fun tryToGetBicFromIban(enteredText: CharSequence) {
|
||||||
if (enteredText.length >= 12) { // first two characters are country code, 3rd and 4th character are checksum
|
if (enteredText.length >= 12) { // first two characters are country code, 3rd and 4th character are checksum
|
||||||
if (enteredText.startsWith("DE", true)) {
|
if (enteredText.startsWith("DE", true)) {
|
||||||
presenter.searchForBankAsync(enteredText.substring(4)) { foundBanks ->
|
presenter.searchBanksByBankCodeAsync(enteredText.substring(4)) { foundBanks ->
|
||||||
if (foundBanks.isNotEmpty()) {
|
if (foundBanks.isNotEmpty()) {
|
||||||
context?.asActivity()?.runOnUiThread {
|
context?.asActivity()?.runOnUiThread {
|
||||||
edtxtRemitteeBic.setText(foundBanks.first().bic)
|
edtxtRemitteeBic.setText(foundBanks.first().bic)
|
||||||
|
|
|
@ -18,10 +18,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/dialog_add_account_edit_text_height"
|
android:layout_height="@dimen/dialog_add_account_edit_text_height"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
>
|
/>
|
||||||
|
|
||||||
<requestFocus />
|
|
||||||
</AutoCompleteTextView>
|
|
||||||
|
|
||||||
</android.support.design.widget.TextInputLayout>
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,18 @@ open class BankFinder {
|
||||||
|
|
||||||
|
|
||||||
open fun findBankByBankCode(query: String): List<BankInfo> {
|
open fun findBankByBankCode(query: String): List<BankInfo> {
|
||||||
|
if (query.isEmpty()) {
|
||||||
|
return getBankList()
|
||||||
|
}
|
||||||
|
|
||||||
return getBankList().filter { it.bankCode.startsWith(query) }
|
return getBankList().filter { it.bankCode.startsWith(query) }
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun findBankByNameBankCodeOrCity(query: String): List<BankInfo> {
|
open fun findBankByNameBankCodeOrCity(query: String): List<BankInfo> {
|
||||||
|
if (query.isEmpty()) {
|
||||||
|
return getBankList()
|
||||||
|
}
|
||||||
|
|
||||||
val queryLowerCase = query.toLowerCase()
|
val queryLowerCase = query.toLowerCase()
|
||||||
|
|
||||||
return getBankList().filter {
|
return getBankList().filter {
|
||||||
|
|
Loading…
Reference in New Issue