feat: if qrcode need confirmation code then alert dialog #136
3 changed files with 42 additions and 7 deletions
|
@ -0,0 +1,24 @@
|
||||||
|
package im.angry.openeuicc.ui.wizard
|
||||||
|
|
||||||
|
|
||||||
|
data class ActivationCode(
|
||||||
|
val address: String,
|
||||||
|
val matchingId: String? = null,
|
||||||
|
val oid: String? = null,
|
||||||
|
val requiredConfirmationCode: Boolean = false,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun fromString(input: String): ActivationCode {
|
||||||
|
val components = input.removePrefix("LPA:").split('$')
|
||||||
|
if (components.size < 2 || components[0] != "1") {
|
||||||
|
throw IllegalArgumentException("Invalid activation code format")
|
||||||
|
}
|
||||||
|
return ActivationCode(
|
||||||
|
address = components[1].trim(),
|
||||||
|
matchingId = components.getOrNull(2)?.trim()?.ifBlank { null },
|
||||||
|
oid = components.getOrNull(3)?.trim()?.ifBlank { null },
|
||||||
|
requiredConfirmationCode = components.getOrNull(4)?.trim() == "1"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -124,9 +124,22 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
|
||||||
processLpaString(text.toString())
|
processLpaString(text.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processLpaString(s: String) {
|
private fun processLpaString(input: String) {
|
||||||
val components = s.split("$")
|
try {
|
||||||
if (components.size < 3 || components[0] != "LPA:1") {
|
val parsed = ActivationCode.fromString(input)
|
||||||
|
state.smdp = parsed.address
|
||||||
|
state.matchingId = parsed.matchingId
|
||||||
|
if (parsed.requiredConfirmationCode) {
|
||||||
|
AlertDialog.Builder(requireContext()).apply {
|
||||||
|
setTitle(R.string.profile_download_required_confirmation_code)
|
||||||
|
setMessage(R.string.profile_download_required_confirmation_code_message)
|
||||||
|
setCancelable(true)
|
||||||
|
setPositiveButton(android.R.string.ok, null)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gotoNextFragment(DownloadWizardDetailsFragment())
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
AlertDialog.Builder(requireContext()).apply {
|
AlertDialog.Builder(requireContext()).apply {
|
||||||
setTitle(R.string.profile_download_incorrect_lpa_string)
|
setTitle(R.string.profile_download_incorrect_lpa_string)
|
||||||
setMessage(R.string.profile_download_incorrect_lpa_string_message)
|
setMessage(R.string.profile_download_incorrect_lpa_string_message)
|
||||||
|
@ -134,11 +147,7 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
|
||||||
setNegativeButton(android.R.string.cancel, null)
|
setNegativeButton(android.R.string.cancel, null)
|
||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
state.smdp = components[1]
|
|
||||||
state.matchingId = components[2]
|
|
||||||
gotoNextFragment(DownloadWizardDetailsFragment())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DownloadMethodViewHolder(private val root: View) : ViewHolder(root) {
|
private class DownloadMethodViewHolder(private val root: View) : ViewHolder(root) {
|
||||||
|
|
|
@ -57,6 +57,8 @@
|
||||||
<string name="profile_download_low_nvram_title">This download may fail</string>
|
<string name="profile_download_low_nvram_title">This download may fail</string>
|
||||||
<string name="profile_download_low_nvram_message">This download may fail due to low remaining capacity.</string>
|
<string name="profile_download_low_nvram_message">This download may fail due to low remaining capacity.</string>
|
||||||
<string name="profile_download_no_lpa_string">No LPA code found in clipboard</string>
|
<string name="profile_download_no_lpa_string">No LPA code found in clipboard</string>
|
||||||
|
<string name="profile_download_required_confirmation_code">Require Confirmation Code</string>
|
||||||
|
<string name="profile_download_required_confirmation_code_message">This QR code or clipboard content requires a confirmation code</string>
|
||||||
<string name="profile_download_incorrect_lpa_string">Unable to parse</string>
|
<string name="profile_download_incorrect_lpa_string">Unable to parse</string>
|
||||||
<string name="profile_download_incorrect_lpa_string_message">Could not parse QR code or clipboard content as a LPA code.</string>
|
<string name="profile_download_incorrect_lpa_string_message">Could not parse QR code or clipboard content as a LPA code.</string>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue