diff --git a/fints4javaAndroidApp/build.gradle b/fints4javaAndroidApp/build.gradle index c4a7b978..30183272 100644 --- a/fints4javaAndroidApp/build.gradle +++ b/fints4javaAndroidApp/build.gradle @@ -27,7 +27,7 @@ android { dependencies { implementation project(':fints4javaLib') -// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" api "net.dankito.utils:android-utils:$androidUtilsVersion", { 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 new file mode 100644 index 00000000..7b8b7bc6 --- /dev/null +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/BankListAdapter.kt @@ -0,0 +1,46 @@ +package net.dankito.banking.fints4java.android.ui.adapter + +import android.content.Context.LAYOUT_INFLATER_SERVICE +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +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.adapter.filter.BankInfoFilter +import net.dankito.fints.banks.BankFinder +import net.dankito.fints.model.BankInfo +import net.dankito.utils.android.ui.adapter.ListAdapter + + +open class BankListAdapter(protected val bankFinder: BankFinder = BankFinder()) : ListAdapter(), Filterable { + + override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? { + + val item = getItem(position) + + val inflater = parent?.context?.getSystemService(LAYOUT_INFLATER_SERVICE) as? LayoutInflater + val view = convertView ?: inflater?.inflate(R.layout.list_item_bank_info, parent, false) + + view?.let { + // view.imgSupportsFints30.setImageResource(if (item.supportsFinTs3_0) ) // TODO + + view.txtvwBankName.text = item.name + + view.txtvwBankCode.text = item.bankCode + + view.txtvwBankAddress.text = item.postalCode + " " + item.city + } + + return view + } + + + override fun getFilter(): Filter { + return BankInfoFilter(bankFinder) { + this.setItems(it) + } + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000..b116c11e --- /dev/null +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/filter/BankInfoFilter.kt @@ -0,0 +1,31 @@ +package net.dankito.banking.fints4java.android.ui.adapter.filter + +import android.widget.Filter +import net.dankito.fints.banks.BankFinder +import net.dankito.fints.model.BankInfo + + +open class BankInfoFilter(protected val bankFinder: BankFinder, + protected val publishResultsCallback: (List) -> Unit) : Filter() { + + + override fun performFiltering(constraint: CharSequence?): FilterResults { + val results = FilterResults() + + constraint?.let { + results.values = bankFinder.findBankByNameBankCodeOrCity(it.toString()) + } + ?: run { + results.values = bankFinder.getBankList() + } + + results.count = (results.values as List<*>).size + + return results + } + + override fun publishResults(constraint: CharSequence?, results: FilterResults) { + publishResultsCallback(results.values as List) + } + +} \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/viewholder/AccountTransactionViewHolder.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/viewholder/AccountTransactionViewHolder.kt index b0169615..21906726 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/viewholder/AccountTransactionViewHolder.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/adapter/viewholder/AccountTransactionViewHolder.kt @@ -6,7 +6,7 @@ import android.widget.TextView import kotlinx.android.synthetic.main.list_item_account_transaction.view.* -class AccountTransactionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { +open class AccountTransactionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val txtvwBookingDate: TextView = itemView.txtvwBookingDate 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 50a3b103..c58051c4 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 @@ -13,21 +13,24 @@ import kotlinx.android.synthetic.main.dialog_add_account.* import kotlinx.android.synthetic.main.dialog_add_account.view.* import net.dankito.banking.fints4java.android.R import net.dankito.banking.fints4java.android.ui.MainWindowPresenter +import net.dankito.banking.fints4java.android.ui.adapter.BankListAdapter import net.dankito.fints.model.BankInfo import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.utils.android.extensions.asActivity -class AddAccountDialog : DialogFragment() { +open class AddAccountDialog : DialogFragment() { companion object { const val DialogTag = "AddAccountDialog" } - private lateinit var presenter: MainWindowPresenter + protected lateinit var presenter: MainWindowPresenter - private var selectedBank: BankInfo? = null + protected val adapter = BankListAdapter() // TODO: set BankFinder + + protected var selectedBank: BankInfo? = null fun show(activity: AppCompatActivity, presenter: MainWindowPresenter, fullscreen: Boolean = false) { @@ -50,17 +53,20 @@ class AddAccountDialog : DialogFragment() { return rootView } - private fun setupUI(rootView: View) { - rootView.edtxtBankCode.addTextChangedListener(bankCodeChangedWatcher) + protected open fun setupUI(rootView: View) { + rootView.edtxtBankCode.threshold = 1 // will start working from first character + rootView.edtxtBankCode.setAdapter(adapter) + + rootView.edtxtBankCode.setOnItemClickListener { _, _, position, _ -> bankSelected(adapter.getItem(position)) } rootView.edtxtCustomerId.addTextChangedListener(otherEditTextChangedWatcher) rootView.edtxtPin.addTextChangedListener(otherEditTextChangedWatcher) - rootView.btnSelect.setOnClickListener { addAccount() } + rootView.btnAddAccount.setOnClickListener { addAccount() } rootView.btnCancel.setOnClickListener { dismiss() } } - private fun addAccount() { + protected open fun addAccount() { selectedBank?.let { selectedBank -> // should always be non-null at this stage val customerId = edtxtCustomerId.text.toString() val pin = edtxtPin.text.toString() @@ -73,7 +79,7 @@ class AddAccountDialog : DialogFragment() { } } - private fun handleAccountCheckResponseOnUiThread(response: FinTsClientResponse) { + protected open fun handleAccountCheckResponseOnUiThread(response: FinTsClientResponse) { context?.let { context -> if (response.isSuccessful) { AlertDialog.Builder(context) @@ -89,19 +95,7 @@ class AddAccountDialog : DialogFragment() { } - val bankCodeChangedWatcher = object : TextWatcher { - - override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { } - - override fun onTextChanged(enteredText: CharSequence?, start: Int, before: Int, count: Int) { - enteredText?.let { searchForBankAsync(enteredText) } - } - - override fun afterTextChanged(s: Editable?) { } - - } - - val otherEditTextChangedWatcher = object : TextWatcher { + protected val otherEditTextChangedWatcher = object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { } @@ -113,31 +107,27 @@ class AddAccountDialog : DialogFragment() { } - private fun searchForBankAsync(enteredBankCode: CharSequence) { - presenter.searchForBankAsync(enteredBankCode.toString()) { foundBanks -> - context?.asActivity()?.runOnUiThread { - showFoundBanksOnUiThread(foundBanks) - } - } - } + protected open fun bankSelected(bank: BankInfo) { + if (bank.supportsFinTs3_0) { + selectedBank = bank - private fun showFoundBanksOnUiThread(foundBanks: List) { - if (foundBanks.isNotEmpty()) { - selectedBank = foundBanks.first() - } - else { - selectedBank = null + edtxtBankCode.setText(bank.bankCode) + + edtxtFinTsServerAddress.setText(bank.pinTanAddress) + + edtxtBankCode.clearListSelection() } checkIfRequiredDataEnteredOnUiThread() } - private fun checkIfRequiredDataEnteredOnUiThread() { + protected open fun checkIfRequiredDataEnteredOnUiThread() { val requiredDataEntered = selectedBank != null + && selectedBank?.supportsFinTs3_0 == true && edtxtCustomerId.text.toString().isNotEmpty() // TODO: check if it is of length 10? && edtxtPin.text.toString().isNotEmpty() // TODO: check if it is of length 5? - btnSelect.isEnabled = requiredDataEntered + btnAddAccount.isEnabled = requiredDataEntered } } \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml b/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml index 17698d04..e6ec70e8 100644 --- a/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml +++ b/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml @@ -6,47 +6,77 @@ android:padding="@dimen/dialog_add_account_padding" > - - - + android:hint="@string/dialog_add_account_enter_bank_code" + > - + - + + + + + + + android:hint="@string/dialog_add_account_enter_fints_server_address" + > - + - + + + + android:hint="@string/dialog_add_account_enter_customer_id" + > + + + + + + + + + + + +