ソースを参照

ui: Remove more blocking operations in NotificationsActivity

Peter Cai 1 年間 前
コミット
16b6aceedf

+ 14 - 4
app-common/src/main/java/im/angry/openeuicc/ui/NotificationsActivity.kt

@@ -50,16 +50,14 @@ class NotificationsActivity: BaseEuiccAccessActivity(), OpenEuiccContextMarker {
     }
 
     override fun onInit() {
-        val logicalSlotId = intent.getIntExtra("logicalSlotId", 0)
-        euiccChannel = euiccChannelManager
-            .findEuiccChannelBySlotBlocking(logicalSlotId)!!
-
         notificationList.layoutManager =
             LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
         notificationList.addItemDecoration(DividerItemDecoration(this, LinearLayoutManager.VERTICAL))
         notificationList.adapter = notificationAdapter
         registerForContextMenu(notificationList)
 
+        val logicalSlotId = intent.getIntExtra("logicalSlotId", 0)
+
         // This is slightly different from the MainActivity logic
         // due to the length (we don't want to display the full USB product name)
         val channelTitle = if (logicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
@@ -106,6 +104,18 @@ class NotificationsActivity: BaseEuiccAccessActivity(), OpenEuiccContextMarker {
         swipeRefresh.isRefreshing = true
 
         lifecycleScope.launch {
+            if (!this@NotificationsActivity::euiccChannel.isInitialized) {
+                withContext(Dispatchers.IO) {
+                    euiccChannelManagerLoaded.await()
+                    euiccChannel = euiccChannelManager.findEuiccChannelBySlotBlocking(
+                        intent.getIntExtra(
+                            "logicalSlotId",
+                            0
+                        )
+                    )!!
+                }
+            }
+
             task()
 
             swipeRefresh.isRefreshing = false