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 import eu.davidea.flexibleadapter.items.IFlexible
abstract class BaseChaptersAdapter<T : IFlexible<*>>( abstract class BaseChaptersAdapter<T : IFlexible<*>>(
controller: OnChapterClickListener controller: OnChapterClickListener,
) : FlexibleAdapter<T>(null, controller, true) { items: List<T>? = null,
) : FlexibleAdapter<T>(items, controller, true) {
/** /**
* Listener for browse item clicks. * Listener for browse item clicks.

View File

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

View File

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

View File

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