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

This commit is contained in:
Ivan Iskandar 2021-10-03 23:00:00 +07:00 committed by GitHub
parent dc92ffed87
commit b0f87fdd21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 8 deletions

View file

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

View file

@ -1,7 +1,21 @@
<?xml version="1.0" encoding="utf-8"?> <?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" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recycler"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
tools:listitem="@layout/licenses_item" />
<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>