UpdatesController: Don't init adapter until chapter data is ready (#6824)

Considering there's no pagination for this list, the data loading can take some
time. So this will show the existing refresh indicator instead of empty view
while the list is loading.
This commit is contained in:
Ivan Iskandar 2022-03-26 09:20:47 +07:00 committed by GitHub
parent ef600c0956
commit ffd9c6995a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 9 deletions

View File

@ -4,8 +4,9 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
abstract class BaseChaptersAdapter<T : IFlexible<*>>(
controller: OnChapterClickListener
) : FlexibleAdapter<T>(null, controller, true) {
controller: OnChapterClickListener,
items: List<T>? = null,
) : FlexibleAdapter<T>(items, controller, true) {
/**
* Listener for browse item clicks.

View File

@ -8,8 +8,9 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
class UpdatesAdapter(
val controller: UpdatesController,
context: Context
) : BaseChaptersAdapter<IFlexible<*>>(controller) {
context: Context,
val items: List<IFlexible<*>>?
) : BaseChaptersAdapter<IFlexible<*>>(controller, items) {
var readColor = context.getResourceColor(R.attr.colorOnSurface, 0.38f)
var unreadColor = context.getResourceColor(R.attr.colorOnSurface)

View File

@ -6,6 +6,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import androidx.appcompat.view.ActionMode
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import dev.chrisbanes.insetter.applyInsetter
import eu.davidea.flexibleadapter.FlexibleAdapter
@ -88,10 +89,6 @@ class UpdatesController :
val layoutManager = LinearLayoutManager(view.context)
binding.recycler.layoutManager = layoutManager
binding.recycler.setHasFixedSize(true)
adapter = UpdatesAdapter(this@UpdatesController, view.context)
binding.recycler.adapter = adapter
adapter?.fastScroller = binding.fastScroller
binding.recycler.scrollStateChanges()
.onEach {
// Disable swipe refresh when view is not at the top
@ -100,6 +97,7 @@ class UpdatesController :
}
.launchIn(viewScope)
binding.swipeRefresh.isRefreshing = true
binding.swipeRefresh.setDistanceToTriggerSync((2 * 64 * view.resources.displayMetrics.density).toInt())
binding.swipeRefresh.refreshes()
.onEach {
@ -212,7 +210,15 @@ class UpdatesController :
*/
fun onNextRecentChapters(chapters: List<IFlexible<*>>) {
destroyActionModeIfNeeded()
adapter?.updateDataSet(chapters)
if (adapter == null) {
adapter = UpdatesAdapter(this@UpdatesController, binding.recycler.context, chapters)
binding.recycler.adapter = adapter
adapter!!.fastScroller = binding.fastScroller
} else {
adapter?.updateDataSet(chapters)
}
binding.swipeRefresh.isRefreshing = false
binding.fastScroller.isVisible = true
binding.recycler.onAnimationsFinished {
(activity as? MainActivity)?.ready = true
}

View File

@ -24,6 +24,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:visibility="gone"
app:fastScrollerBubbleEnabled="false"
tools:visibility="visible" />