Compare commits
No commits in common. "b2fb3d23cb528eb0ec218ade8b4d7e98e7842089" and "3ffd847af76d0f7c3bebaec642fe51447f3d7672" have entirely different histories.
b2fb3d23cb
...
3ffd847af7
3 changed files with 20 additions and 31 deletions
|
@ -50,12 +50,22 @@ 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(true)
|
refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,8 +121,8 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun init(fromUsbEvent: Boolean = false) {
|
private suspend fun init() {
|
||||||
loadingProgress.visibility = View.VISIBLE
|
loading = true
|
||||||
viewPager.visibility = View.GONE
|
viewPager.visibility = View.GONE
|
||||||
tabs.visibility = View.GONE
|
tabs.visibility = View.GONE
|
||||||
|
|
||||||
|
@ -132,7 +142,7 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
loadingProgress.visibility = View.GONE
|
loading = false
|
||||||
|
|
||||||
knownChannels.sortedBy { it.logicalSlotId }.forEach { channel ->
|
knownChannels.sortedBy { it.logicalSlotId }.forEach { channel ->
|
||||||
pages.add(Page(
|
pages.add(Page(
|
||||||
|
@ -155,28 +165,19 @@ 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(fromUsbEvent: Boolean = false) {
|
private fun refresh() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
loadingProgress.visibility = View.VISIBLE
|
loading = true
|
||||||
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(fromUsbEvent)
|
init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,6 @@ 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
|
||||||
|
@ -70,7 +69,6 @@ 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
|
||||||
|
@ -84,7 +82,6 @@ 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)
|
||||||
|
@ -138,13 +135,14 @@ 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()
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingProgress.visibility = View.GONE
|
(requireActivity() as MainActivity).loading = false
|
||||||
|
|
||||||
usbDevice = device
|
usbDevice = device
|
||||||
usbChannel = channel
|
usbChannel = channel
|
||||||
|
|
|
@ -4,16 +4,6 @@
|
||||||
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