Implemented that user is allowed to set BIC by herself

This commit is contained in:
dankito 2020-04-23 13:53:02 +02:00
parent 4bbc65bfd5
commit e880532cc5
5 changed files with 56 additions and 13 deletions

View File

@ -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})" const val BicPatternString = "[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:\\b|[A-Z0-9]{03})"
val BicPattern = Pattern.compile("^" + BicPatternString + "$") val BicPattern = Pattern.compile("^" + BicPatternString + "$")
val InvalidBicCharactersPattern = Pattern.compile("[^A-Z0-9]")
val InvalidSepaCharactersPattern = Pattern.compile("[^${SepaMessageCreator.AllowedSepaCharacters}]+") 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 { open fun containsOnlyValidSepaCharacters(stringToTest: String): Boolean {
return sepaMessageCreator.containsOnlyAllowedCharacters(stringToTest) return sepaMessageCreator.containsOnlyAllowedCharacters(stringToTest)
} }

View File

@ -99,6 +99,7 @@ open class TransferMoneyDialog : DialogFragment() {
rootView.edtxtRemitteeName.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredRemitteeNameIsValid() } rootView.edtxtRemitteeName.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredRemitteeNameIsValid() }
rootView.edtxtRemitteeIban.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredRemitteeIbanIsValid() } 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.edtxtAmount.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredAmountIsValid() }
rootView.edtxtUsage.setOnFocusChangeListener { _, hasFocus -> if (hasFocus == false) checkIfEnteredUsageTextIsValid() } 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 "") 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) { if (foundBankForEnteredIban) {
lytRemitteeBic.error = null lytRemitteeIban.error = null
} }
checkIfRequiredDataEnteredOnUiThread() checkIfRequiredDataEnteredOnUiThread()
} }
protected open fun checkIfRequiredDataEnteredOnUiThread() { protected open fun checkIfRequiredDataEnteredOnUiThread() {
val isRemitteeNameValid = isRemitteeNameValid() btnTransferMoney.isEnabled = isRemitteeNameValid() && isRemitteeIbanValid()
val isValidIban = isRemitteeIbanValid() && isRemitteeBicValid()
val isAmountValid = isAmountGreaterZero() && isAmountGreaterZero() && isUsageTextValid()
val isUsageTextValid = isUsageTextValid()
btnTransferMoney.isEnabled = isRemitteeNameValid && isValidIban
&& edtxtRemitteeBic?.text.toString().isNotEmpty() // TODO: check if it is of length is 8 or 11?
&& isAmountValid && isUsageTextValid
} }
protected open fun checkIfEnteredRemitteeNameIsValid() { protected open fun checkIfEnteredRemitteeNameIsValid() {
@ -264,11 +261,13 @@ open class TransferMoneyDialog : DialogFragment() {
} }
protected open fun checkIfEnteredRemitteeIbanIsValid() { protected open fun checkIfEnteredRemitteeIbanIsValid() {
val enteredIban = edtxtRemitteeIban.text.toString()
if (isRemitteeIbanValid()) { if (isRemitteeIbanValid()) {
lytRemitteeIban.error = null lytRemitteeIban.error = null
} }
else { else {
val invalidIbanCharacters = inputValidator.getInvalidIbanCharacters(edtxtRemitteeIban.text.toString()) val invalidIbanCharacters = inputValidator.getInvalidIbanCharacters(enteredIban)
if (invalidIbanCharacters.isNotEmpty()) { if (invalidIbanCharacters.isNotEmpty()) {
lytRemitteeIban.error = context?.getString(R.string.error_invalid_iban_characters_entered, invalidIbanCharacters) 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 lytRemitteeBic.error = null
} }
else { else {
@ -289,6 +288,32 @@ open class TransferMoneyDialog : DialogFragment() {
return inputValidator.isValidIban(edtxtRemitteeIban.text.toString()) 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() { protected open fun checkIfEnteredAmountIsValid() {
if (isAmountGreaterZero()) { if (isAmountGreaterZero()) {
lytAmount.error = null lytAmount.error = null

View File

@ -114,7 +114,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/dialog_transfer_money_input_fields_height" android:layout_height="@dimen/dialog_transfer_money_input_fields_height"
android:inputType="text" android:inputType="text"
android:enabled="false"
/> />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>

View File

@ -93,6 +93,10 @@
<string name="error_invalid_iban_characters_entered">Unzulässige(s) Zeichen eingegeben: %s</string> <string name="error_invalid_iban_characters_entered">Unzulässige(s) Zeichen eingegeben: %s</string>
<string name="error_invalid_iban_pattern_entered">IBANs bestehen aus folgendem Muster: DE12 1234 5678 9012 3456 78</string> <string name="error_invalid_iban_pattern_entered">IBANs bestehen aus folgendem Muster: DE12 1234 5678 9012 3456 78</string>
<string name="error_no_bank_found_for_entered_iban">Es wurde keine Bank zur eingegebenen IBAN gefunden.</string> <string name="error_no_bank_found_for_entered_iban">Es wurde keine Bank zur eingegebenen IBAN gefunden.</string>
<string name="error_no_bic_entered">Bitte geben Sie die BIC des Empfängers ein</string>
<string name="error_invalid_bic_characters_entered">Unzulässige(s) Zeichen eingegeben: %s</string>
<string name="error_invalid_bic_pattern_entered">Eine BIC besteht aus 8 oder 11 Zeichen und folgt dem Muster: ABCDED12(XYZ)</string>
<string name="error_no_amount_entered">Bitte geben Sie den zu überweisenden Betrag ein</string>
<string name="error_invalid_amount_entered">Bitte geben Sie einen Betrag größer 0 ein.</string> <string name="error_invalid_amount_entered">Bitte geben Sie einen Betrag größer 0 ein.</string>
</resources> </resources>

View File

@ -93,6 +93,10 @@
<string name="error_invalid_iban_characters_entered">Invalid character(s) entered: %s</string> <string name="error_invalid_iban_characters_entered">Invalid character(s) entered: %s</string>
<string name="error_invalid_iban_pattern_entered">IBAN has to have pattern: EN12 1234 5678 9012 3456 78</string> <string name="error_invalid_iban_pattern_entered">IBAN has to have pattern: EN12 1234 5678 9012 3456 78</string>
<string name="error_no_bank_found_for_entered_iban">No bank found for entered IBAN.</string> <string name="error_no_bank_found_for_entered_iban">No bank found for entered IBAN.</string>
<string name="error_no_bic_entered">Please enter remittee\'s BIC</string>
<string name="error_invalid_bic_characters_entered">Invalid character(s) entered: %s</string>
<string name="error_invalid_bic_pattern_entered">A BIC consists of 8 or 11 characters and has the pattern: ABCDED12(XYZ)</string>
<string name="error_no_amount_entered">Please enter the amount to be transferred</string>
<string name="error_invalid_amount_entered">Please enter an amount greater zero.</string> <string name="error_invalid_amount_entered">Please enter an amount greater zero.</string>
</resources> </resources>