Compare commits
1 commit
0b80eb1262
...
81d1fb2b70
Author | SHA1 | Date | |
---|---|---|---|
81d1fb2b70 |
2 changed files with 35 additions and 4 deletions
|
@ -48,9 +48,8 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
|
|||
matchingId = view.requireViewById(R.id.profile_download_code)
|
||||
confirmationCode = view.requireViewById(R.id.profile_download_confirmation_code)
|
||||
imei = view.requireViewById(R.id.profile_download_imei)
|
||||
smdp.editText!!.addTextChangedListener {
|
||||
updateInputCompleteness()
|
||||
}
|
||||
smdp.editText!!.addTextChangedListener { updateInputCompleteness() }
|
||||
imei.editText!!.addTextChangedListener { updateInputCompleteness() }
|
||||
return view
|
||||
}
|
||||
|
||||
|
@ -69,7 +68,37 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
|
|||
}
|
||||
|
||||
private fun updateInputCompleteness() {
|
||||
inputComplete = Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()
|
||||
validate()
|
||||
val errors = arrayOf(
|
||||
smdp.editText!!.error,
|
||||
imei.editText!!.error,
|
||||
)
|
||||
inputComplete = errors.all { it == null }
|
||||
refreshButtons()
|
||||
}
|
||||
|
||||
private fun validate() {
|
||||
smdp.error = smdp.editText!!.text?.let {
|
||||
if (Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()) return@let null
|
||||
getString(R.string.download_wizard_error_invalid_address_format)
|
||||
}
|
||||
imei.error = imei.editText!!.text?.let {
|
||||
if (it.isEmpty()) return@let null
|
||||
if (it.length == 15 && luhnValid(it)) return@let null
|
||||
getString(R.string.download_wizard_error_invalid_imei_format)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun luhnValid(number: CharSequence, mod: Int = 10): Boolean {
|
||||
if (!number.all(Char::isDigit)) return false
|
||||
var checksum = 0
|
||||
for (i in number.length - 1 downTo 0 step 2) {
|
||||
checksum += number[i] - '0'
|
||||
}
|
||||
for (i in number.length - 2 downTo 0 step 2) {
|
||||
val n: Int = (number[i] - '0') * 2
|
||||
checksum += if (n > 9) n - 9 else n
|
||||
}
|
||||
return checksum % mod == 0
|
||||
}
|
|
@ -98,6 +98,8 @@
|
|||
<string name="download_wizard_diagnostics_last_apdu_exception">Last APDU exception:</string>
|
||||
<string name="download_wizard_diagnostics_save">Save</string>
|
||||
<string name="download_wizard_diagnostics_file_template">Diagnostics at %s</string>
|
||||
<string name="download_wizard_error_invalid_address_format">Invalid SM-DP+ address</string>
|
||||
<string name="download_wizard_error_invalid_imei_format">Invalid IMEI format</string>
|
||||
|
||||
<string name="logs_saved_message">Logs have been saved to the selected path. Would you like to share the log through another app?</string>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue