Эх сурвалжийг харах

LicensesController: Move item init to IO thread (#6020)

Ivan Iskandar 3 жил өмнө
parent
commit
b0f87fdd21

+ 16 - 4
app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt

@@ -9,6 +9,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
 import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.databinding.LicensesControllerBinding
 import eu.kanade.tachiyomi.ui.base.controller.BaseController
+import eu.kanade.tachiyomi.util.lang.launchUI
+import eu.kanade.tachiyomi.util.lang.withIOContext
 import eu.kanade.tachiyomi.util.system.openInBrowser
 
 class LicensesController :
@@ -30,15 +32,25 @@ class LicensesController :
                 padding()
             }
         }
+        binding.progress.applyInsetter {
+            type(navigationBars = true) {
+                padding()
+            }
+        }
 
         binding.recycler.layoutManager = LinearLayoutManager(view.context)
         adapter = LicensesAdapter(this)
         binding.recycler.adapter = adapter
 
-        val licenseItems = Libs(view.context).libraries
-            .sortedBy { it.libraryName.lowercase() }
-            .map { LicensesItem(it) }
-        adapter?.updateDataSet(licenseItems)
+        viewScope.launchUI {
+            val licenseItems = withIOContext {
+                Libs(view.context).libraries
+                    .sortedBy { it.libraryName.lowercase() }
+                    .map { LicensesItem(it) }
+            }
+            binding.progress.hide()
+            adapter?.updateDataSet(licenseItems)
+        }
     }
 
     override fun onDestroyView(view: View) {

+ 18 - 4
app/src/main/res/layout/licenses_controller.xml

@@ -1,7 +1,21 @@
 <?xml version="1.0" encoding="utf-8"?>
-<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/recycler"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    tools:listitem="@layout/licenses_item" />
+    android:layout_height="wrap_content">
+
+    <com.google.android.material.progressindicator.CircularProgressIndicator
+        android:id="@+id/progress"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:indeterminate="true" />
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recycler"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:clipToPadding="false"
+        tools:listitem="@layout/licenses_item" />
+
+</RelativeLayout>