From ffd9c6995a0ca376e72ca8271ff673b3477a6e78 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 26 Mar 2022 09:20:47 +0700 Subject: [PATCH] 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. --- .../ui/manga/chapter/base/BaseChaptersAdapter.kt | 5 +++-- .../ui/recent/updates/UpdatesAdapter.kt | 5 +++-- .../ui/recent/updates/UpdatesController.kt | 16 +++++++++++----- app/src/main/res/layout/updates_controller.xml | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/base/BaseChaptersAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/base/BaseChaptersAdapter.kt index a4f7300ac..826ab2a05 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/base/BaseChaptersAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/base/BaseChaptersAdapter.kt @@ -4,8 +4,9 @@ import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible abstract class BaseChaptersAdapter>( - controller: OnChapterClickListener -) : FlexibleAdapter(null, controller, true) { + controller: OnChapterClickListener, + items: List? = null, +) : FlexibleAdapter(items, controller, true) { /** * Listener for browse item clicks. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesAdapter.kt index 639b6bac3..70b131225 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesAdapter.kt @@ -8,8 +8,9 @@ import eu.kanade.tachiyomi.util.system.getResourceColor class UpdatesAdapter( val controller: UpdatesController, - context: Context -) : BaseChaptersAdapter>(controller) { + context: Context, + val items: List>? +) : BaseChaptersAdapter>(controller, items) { var readColor = context.getResourceColor(R.attr.colorOnSurface, 0.38f) var unreadColor = context.getResourceColor(R.attr.colorOnSurface) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 4b95af529..c2aedebe6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -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>) { 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 } diff --git a/app/src/main/res/layout/updates_controller.xml b/app/src/main/res/layout/updates_controller.xml index 8982a067c..ab95c93e9 100644 --- a/app/src/main/res/layout/updates_controller.xml +++ b/app/src/main/res/layout/updates_controller.xml @@ -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" />