ソースを参照

ui: wizard: Add toast for when clipboard is empty

Peter Cai 1 年間 前
コミット
3430406603

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

@@ -9,6 +9,7 @@ import android.view.View
 import android.view.ViewGroup
 import android.view.ViewGroup
 import android.widget.ImageView
 import android.widget.ImageView
 import android.widget.TextView
 import android.widget.TextView
+import android.widget.Toast
 import androidx.activity.result.contract.ActivityResultContracts
 import androidx.activity.result.contract.ActivityResultContracts
 import androidx.lifecycle.lifecycleScope
 import androidx.lifecycle.lifecycleScope
 import androidx.recyclerview.widget.DividerItemDecoration
 import androidx.recyclerview.widget.DividerItemDecoration
@@ -109,7 +110,17 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
 
 
     private fun handleLoadFromClipboard() {
     private fun handleLoadFromClipboard() {
         val clipboard = requireContext().getSystemService(ClipboardManager::class.java)
         val clipboard = requireContext().getSystemService(ClipboardManager::class.java)
-        val text = clipboard.primaryClip?.getItemAt(0)?.text ?: return
+        val text = clipboard.primaryClip?.getItemAt(0)?.text
+
+        if (text == null) {
+            Toast.makeText(
+                requireContext(),
+                R.string.profile_download_no_lpa_string,
+                Toast.LENGTH_SHORT
+            ).show()
+            return
+        }
+
         processLpaString(text.toString())
         processLpaString(text.toString())
     }
     }
 
 

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

@@ -55,6 +55,7 @@
 
 
     <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 string found in clipboard</string>
     <string name="profile_download_incorrect_lpa_string">Incorrect LPA String</string>
     <string name="profile_download_incorrect_lpa_string">Incorrect LPA String</string>
     <string name="profile_download_incorrect_lpa_string_message">The LPA string could not be parsed</string>
     <string name="profile_download_incorrect_lpa_string_message">The LPA string could not be parsed</string>