|
@@ -3,6 +3,7 @@ package im.angry.openeuicc.ui
|
|
|
import android.annotation.SuppressLint
|
|
import android.annotation.SuppressLint
|
|
|
import android.app.Dialog
|
|
import android.app.Dialog
|
|
|
import android.content.DialogInterface
|
|
import android.content.DialogInterface
|
|
|
|
|
+import android.graphics.BitmapFactory
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
import android.text.Editable
|
|
import android.text.Editable
|
|
|
import android.util.Log
|
|
import android.util.Log
|
|
@@ -10,6 +11,7 @@ import android.view.*
|
|
|
import android.widget.ProgressBar
|
|
import android.widget.ProgressBar
|
|
|
import android.widget.TextView
|
|
import android.widget.TextView
|
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
|
|
|
+import androidx.activity.result.contract.ActivityResultContracts
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import com.google.android.material.textfield.TextInputLayout
|
|
import com.google.android.material.textfield.TextInputLayout
|
|
@@ -54,13 +56,38 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
|
|
private val barcodeScannerLauncher = registerForActivityResult(ScanContract()) { result ->
|
|
private val barcodeScannerLauncher = registerForActivityResult(ScanContract()) { result ->
|
|
|
result.contents?.let { content ->
|
|
result.contents?.let { content ->
|
|
|
Log.d(TAG, content)
|
|
Log.d(TAG, content)
|
|
|
- val components = content.split("$")
|
|
|
|
|
- if (components.size < 3 || components[0] != "LPA:1") return@registerForActivityResult
|
|
|
|
|
- profileDownloadServer.editText?.setText(components[1])
|
|
|
|
|
- profileDownloadCode.editText?.setText(components[2])
|
|
|
|
|
|
|
+ onScanResult(content)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private val gallerySelectorLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { result ->
|
|
|
|
|
+ if (result == null) return@registerForActivityResult
|
|
|
|
|
+
|
|
|
|
|
+ lifecycleScope.launch(Dispatchers.IO) {
|
|
|
|
|
+ runCatching {
|
|
|
|
|
+ requireContext().contentResolver.openInputStream(result)?.let { input ->
|
|
|
|
|
+ val bmp = BitmapFactory.decodeStream(input)
|
|
|
|
|
+ input.close()
|
|
|
|
|
+
|
|
|
|
|
+ decodeQrFromBitmap(bmp)?.let {
|
|
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
|
|
+ onScanResult(it)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bmp.recycle()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private fun onScanResult(result: String) {
|
|
|
|
|
+ val components = result.split("$")
|
|
|
|
|
+ if (components.size < 3 || components[0] != "LPA:1") return
|
|
|
|
|
+ profileDownloadServer.editText?.setText(components[1])
|
|
|
|
|
+ profileDownloadCode.editText?.setText(components[2])
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
override fun onCreateView(
|
|
override fun onCreateView(
|
|
|
inflater: LayoutInflater,
|
|
inflater: LayoutInflater,
|
|
|
container: ViewGroup?,
|
|
container: ViewGroup?,
|
|
@@ -103,6 +130,10 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
|
|
})
|
|
})
|
|
|
true
|
|
true
|
|
|
}
|
|
}
|
|
|
|
|
+ R.id.scan_from_gallery -> {
|
|
|
|
|
+ gallerySelectorLauncher.launch("image/*")
|
|
|
|
|
+ true
|
|
|
|
|
+ }
|
|
|
R.id.ok -> {
|
|
R.id.ok -> {
|
|
|
startDownloadProfile()
|
|
startDownloadProfile()
|
|
|
true
|
|
true
|