diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt b/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt
index ecf3c9bf..3b4fc027 100644
--- a/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt
+++ b/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt
@@ -44,6 +44,8 @@ open class InputValidator {
const val BicPatternString = "[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:\\b|[A-Z0-9]{03})"
val BicPattern = Pattern.compile("^" + BicPatternString + "$")
+ val InvalidBicCharactersPattern = Pattern.compile("[^A-Z0-9]")
+
val InvalidSepaCharactersPattern = Pattern.compile("[^${SepaMessageCreator.AllowedSepaCharacters}]+")
}
@@ -62,6 +64,15 @@ open class InputValidator {
}
+ open fun isValidBic(stringToTest: String): Boolean {
+ return BicPattern.matcher(stringToTest).matches()
+ }
+
+ open fun getInvalidBicCharacters(string: String): String {
+ return getInvalidCharacters(string, InvalidBicCharactersPattern)
+ }
+
+
open fun containsOnlyValidSepaCharacters(stringToTest: String): Boolean {
return sepaMessageCreator.containsOnlyAllowedCharacters(stringToTest)
}
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 28e9eaa1..4c9c717b 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
@@ -99,6 +99,7 @@ open class TransferMoneyDialog : DialogFragment() {
rootView.edtxtRemitteeName.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredRemitteeNameIsValid() }
rootView.edtxtRemitteeIban.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredRemitteeIbanIsValid() }
+ rootView.edtxtRemitteeBic.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredRemitteeBicIsValid() }
rootView.edtxtAmount.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredAmountIsValid() }
rootView.edtxtUsage.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredUsageTextIsValid() }
@@ -226,24 +227,20 @@ open class TransferMoneyDialog : DialogFragment() {
edtxtRemitteeBank.setText(if (foundBank != null) (foundBank.name + " " + foundBank.city) else "")
- edtxtRemitteeBic.setText(foundBank?.bic ?: "")
+ edtxtRemitteeBic.setText(foundBank?.bic ?: "") // TODO: check if user entered BIC to not overwrite self entered BIC
+ lytRemitteeBic.error = null
if (foundBankForEnteredIban) {
- lytRemitteeBic.error = null
+ lytRemitteeIban.error = null
}
checkIfRequiredDataEnteredOnUiThread()
}
protected open fun checkIfRequiredDataEnteredOnUiThread() {
- val isRemitteeNameValid = isRemitteeNameValid()
- val isValidIban = isRemitteeIbanValid()
- val isAmountValid = isAmountGreaterZero()
- val isUsageTextValid = isUsageTextValid()
-
- btnTransferMoney.isEnabled = isRemitteeNameValid && isValidIban
- && edtxtRemitteeBic?.text.toString().isNotEmpty() // TODO: check if it is of length is 8 or 11?
- && isAmountValid && isUsageTextValid
+ btnTransferMoney.isEnabled = isRemitteeNameValid() && isRemitteeIbanValid()
+ && isRemitteeBicValid()
+ && isAmountGreaterZero() && isUsageTextValid()
}
protected open fun checkIfEnteredRemitteeNameIsValid() {
@@ -264,11 +261,13 @@ open class TransferMoneyDialog : DialogFragment() {
}
protected open fun checkIfEnteredRemitteeIbanIsValid() {
+ val enteredIban = edtxtRemitteeIban.text.toString()
+
if (isRemitteeIbanValid()) {
lytRemitteeIban.error = null
}
else {
- val invalidIbanCharacters = inputValidator.getInvalidIbanCharacters(edtxtRemitteeIban.text.toString())
+ val invalidIbanCharacters = inputValidator.getInvalidIbanCharacters(enteredIban)
if (invalidIbanCharacters.isNotEmpty()) {
lytRemitteeIban.error = context?.getString(R.string.error_invalid_iban_characters_entered, invalidIbanCharacters)
}
@@ -277,7 +276,7 @@ open class TransferMoneyDialog : DialogFragment() {
}
}
- if (foundBankForEnteredIban) {
+ if (foundBankForEnteredIban || enteredIban.isBlank()) {
lytRemitteeBic.error = null
}
else {
@@ -289,6 +288,32 @@ open class TransferMoneyDialog : DialogFragment() {
return inputValidator.isValidIban(edtxtRemitteeIban.text.toString())
}
+ protected open fun checkIfEnteredRemitteeBicIsValid() {
+ if (isRemitteeBicValid()) {
+ lytRemitteeBic.error = null
+ }
+ else {
+ val enteredBic = edtxtRemitteeBic.text.toString()
+
+ if (enteredBic.isBlank()) {
+ lytRemitteeBic.error = context?.getString(R.string.error_no_bic_entered)
+ }
+ else {
+ val invalidBicCharacters = inputValidator.getInvalidBicCharacters(enteredBic)
+ if (invalidBicCharacters.isNotEmpty()) {
+ lytRemitteeBic.error = context?.getString(R.string.error_invalid_bic_characters_entered, invalidBicCharacters)
+ }
+ else {
+ lytRemitteeBic.error = context?.getString(R.string.error_invalid_bic_pattern_entered)
+ }
+ }
+ }
+ }
+
+ protected open fun isRemitteeBicValid(): Boolean {
+ return inputValidator.isValidBic(edtxtRemitteeBic.text.toString())
+ }
+
protected open fun checkIfEnteredAmountIsValid() {
if (isAmountGreaterZero()) {
lytAmount.error = null
diff --git a/fints4javaAndroidApp/src/main/res/layout/dialog_transfer_money.xml b/fints4javaAndroidApp/src/main/res/layout/dialog_transfer_money.xml
index cd54455b..9589d842 100644
--- a/fints4javaAndroidApp/src/main/res/layout/dialog_transfer_money.xml
+++ b/fints4javaAndroidApp/src/main/res/layout/dialog_transfer_money.xml
@@ -114,7 +114,6 @@
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_transfer_money_input_fields_height"
android:inputType="text"
- android:enabled="false"
/>
diff --git a/fints4javaAndroidApp/src/main/res/values-de/strings.xml b/fints4javaAndroidApp/src/main/res/values-de/strings.xml
index f1d98e22..d662f792 100644
--- a/fints4javaAndroidApp/src/main/res/values-de/strings.xml
+++ b/fints4javaAndroidApp/src/main/res/values-de/strings.xml
@@ -93,6 +93,10 @@
Unzulässige(s) Zeichen eingegeben: %s
IBANs bestehen aus folgendem Muster: DE12 1234 5678 9012 3456 78
Es wurde keine Bank zur eingegebenen IBAN gefunden.
+ Bitte geben Sie die BIC des Empfängers ein
+ Unzulässige(s) Zeichen eingegeben: %s
+ Eine BIC besteht aus 8 oder 11 Zeichen und folgt dem Muster: ABCDED12(XYZ)
+ Bitte geben Sie den zu überweisenden Betrag ein
Bitte geben Sie einen Betrag größer 0 ein.
diff --git a/fints4javaAndroidApp/src/main/res/values/strings.xml b/fints4javaAndroidApp/src/main/res/values/strings.xml
index fb8f9209..58a1ca7f 100644
--- a/fints4javaAndroidApp/src/main/res/values/strings.xml
+++ b/fints4javaAndroidApp/src/main/res/values/strings.xml
@@ -93,6 +93,10 @@
Invalid character(s) entered: %s
IBAN has to have pattern: EN12 1234 5678 9012 3456 78
No bank found for entered IBAN.
+ Please enter remittee\'s BIC
+ Invalid character(s) entered: %s
+ A BIC consists of 8 or 11 characters and has the pattern: ABCDED12(XYZ)
+ Please enter the amount to be transferred
Please enter an amount greater zero.