Compare commits
2 commits
3ffd847af7
...
b2fb3d23cb
Author | SHA1 | Date | |
---|---|---|---|
b2fb3d23cb | |||
388f15a531 |
3 changed files with 31 additions and 20 deletions
|
@ -50,22 +50,12 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var loading: Boolean
|
|
||||||
get() = loadingProgress.visibility == View.VISIBLE
|
|
||||||
set(value) {
|
|
||||||
loadingProgress.visibility = if (value) {
|
|
||||||
View.VISIBLE
|
|
||||||
} else {
|
|
||||||
View.GONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected lateinit var tm: TelephonyManager
|
protected lateinit var tm: TelephonyManager
|
||||||
|
|
||||||
private val usbReceiver = object : BroadcastReceiver() {
|
private val usbReceiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
if (intent?.action == UsbManager.ACTION_USB_DEVICE_ATTACHED || intent?.action == UsbManager.ACTION_USB_DEVICE_DETACHED) {
|
if (intent?.action == UsbManager.ACTION_USB_DEVICE_ATTACHED || intent?.action == UsbManager.ACTION_USB_DEVICE_DETACHED) {
|
||||||
refresh()
|
refresh(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,8 +111,8 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun init() {
|
private suspend fun init(fromUsbEvent: Boolean = false) {
|
||||||
loading = true
|
loadingProgress.visibility = View.VISIBLE
|
||||||
viewPager.visibility = View.GONE
|
viewPager.visibility = View.GONE
|
||||||
tabs.visibility = View.GONE
|
tabs.visibility = View.GONE
|
||||||
|
|
||||||
|
@ -142,7 +132,7 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
loading = false
|
loadingProgress.visibility = View.GONE
|
||||||
|
|
||||||
knownChannels.sortedBy { it.logicalSlotId }.forEach { channel ->
|
knownChannels.sortedBy { it.logicalSlotId }.forEach { channel ->
|
||||||
pages.add(Page(
|
pages.add(Page(
|
||||||
|
@ -165,19 +155,28 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
||||||
pages.add(Page("") { appContainer.uiComponentFactory.createNoEuiccPlaceholderFragment() })
|
pages.add(Page("") { appContainer.uiComponentFactory.createNoEuiccPlaceholderFragment() })
|
||||||
pagerAdapter.notifyDataSetChanged()
|
pagerAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fromUsbEvent && usbDevice != null) {
|
||||||
|
// If this refresh was triggered by a USB insertion while active, scroll to that page
|
||||||
|
viewPager.post {
|
||||||
|
viewPager.setCurrentItem(pages.size - 1, true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
viewPager.currentItem = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refresh() {
|
private fun refresh(fromUsbEvent: Boolean = false) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
loading = true
|
loadingProgress.visibility = View.VISIBLE
|
||||||
viewPager.visibility = View.GONE
|
viewPager.visibility = View.GONE
|
||||||
tabs.visibility = View.GONE
|
tabs.visibility = View.GONE
|
||||||
|
|
||||||
pages.clear()
|
pages.clear()
|
||||||
pagerAdapter.notifyDataSetChanged()
|
pagerAdapter.notifyDataSetChanged()
|
||||||
|
|
||||||
init()
|
init(fromUsbEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
|
import android.widget.ProgressBar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.commit
|
import androidx.fragment.app.commit
|
||||||
|
@ -69,6 +70,7 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
||||||
|
|
||||||
private lateinit var text: TextView
|
private lateinit var text: TextView
|
||||||
private lateinit var permissionButton: Button
|
private lateinit var permissionButton: Button
|
||||||
|
private lateinit var loadingProgress: ProgressBar
|
||||||
|
|
||||||
private var usbDevice: UsbDevice? = null
|
private var usbDevice: UsbDevice? = null
|
||||||
private var usbChannel: EuiccChannel? = null
|
private var usbChannel: EuiccChannel? = null
|
||||||
|
@ -82,6 +84,7 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
||||||
|
|
||||||
text = view.requireViewById(R.id.usb_reader_text)
|
text = view.requireViewById(R.id.usb_reader_text)
|
||||||
permissionButton = view.requireViewById(R.id.usb_grant_permission)
|
permissionButton = view.requireViewById(R.id.usb_grant_permission)
|
||||||
|
loadingProgress = view.requireViewById(R.id.loading)
|
||||||
|
|
||||||
permissionButton.setOnClickListener {
|
permissionButton.setOnClickListener {
|
||||||
usbManager.requestPermission(usbDevice, usbPendingIntent)
|
usbManager.requestPermission(usbDevice, usbPendingIntent)
|
||||||
|
@ -135,14 +138,13 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
||||||
private suspend fun tryLoadUsbChannel() {
|
private suspend fun tryLoadUsbChannel() {
|
||||||
text.visibility = View.GONE
|
text.visibility = View.GONE
|
||||||
permissionButton.visibility = View.GONE
|
permissionButton.visibility = View.GONE
|
||||||
|
loadingProgress.visibility = View.VISIBLE
|
||||||
(requireActivity() as MainActivity).loading = true
|
|
||||||
|
|
||||||
val (device, channel) = withContext(Dispatchers.IO) {
|
val (device, channel) = withContext(Dispatchers.IO) {
|
||||||
euiccChannelManager.enumerateUsbEuiccChannel()
|
euiccChannelManager.enumerateUsbEuiccChannel()
|
||||||
}
|
}
|
||||||
|
|
||||||
(requireActivity() as MainActivity).loading = false
|
loadingProgress.visibility = View.GONE
|
||||||
|
|
||||||
usbDevice = device
|
usbDevice = device
|
||||||
usbChannel = channel
|
usbChannel = channel
|
||||||
|
|
|
@ -4,6 +4,16 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/loading"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/usb_reader_text"
|
android:id="@+id/usb_reader_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
Loading…
Add table
Reference in a new issue