From d5844286b9cfc9ab8dc285473024b7e543cba025 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sun, 4 Aug 2024 23:45:11 +0800 Subject: [PATCH] Match extra layout space with scroll distance (mihonapp/mihon#1076) And increase recycler item view cache size. (cherry picked from commit a3dfd2efe6ace7a2a4d79bd09fb1a729989f1094) --- .../reader/viewer/webtoon/WebtoonLayoutManager.kt | 8 ++------ .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 15 +++++++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonLayoutManager.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonLayoutManager.kt index 852cd76e12..1948bcdf12 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonLayoutManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonLayoutManager.kt @@ -13,12 +13,7 @@ import androidx.recyclerview.widget.RecyclerView.NO_POSITION * This layout manager uses the same package name as the support library in order to use a package * protected method. */ -class WebtoonLayoutManager(context: Context) : LinearLayoutManager(context) { - - /** - * Extra layout space is set to half the screen height. - */ - private val extraLayoutSpace = context.resources.displayMetrics.heightPixels / 2 +class WebtoonLayoutManager(context: Context, private val extraLayoutSpace: Int) : LinearLayoutManager(context) { init { isItemPrefetchEnabled = false @@ -27,6 +22,7 @@ class WebtoonLayoutManager(context: Context) : LinearLayoutManager(context) { /** * Returns the custom extra layout space. */ + @Deprecated("Deprecated in Java") override fun getExtraLayoutSpace(state: RecyclerView.State): Int { return extraLayoutSpace } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 9784c38d0c..505f930116 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -57,10 +57,15 @@ class WebtoonViewer( */ private val frame = WebtoonFrame(activity) + /** + * Distance to scroll when the user taps on one side of the recycler view. + */ + private val scrollDistance = activity.resources.displayMetrics.heightPixels * 3 / 4 + /** * Layout manager of the recycler view. */ - private val layoutManager = WebtoonLayoutManager(activity) + private val layoutManager = WebtoonLayoutManager(activity, scrollDistance) /** * Configuration used by this viewer, like allow taps, or crop image borders. @@ -77,11 +82,6 @@ class WebtoonViewer( // KMK <-- ) - /** - * Distance to scroll when the user taps on one side of the recycler view. - */ - private var scrollDistance = activity.resources.displayMetrics.heightPixels * 3 / 4 - /** * Currently active item. It can be a chapter page or a chapter transition. */ @@ -95,6 +95,7 @@ class WebtoonViewer( .threshold init { + recycler.setItemViewCacheSize(RecyclerViewCacheSize) recycler.isVisible = false // Don't let the recycler layout yet recycler.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT) recycler.isFocusable = false @@ -409,3 +410,5 @@ class WebtoonViewer( ) } } + +private const val RecyclerViewCacheSize = 4