Browse Source

[1/n] Remove dependency on databinding

This is not going to work with AOSP
master
Peter Cai 1 week ago
parent
commit
83fc7ac7ab
  1. 9
      app/src/main/java/im/angry/openeuicc/ui/MainActivity.kt
  2. 42
      app/src/main/java/im/angry/openeuicc/ui/ProfileDownloadFragment.kt

9
app/src/main/java/im/angry/openeuicc/ui/MainActivity.kt

@ -14,7 +14,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import im.angry.openeuicc.R
import im.angry.openeuicc.core.EuiccChannelManager
import im.angry.openeuicc.databinding.ActivityMainBinding
import im.angry.openeuicc.util.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -32,14 +31,14 @@ class MainActivity : AppCompatActivity() {
private val fragments = arrayListOf<EuiccManagementFragment>()
private lateinit var binding: ActivityMainBinding
private lateinit var noEuiccPlaceholder: View
private lateinit var tm: TelephonyManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setContentView(R.layout.activity_main)
noEuiccPlaceholder = findViewById(R.id.no_euicc_placeholder)
tm = openEuiccApplication.telephonyManager
@ -108,7 +107,7 @@ class MainActivity : AppCompatActivity() {
}
if (fragments.isNotEmpty()) {
binding.noEuiccPlaceholder.visibility = View.GONE
noEuiccPlaceholder.visibility = View.GONE
supportFragmentManager.beginTransaction().replace(R.id.fragment_root, fragments.first()).commit()
}
}

42
app/src/main/java/im/angry/openeuicc/ui/ProfileDownloadFragment.kt

@ -4,15 +4,16 @@ import android.app.Dialog
import android.os.Bundle
import android.util.Log
import android.view.*
import android.widget.ProgressBar
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import com.google.android.material.textfield.TextInputLayout
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
import com.truphone.lpa.progress.DownloadProgress
import im.angry.openeuicc.R
import im.angry.openeuicc.databinding.FragmentProfileDownloadBinding
import im.angry.openeuicc.util.setWidthPercent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -27,8 +28,10 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
newInstanceEuicc(ProfileDownloadFragment::class.java, slotId)
}
private var _binding: FragmentProfileDownloadBinding? = null
private val binding get() = _binding!!
private lateinit var toolbar: Toolbar
private lateinit var profileDownloadServer: TextInputLayout
private lateinit var profileDownloadCode: TextInputLayout
private lateinit var progress: ProgressBar
private var downloading = false
@ -37,8 +40,8 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
Log.d(TAG, 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])
profileDownloadServer.editText?.setText(components[1])
profileDownloadCode.editText?.setText(components[2])
}
}
@ -47,14 +50,19 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentProfileDownloadBinding.inflate(inflater, container, false)
binding.toolbar.inflateMenu(R.menu.fragment_profile_download)
return binding.root
val view = inflater.inflate(R.layout.fragment_profile_download, container, false)
toolbar = view.findViewById(R.id.toolbar)
profileDownloadServer = view.findViewById(R.id.profile_download_server)
profileDownloadCode = view.findViewById(R.id.profile_download_code)
progress = view.findViewById(R.id.progress)
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.toolbar.apply {
toolbar.apply {
setTitle(R.string.profile_download)
setNavigationOnClickListener {
if (!downloading) dismiss()
@ -92,7 +100,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
}
private fun startDownloadProfile() {
val server = binding.profileDownloadServer.editText!!.let {
val server = profileDownloadServer.editText!!.let {
it.text.toString().trim().apply {
if (isEmpty()) {
it.requestFocus()
@ -101,15 +109,15 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
}
}
val code = binding.profileDownloadCode.editText!!.text.toString().trim()
val code = profileDownloadCode.editText!!.text.toString().trim()
downloading = true
binding.profileDownloadServer.editText!!.isEnabled = false
binding.profileDownloadCode.editText!!.isEnabled = false
profileDownloadServer.editText!!.isEnabled = false
profileDownloadCode.editText!!.isEnabled = false
binding.progress.isIndeterminate = true
binding.progress.visibility = View.VISIBLE
progress.isIndeterminate = true
progress.visibility = View.VISIBLE
lifecycleScope.launch {
try {
@ -130,8 +138,8 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
private suspend fun doDownloadProfile(server: String, code: String) = withContext(Dispatchers.IO) {
channel.lpa.downloadProfile("1\$${server}\$${code}", channel.imei, DownloadProgress().apply {
setProgressListener { _, _, percentage, _ ->
binding.progress.isIndeterminate = false
binding.progress.progress = (percentage * 100).toInt()
progress.isIndeterminate = false
progress.progress = (percentage * 100).toInt()
}
})
}

Loading…
Cancel
Save