|
@@ -2,17 +2,17 @@ package im.angry.openeuicc.ui
|
|
|
|
|
|
|
|
import android.app.Dialog
|
|
import android.app.Dialog
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
-import android.view.LayoutInflater
|
|
|
|
|
-import android.view.View
|
|
|
|
|
-import android.view.ViewGroup
|
|
|
|
|
-import android.view.Window
|
|
|
|
|
|
|
+import android.view.*
|
|
|
|
|
+import androidx.appcompat.widget.Toolbar
|
|
|
import androidx.fragment.app.DialogFragment
|
|
import androidx.fragment.app.DialogFragment
|
|
|
|
|
+import com.journeyapps.barcodescanner.ScanContract
|
|
|
|
|
+import com.journeyapps.barcodescanner.ScanOptions
|
|
|
import im.angry.openeuicc.R
|
|
import im.angry.openeuicc.R
|
|
|
import im.angry.openeuicc.core.EuiccChannel
|
|
import im.angry.openeuicc.core.EuiccChannel
|
|
|
import im.angry.openeuicc.databinding.FragmentProfileDownloadBinding
|
|
import im.angry.openeuicc.databinding.FragmentProfileDownloadBinding
|
|
|
import im.angry.openeuicc.util.setWidthPercent
|
|
import im.angry.openeuicc.util.setWidthPercent
|
|
|
|
|
|
|
|
-class ProfileDownloadFragment(val channel: EuiccChannel) : DialogFragment() {
|
|
|
|
|
|
|
+class ProfileDownloadFragment(val channel: EuiccChannel) : DialogFragment(), Toolbar.OnMenuItemClickListener {
|
|
|
companion object {
|
|
companion object {
|
|
|
const val TAG = "ProfileDownloadFragment"
|
|
const val TAG = "ProfileDownloadFragment"
|
|
|
}
|
|
}
|
|
@@ -20,12 +20,22 @@ class ProfileDownloadFragment(val channel: EuiccChannel) : DialogFragment() {
|
|
|
private var _binding: FragmentProfileDownloadBinding? = null
|
|
private var _binding: FragmentProfileDownloadBinding? = null
|
|
|
private val binding get() = _binding!!
|
|
private val binding get() = _binding!!
|
|
|
|
|
|
|
|
|
|
+ private val barcodeScannerLauncher = registerForActivityResult(ScanContract()) { result ->
|
|
|
|
|
+ result.contents?.let { content ->
|
|
|
|
|
+ val components = content.split("$")
|
|
|
|
|
+ if (components.size != 3 || components[0] != "LPA:1") return@registerForActivityResult
|
|
|
|
|
+ binding.profileDownloadServer.editText?.setText(components[1])
|
|
|
|
|
+ binding.profileDownloadCode.editText?.setText(components[2])
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
override fun onCreateView(
|
|
override fun onCreateView(
|
|
|
inflater: LayoutInflater,
|
|
inflater: LayoutInflater,
|
|
|
container: ViewGroup?,
|
|
container: ViewGroup?,
|
|
|
savedInstanceState: Bundle?
|
|
savedInstanceState: Bundle?
|
|
|
): View {
|
|
): View {
|
|
|
_binding = FragmentProfileDownloadBinding.inflate(inflater, container, false)
|
|
_binding = FragmentProfileDownloadBinding.inflate(inflater, container, false)
|
|
|
|
|
+ binding.toolbar.inflateMenu(R.menu.fragment_profile_download)
|
|
|
return binding.root
|
|
return binding.root
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -36,9 +46,22 @@ class ProfileDownloadFragment(val channel: EuiccChannel) : DialogFragment() {
|
|
|
setNavigationOnClickListener {
|
|
setNavigationOnClickListener {
|
|
|
dismiss()
|
|
dismiss()
|
|
|
}
|
|
}
|
|
|
|
|
+ setOnMenuItemClickListener(this@ProfileDownloadFragment)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ override fun onMenuItemClick(item: MenuItem): Boolean =
|
|
|
|
|
+ when (item.itemId) {
|
|
|
|
|
+ R.id.scan -> {
|
|
|
|
|
+ barcodeScannerLauncher.launch(ScanOptions().apply {
|
|
|
|
|
+ setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
|
|
|
|
+ setOrientationLocked(false)
|
|
|
|
|
+ })
|
|
|
|
|
+ true
|
|
|
|
|
+ }
|
|
|
|
|
+ else -> false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
override fun onResume() {
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
super.onResume()
|
|
|
setWidthPercent(95)
|
|
setWidthPercent(95)
|