Implemented BankTransferDialog

This commit is contained in:
dankl 2019-10-20 23:52:07 +02:00 committed by dankito
parent 7e698f78cc
commit 1444d93860
4 changed files with 258 additions and 0 deletions

View File

@ -0,0 +1,124 @@
package net.dankito.banking.fints4java.android.ui.dialogs
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v7.app.AppCompatActivity
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.dialog_bank_transfer.*
import kotlinx.android.synthetic.main.dialog_bank_transfer.view.*
import net.dankito.banking.fints4java.android.R
import net.dankito.banking.fints4java.android.ui.MainWindowPresenter
import net.dankito.utils.android.extensions.asActivity
import java.math.BigDecimal
open class BankTransferDialog : DialogFragment() {
companion object {
const val DialogTag = "BankTransferDialog"
}
protected lateinit var presenter: MainWindowPresenter
open fun show(activity: AppCompatActivity, presenter: MainWindowPresenter, fullscreen: Boolean = false) {
this.presenter = presenter
val style = if(fullscreen) R.style.FullscreenDialogWithStatusBar else R.style.Dialog
setStyle(STYLE_NORMAL, style)
show(activity.supportFragmentManager, DialogTag)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.dialog_bank_transfer, container, false)
setupUI(rootView)
return rootView
}
protected open fun setupUI(rootView: View) {
// TODO: add autocompletion by searching for name in account entries
rootView.edtxtRemitteeName.addTextChangedListener(otherEditTextChangedWatcher)
rootView.edtxtRemitteeIban.addTextChangedListener(ibanChangedWatcher)
rootView.edtxtRemitteeBic.addTextChangedListener(otherEditTextChangedWatcher)
rootView.edtxtAmount.addTextChangedListener(otherEditTextChangedWatcher)
rootView.btnCancel.setOnClickListener { dismiss() }
rootView.btnDoBankTransfer.setOnClickListener { dismiss() }
}
protected val otherEditTextChangedWatcher = object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { }
override fun onTextChanged(enteredText: CharSequence?, start: Int, before: Int, count: Int) {
checkIfRequiredDataEnteredOnUiThread()
}
override fun afterTextChanged(s: Editable?) { }
}
protected val ibanChangedWatcher = 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 {
tryToGetBicFromIban(enteredText)
}
}
override fun afterTextChanged(s: Editable?) { }
}
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 ->
if (foundBanks.isNotEmpty()) {
context?.asActivity()?.runOnUiThread {
edtxtRemitteeBic.setText(foundBanks.first().bic)
checkIfRequiredDataEnteredOnUiThread()
}
}
}
}
}
}
protected open fun checkIfRequiredDataEnteredOnUiThread() {
val requiredDataEntered =
edtxtRemitteeName.text.toString().isNotEmpty()
&& edtxtRemitteeIban.text.toString().isNotEmpty() // TODO: check if it is of length > 12, in Germany > 22?
&& edtxtRemitteeBic?.text.toString().isNotEmpty() // TODO: check if it is of length is 8 or 11?
&& isAmountGreaterZero(edtxtAmount.text.toString())
btnDoBankTransfer.isEnabled = requiredDataEntered
}
protected open fun isAmountGreaterZero(amountString: String): Boolean {
try {
val amount = amountString.toBigDecimal()
return amount > BigDecimal.ZERO
} catch (ignored: Exception) { }
return false
}
}

View File

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/dialog_bank_transfer_padding"
>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dialog_bank_transfer_remittee_name"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/edtxtRemitteeName"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_bank_transfer_input_fields_height"
android:inputType="textPersonName"
>
<requestFocus />
</android.support.design.widget.TextInputEditText>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dialog_bank_transfer_remittee_iban"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/edtxtRemitteeIban"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_bank_transfer_autocomplete_fields_height"
android:inputType="text"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dialog_bank_transfer_remittee_bic"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/edtxtRemitteeBic"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_bank_transfer_input_fields_height"
android:inputType="text"
android:enabled="false"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dialog_bank_transfer_amount"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/edtxtAmount"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_bank_transfer_input_fields_height"
android:inputType="numberDecimal"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dialog_bank_transfer_usage"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/edtxtUsage"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_bank_transfer_input_fields_height"
android:inputType="text"
/>
</android.support.design.widget.TextInputLayout>
<RelativeLayout
android:id="@+id/lytButtonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/btnDoBankTransfer"
android:layout_width="@dimen/dialog_bank_transfer_buttons_width"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
style="?android:attr/buttonBarButtonStyle"
android:text="@string/dialog_bank_transfer_transfer"
android:enabled="false"
/>
<Button
android:id="@+id/btnCancel"
android:layout_width="@dimen/dialog_bank_transfer_buttons_width"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/btnDoBankTransfer"
android:layout_toStartOf="@+id/btnDoBankTransfer"
style="?android:attr/buttonBarButtonStyle"
android:text="@string/cancel"
/>
</RelativeLayout>
</LinearLayout>

View File

@ -26,4 +26,9 @@
<dimen name="list_item_bank_info_bank_code_and_address_height">30dp</dimen>
<dimen name="list_item_bank_info_bank_code_width">80dp</dimen>
<dimen name="dialog_bank_transfer_padding">4dp</dimen>
<dimen name="dialog_bank_transfer_input_fields_height">40dp</dimen>
<dimen name="dialog_bank_transfer_autocomplete_fields_height">50dp</dimen>
<dimen name="dialog_bank_transfer_buttons_width">120dp</dimen>
</resources>

View File

@ -18,4 +18,11 @@
<string name="dialog_add_account_enter_pin">Pin:</string>
<string name="dialog_add_account_add">Add</string>
<string name="dialog_bank_transfer_remittee_name">Name:</string>
<string name="dialog_bank_transfer_remittee_iban">IBAN:</string>
<string name="dialog_bank_transfer_remittee_bic">BIC:</string>
<string name="dialog_bank_transfer_amount">Amount:</string>
<string name="dialog_bank_transfer_usage">Usage:</string>
<string name="dialog_bank_transfer_transfer">Transfer</string>
</resources>