瀏覽代碼

wizard: Rework handling for confirmation code from LPA strings

There are more than one way to acquire an LPA string here. Let's just
store whether we need confirmation code as a boolean in state and then
use that to decide whether it is actually required in the step for
inputting details.
Peter Cai 11 月之前
父節點
當前提交
7edde1ffa4

+ 7 - 1
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt

@@ -35,6 +35,7 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
         var downloadTaskID: Long,
         var downloadError: LocalProfileAssistant.ProfileDownloadException?,
         var skipMethodSelect: Boolean,
+        var confirmationCodeRequired: Boolean,
     )
 
     private lateinit var state: DownloadWizardState
@@ -72,7 +73,8 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
             downloadStarted = false,
             downloadTaskID = -1,
             downloadError = null,
-            skipMethodSelect = false
+            skipMethodSelect = false,
+            confirmationCodeRequired = false,
         )
 
         handleDeepLink()
@@ -125,6 +127,7 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
             val parsed = ActivationCode.parse(uri.schemeSpecificPart)
             state.smdp = parsed.address
             state.matchingId = parsed.matchingId
+            state.confirmationCodeRequired = parsed.confirmationCodeRequired
             state.skipMethodSelect = true
         }
     }
@@ -154,6 +157,7 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
         outState.putString("imei", state.imei)
         outState.putBoolean("downloadStarted", state.downloadStarted)
         outState.putLong("downloadTaskID", state.downloadTaskID)
+        outState.putBoolean("confirmationCodeRequired", state.confirmationCodeRequired)
     }
 
     override fun onRestoreInstanceState(savedInstanceState: Bundle) {
@@ -170,6 +174,8 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
         state.downloadStarted =
             savedInstanceState.getBoolean("downloadStarted", state.downloadStarted)
         state.downloadTaskID = savedInstanceState.getLong("downloadTaskID", state.downloadTaskID)
+        state.confirmationCode = savedInstanceState.getString("confirmationCode", state.confirmationCode)
+        state.confirmationCodeRequired = savedInstanceState.getBoolean("confirmationCodeRequired", state.confirmationCodeRequired)
     }
 
     private fun onPrevPressed() {

+ 16 - 0
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardDetailsFragment.kt

@@ -5,6 +5,7 @@ import android.util.Patterns
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.widget.Toast
 import androidx.core.widget.addTextChangedListener
 import com.google.android.material.textfield.TextInputLayout
 import im.angry.openeuicc.common.R
@@ -55,6 +56,9 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
         smdp.editText!!.addTextChangedListener {
             updateInputCompleteness()
         }
+        confirmationCode.editText!!.addTextChangedListener {
+            updateInputCompleteness()
+        }
         return view
     }
 
@@ -65,6 +69,15 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
         confirmationCode.editText!!.setText(state.confirmationCode)
         imei.editText!!.setText(state.imei)
         updateInputCompleteness()
+
+        if (state.confirmationCodeRequired) {
+            confirmationCode.editText!!.requestFocus()
+            confirmationCode.editText!!.hint =
+                getString(R.string.profile_download_confirmation_code_required)
+        } else {
+            confirmationCode.editText!!.hint =
+                getString(R.string.profile_download_confirmation_code)
+        }
     }
 
     override fun onPause() {
@@ -74,6 +87,9 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
 
     private fun updateInputCompleteness() {
         inputComplete = Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()
+        if (state.confirmationCodeRequired) {
+            inputComplete = inputComplete && confirmationCode.editText!!.text.isNotEmpty()
+        }
         refreshButtons()
     }
 }

+ 8 - 11
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardMethodSelectFragment.kt

@@ -129,15 +129,7 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
             val parsed = ActivationCode.parse(input)
             state.smdp = parsed.address
             state.matchingId = parsed.matchingId
-            if (parsed.confirmationCodeRequired) {
-                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()
-                }
-            }
+            state.confirmationCodeRequired = parsed.confirmationCodeRequired
             gotoNextFragment(DownloadWizardDetailsFragment())
         } catch (e: IllegalArgumentException) {
             AlertDialog.Builder(requireContext()).apply {
@@ -150,14 +142,19 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
         }
     }
 
