From 4d551197f909a0ab6a29a68d59d9c077d8eaf166 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 30 Apr 2020 17:19:11 +0200 Subject: [PATCH] Implemented accepting TAN or transferring money if enter key is pressed --- .../android/ui/dialogs/EnterTanDialog.kt | 9 ++++++++ .../android/ui/dialogs/TransferMoneyDialog.kt | 21 +++++++++++++++++++ .../ui/extensions/EditTextExtensions.kt | 15 +++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/extensions/EditTextExtensions.kt diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterTanDialog.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterTanDialog.kt index fe027aae..ae2621c7 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterTanDialog.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterTanDialog.kt @@ -5,6 +5,7 @@ import android.graphics.BitmapFactory import android.os.Bundle import android.os.Handler import android.text.InputType +import android.view.KeyEvent import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -163,6 +164,14 @@ open class EnterTanDialog : DialogFragment() { } rootView.edtxtEnteredTan.inputType = InputType.TYPE_CLASS_NUMBER + + rootView.edtxtEnteredTan.setOnKeyListener { _, keyCode, _ -> + if (keyCode == KeyEvent.KEYCODE_ENTER) { + enteringTanDone(rootView.edtxtEnteredTan.text.toString()) + return@setOnKeyListener true + } + false + } } } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt index 2962eeef..815c417b 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt @@ -19,6 +19,7 @@ import net.dankito.banking.fints4java.android.R import net.dankito.banking.fints4java.android.di.BankingComponent import net.dankito.banking.fints4java.android.ui.adapter.BankAccountsAdapter import net.dankito.banking.fints4java.android.ui.adapter.presenter.RemitteePresenter +import net.dankito.banking.fints4java.android.ui.extensions.addEnterPressedListener import net.dankito.banking.fints4java.android.ui.listener.ListItemSelectedListener import net.dankito.banking.fints4java.android.util.StandardAutocompleteCallback import net.dankito.banking.fints4java.android.util.StandardTextWatcher @@ -127,6 +128,12 @@ open class TransferMoneyDialog : DialogFragment() { rootView.edtxtAmount.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredAmountIsValid() } rootView.edtxtUsage.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredUsageTextIsValid() } + transferMoneyIfEnterPressed(rootView.edtxtRemitteeName) + transferMoneyIfEnterPressed(rootView.edtxtRemitteeIban) + transferMoneyIfEnterPressed(rootView.edtxtRemitteeBic) + transferMoneyIfEnterPressed(rootView.edtxtAmount) + transferMoneyIfEnterPressed(rootView.edtxtUsage) + // fix that even in Locales using ',' as decimal separator entering ',' is not allowed (thanks dstibbe! https://stackoverflow.com/a/34256139) val decimalSeparator = DecimalFormatSymbols.getInstance().getDecimalSeparator() rootView.edtxtAmount.keyListener = DigitsKeyListener.getInstance("0123456789$decimalSeparator") @@ -136,6 +143,20 @@ open class TransferMoneyDialog : DialogFragment() { rootView.btnTransferMoney.setOnClickListener { transferMoney() } } + private fun transferMoneyIfEnterPressed(editText: EditText) { + editText.addEnterPressedListener { + if (isRequiredDataEntered()) { + transferMoney() + + return@addEnterPressedListener true + } + + false + } + } + + private fun isRequiredDataEntered() = btnTransferMoney.isEnabled + private fun initRemitteeAutocompletion(edtxtRemitteeName: EditText) { val autocompleteCallback = StandardAutocompleteCallback { _, item -> remitteeSelected(item) diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/extensions/EditTextExtensions.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/extensions/EditTextExtensions.kt new file mode 100644 index 00000000..30577f6e --- /dev/null +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/extensions/EditTextExtensions.kt @@ -0,0 +1,15 @@ +package net.dankito.banking.fints4java.android.ui.extensions + +import android.view.KeyEvent +import android.widget.EditText + + +fun EditText.addEnterPressedListener(enterPressed: () -> Boolean) { + this.setOnKeyListener { _, keyCode, _ -> + if (keyCode == KeyEvent.KEYCODE_ENTER) { + return@setOnKeyListener enterPressed() + } + + false + } +} \ No newline at end of file