Compare commits

..

No commits in common. "b2fb3d23cb528eb0ec218ade8b4d7e98e7842089" and "3ffd847af76d0f7c3bebaec642fe51447f3d7672" have entirely different histories.

3 changed files with 20 additions and 31 deletions

View file

@ -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
private val usbReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
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) {
loadingProgress.visibility = View.VISIBLE
private suspend fun init() {
loading = true
viewPager.visibility = View.GONE
tabs.visibility = View.GONE
@ -132,7 +142,7 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
}
withContext(Dispatchers.Main) {
loadingProgress.visibility = View.GONE
loading = false
knownChannels.sortedBy { it.logicalSlotId }.forEach { channel ->
pages.add(Page(
@ -155,28 +165,19 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
pages.add(Page("") { appContainer.uiComponentFactory.createNoEuiccPlaceholderFragment() })
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 {
loadingProgress.visibility = View.VISIBLE
loading = true
viewPager.visibility = View.GONE
tabs.visibility = View.GONE
pages.clear()
pagerAdapter.notifyDataSetChanged()
init(fromUsbEvent)
init()
}
}
}

View file

@ -14,7 +14,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ProgressBar
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
@ -70,7 +69,6 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
private lateinit var text: TextView
private lateinit var permissionButton: Button
private lateinit var loadingProgress: ProgressBar
private var usbDevice: UsbDevice? = null
private var usbChannel: EuiccChannel? = null
@ -84,7 +82,6 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
text = view.requireViewById(R.id.usb_reader_text)
permissionButton = view.requireViewById(R.id.usb_grant_permission)
loadingProgress = view.requireViewById(R.id.loading)
permissionButton.setOnClickListener {
usbManager.requestPermission(usbDevice, usbPendingIntent)
@ -138,13 +135,14 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
private suspend fun tryLoadUsbChannel() {
text.visibility = View.GONE
permissionButton.visibility = View.GONE
loadingProgress.visibility = View.VISIBLE
(requireActivity() as MainActivity).loading = true
val (device, channel) = withContext(Dispatchers.IO) {
euiccChannelManager.enumerateUsbEuiccChannel()
}
loadingProgress.visibility = View.GONE
(requireActivity() as MainActivity).loading = false
usbDevice = device
usbChannel = channel

View file

@ -4,16 +4,6 @@
android:layout_width="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
android:id="@+id/usb_reader_text"
android:layout_width="match_parent"