-    private class DownloadMethodViewHolder(private val root: View) : ViewHolder(root) {
+    private inner class DownloadMethodViewHolder(private val root: View) : ViewHolder(root) {
         private val icon = root.requireViewById<ImageView>(R.id.download_method_icon)
         private val title = root.requireViewById<TextView>(R.id.download_method_title)
 
         fun bind(item: DownloadMethod) {
             icon.setImageResource(item.iconRes)
             title.setText(item.titleRes)
-            root.setOnClickListener { item.onClick() }
+            root.setOnClickListener {
+                // If the user elected to use another download method, reset the confirmation code flag
+                // too
+                state.confirmationCodeRequired = false
+                item.onClick()
+            }
         }
     }
 

+ 1 - 2
app-common/src/main/res/values-ja/strings.xml

@@ -42,12 +42,11 @@
     <string name="profile_download_server">サーバー (RSP / SM-DP+)</string>
     <string name="profile_download_code">アクティベーションコード</string>
     <string name="profile_download_confirmation_code">確認コード (オプション)</string>
+    <string name="profile_download_confirmation_code_required">確認コード (必須)</string>
     <string name="profile_download_imei">IMEI (オプション)</string>
     <string name="profile_download_low_nvram_title">ダウンロードに失敗する可能性があります</string>
     <string name="profile_download_low_nvram_message">残り容量が少ないため、ダウンロードに失敗する可能性があります。</string>
     <string name="profile_download_no_lpa_string">クリップボードに LPA コードがありません</string>
-    <string name="profile_download_required_confirmation_code">確認コードが必要です</string>
-    <string name="profile_download_required_confirmation_code_message">クリップボードからスキャンした QR コードまたは LPA コードに必要な確認コードを入力してください。</string>
     <string name="profile_download_incorrect_lpa_string">解析できません</string>
     <string name="profile_download_incorrect_lpa_string_message">QR コードまたはクリップボードの内容を LPA コードとして解析できませんでした。</string>
     <string name="download_wizard">ダウンロードウィザード</string>

+ 1 - 2
app-common/src/main/res/values-zh-rCN/strings.xml

@@ -37,6 +37,7 @@
     <string name="profile_download_server">服务器 (RSP / SM-DP+)</string>
     <string name="profile_download_code">激活码</string>
     <string name="profile_download_confirmation_code">确认码 (可选)</string>
+    <string name="profile_download_confirmation_code_required">确认码 (必需)</string>
     <string name="profile_download_imei">IMEI (可选)</string>
     <string name="profile_download_low_nvram_title">本次下载可能会失败</string>
     <string name="profile_download_low_nvram_message">当前芯片的剩余空间不足,可能导致配置下载失败。\n是否继续下载?</string>
@@ -144,6 +145,4 @@
     <string name="pref_developer_ignore_tls_certificate">无视 SM-DP+ 的 TLS 证书</string>
     <string name="pref_developer_ignore_tls_certificate_desc">允许 RSP 服务器使用任意证书</string>
     <string name="information_unavailable">无信息</string>
-    <string name="profile_download_required_confirmation_code">需要确认码</string>
-    <string name="profile_download_required_confirmation_code_message">您扫描的二维码或粘贴的 LPA 码需要一个额外的确认码</string>
 </resources>

+ 1 - 0
app-common/src/main/res/values-zh-rTW/strings.xml

@@ -37,6 +37,7 @@
     <string name="profile_download_server">伺服器 (RSP / SM-DP+)</string>
     <string name="profile_download_code">啟用碼</string>
     <string name="profile_download_confirmation_code">確認碼 (可選)</string>
+    <string name="profile_download_confirmation_code_required">確認碼 (必需)</string>
     <string name="profile_download_imei">IMEI (可選)</string>
     <string name="profile_download_low_nvram_title">本次下載可能會失敗</string>
     <string name="profile_download_low_nvram_message">目前晶片的剩餘空間不足,可能導致配置下載失敗。\n是否繼續下載?</string>

+ 1 - 2
app-common/src/main/res/values/strings.xml

@@ -53,13 +53,12 @@
     <string name="profile_download_server">Server (RSP / SM-DP+)</string>
     <string name="profile_download_code">Activation Code</string>
     <string name="profile_download_confirmation_code">Confirmation Code (Optional)</string>
+    <string name="profile_download_confirmation_code_required">Confirmation Code (Required)</string>
     <string name="profile_download_imei">IMEI (Optional)</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_no_lpa_string">No LPA code found in clipboard</string>
-    <string name="profile_download_required_confirmation_code">Confirmation Code Required</string>
-    <string name="profile_download_required_confirmation_code_message">Please provide a confirmation code as required by the scanned QR code or LPA code from clipboard.</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>