Added AutoCompleteTextView for bank code / FinTS server address; using now TextInputLayout instead of TextView - EditText combo; renamed btnSelect to btnAddAccount

This commit is contained in:
dankl 2019-10-20 23:50:49 +02:00 committed by dankito
parent 6e1185a38c
commit 7e698f78cc
9 changed files with 249 additions and 73 deletions

View File

@ -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", {

View File

@ -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<BankInfo>(), 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)
}
}
}

View File

@ -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<BankInfo>) -> 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<BankInfo>)
}
}

View File

@ -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

View File

@ -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<BankInfo>) {
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
}
}

View File

@ -6,48 +6,78 @@
android:padding="@dimen/dialog_add_account_padding"
>
<TextView
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_label_height"
android:text="@string/dialog_add_account_enter_bank_code"
/>
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:hint="@string/dialog_add_account_enter_bank_code"
>
<EditText
<AutoCompleteTextView
android:id="@+id/edtxtBankCode"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_edit_text_height"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:text="72051210"
/>
android:inputType="text"
>
<TextView
<requestFocus />
</AutoCompleteTextView>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_label_height"
android:text="@string/dialog_add_account_enter_customer_id"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:hint="@string/dialog_add_account_enter_fints_server_address"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/edtxtFinTsServerAddress"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_edit_text_height"
android:inputType="textUri"
android:enabled="false"
/>
<EditText
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:hint="@string/dialog_add_account_enter_customer_id"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/edtxtCustomerId"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_edit_text_height"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:text="560165557"
android:inputType="number"
/>
<TextView
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_label_height"
android:text="@string/dialog_add_account_enter_pin"
/>
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:hint="@string/dialog_add_account_enter_pin"
>
<EditText
<android.support.design.widget.TextInputEditText
android:id="@+id/edtxtPin"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_edit_text_height"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:text="Liebe"
android:inputType="textPassword"
/>
</android.support.design.widget.TextInputLayout>
<RelativeLayout
android:id="@+id/lytButtonBar"
android:layout_width="match_parent"
@ -55,13 +85,13 @@
>
<Button
android:id="@+id/btnSelect"
android:id="@+id/btnAddAccount"
android:layout_width="@dimen/dialog_add_account_buttons_width"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
style="?android:attr/buttonBarButtonStyle"
android:text="@string/select"
android:text="@string/dialog_add_account_add"
android:enabled="false"
/>
@ -69,8 +99,8 @@
android:id="@+id/btnCancel"
android:layout_width="@dimen/dialog_add_account_buttons_width"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/btnSelect"
android:layout_toStartOf="@+id/btnSelect"
android:layout_toLeftOf="@+id/btnAddAccount"
android:layout_toStartOf="@+id/btnAddAccount"
style="?android:attr/buttonBarButtonStyle"
android:text="@string/cancel"
/>

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_bank_info_height"
android:layout_gravity="center_vertical"
>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/imgSupportsFints30"
android:layout_width="@dimen/list_item_bank_info_icon_supports_fints_30_width"
android:layout_height="@dimen/list_item_bank_info_icon_supports_fints_30_height"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:src="@android:drawable/ic_delete"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/imgSupportsFints30"
android:layout_toEndOf="@+id/imgSupportsFints30"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
>
<TextView
android:id="@+id/txtvwBankName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Medium"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_bank_info_bank_code_and_address_height"
>
<TextView
android:id="@+id/txtvwBankCode"
android:layout_width="@dimen/list_item_bank_info_bank_code_width"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/list_item_bank_info_bank_name_margin_bottom"
style="@style/TextAppearance.AppCompat.Small"
android:gravity="center_vertical"
/>
<TextView
android:id="@+id/txtvwBankAddress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="@style/TextAppearance.AppCompat.Small"
android:gravity="center_vertical"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View File

@ -19,4 +19,11 @@
<dimen name="dialog_add_account_field_bottom_margin">12dp</dimen>
<dimen name="dialog_add_account_buttons_width">120dp</dimen>
<dimen name="list_item_bank_info_height">60dp</dimen>
<dimen name="list_item_bank_info_icon_supports_fints_30_height">60dp</dimen>
<dimen name="list_item_bank_info_icon_supports_fints_30_width">60dp</dimen>
<dimen name="list_item_bank_info_bank_name_margin_bottom">12dp</dimen>
<dimen name="list_item_bank_info_bank_code_and_address_height">30dp</dimen>
<dimen name="list_item_bank_info_bank_code_width">80dp</dimen>
</resources>

View File

@ -13,7 +13,9 @@
<string name="menu_home">Home</string>
<string name="dialog_add_account_enter_bank_code">Bank code:</string>
<string name="dialog_add_account_enter_fints_server_address">FinTS server address:</string>
<string name="dialog_add_account_enter_customer_id">Customer Id:</string>
<string name="dialog_add_account_enter_pin">Pin:</string>
<string name="dialog_add_account_add">Add</string>
</resources>