Compare commits
1 commit
53cc032ca2
...
48b7f0bfef
Author | SHA1 | Date | |
---|---|---|---|
48b7f0bfef |
1 changed files with 25 additions and 5 deletions
|
@ -48,9 +48,8 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
|
||||||
matchingId = view.requireViewById(R.id.profile_download_code)
|
matchingId = view.requireViewById(R.id.profile_download_code)
|
||||||
confirmationCode = view.requireViewById(R.id.profile_download_confirmation_code)
|
confirmationCode = view.requireViewById(R.id.profile_download_confirmation_code)
|
||||||
imei = view.requireViewById(R.id.profile_download_imei)
|
imei = view.requireViewById(R.id.profile_download_imei)
|
||||||
smdp.editText!!.addTextChangedListener {
|
smdp.editText!!.addTextChangedListener { updateInputCompleteness() }
|
||||||
updateInputCompleteness()
|
imei.editText!!.addTextChangedListener { updateInputCompleteness() }
|
||||||
}
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +68,28 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateInputCompleteness() {
|
private fun updateInputCompleteness() {
|
||||||
inputComplete = Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()
|
inputComplete = runCatching(::validate).isSuccess
|
||||||
refreshButtons()
|
refreshButtons()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun validate() {
|
||||||
|
check(Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()) {
|
||||||
|
"Invalid SM-DP+ address"
|
||||||
|
}
|
||||||
|
check(imei.editText!!.text.let { it.isEmpty() || isValidIMEI(it) }) {
|
||||||
|
"Invalid IMEI"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isValidIMEI(input: CharSequence): Boolean {
|
||||||
|
if (input.length != 15 || !input.all(Char::isDigit)) return false
|
||||||
|
|
||||||
|
fun sumOfDigits(input: Int): Int {
|
||||||
|
if (input % 2 == 0) return input
|
||||||
|
return (input * 2).toString().map(Char::digitToInt).sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
val sum = input.dropLast(1).map(Char::digitToInt).sumOf(::sumOfDigits)
|
||||||
|
return (sum * 9) % 10 == input.last().digitToInt()
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue