From 34930920a50be25ca05024200bf871512962e3d0 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Fri, 22 Mar 2024 20:56:48 +0800 Subject: [PATCH] Fix webtoon last visible item position calculation (#562) Covers the case when image height > screen height. --- .../viewer/webtoon/WebtoonLayoutManager.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 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 cb9f484a4..852cd76e1 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 @@ -36,20 +36,21 @@ class WebtoonLayoutManager(context: Context) : LinearLayoutManager(context) { */ fun findLastEndVisibleItemPosition(): Int { ensureLayoutState() - @ViewBoundsCheck.ViewBounds val preferredBoundsFlag = - (ViewBoundsCheck.FLAG_CVE_LT_PVE or ViewBoundsCheck.FLAG_CVE_EQ_PVE) - - val fromIndex = childCount - 1 - val toIndex = -1 - - val child = if (mOrientation == HORIZONTAL) { + val callback = if (mOrientation == HORIZONTAL) { mHorizontalBoundCheck - .findOneViewWithinBoundFlags(fromIndex, toIndex, preferredBoundsFlag, 0) } else { mVerticalBoundCheck - .findOneViewWithinBoundFlags(fromIndex, toIndex, preferredBoundsFlag, 0) + }.mCallback + val start = callback.parentStart + val end = callback.parentEnd + for (i in childCount - 1 downTo 0) { + val child = getChildAt(i)!! + val childStart = callback.getChildStart(child) + val childEnd = callback.getChildEnd(child) + if (childEnd <= end || childStart < start) { + return getPosition(child) + } } - - return if (child == null) NO_POSITION else getPosition(child) + return NO_POSITION } }