From 221bb58c8c113bce8924c709cc2c3760e739bddd Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Thu, 22 Apr 2021 20:39:38 -0400 Subject: [PATCH] Fix loop when using skip chapter transition With this change the transition page now goes away. after loading. I imagine those who don't want to see this page would like this change anyway --- .../ui/reader/viewer/pager/PagerViewerAdapter.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt index 48db3b320f..7f26c85fc3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt @@ -35,6 +35,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { private var doubledUp = viewer.config.doublePages var currentChapter: ReaderChapter? = null + var forceTransition = false /** * Updates this adapter with the given [chapters]. It handles setting a few pages of the @@ -44,6 +45,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { fun setChapters(chapters: ViewerChapters, forceTransition: Boolean) { val newItems = mutableListOf() + this.forceTransition = forceTransition // Add previous chapter pages and transition. if (chapters.prevChapter != null) { // We only need to add the last few pages of the previous chapter, because it'll be @@ -277,7 +279,19 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { useSecondPage -> (oldCurrent?.second ?: oldCurrent?.first) else -> oldCurrent?.first ?: return } - val index = joinedItems.indexOfFirst { it.first == newPage || it.second == newPage } + var index = joinedItems.indexOfFirst { it.first == newPage || it.second == newPage } + if (newPage is ChapterTransition && index == -1 && !forceTransition) { + val newerPage = if (newPage is ChapterTransition.Next) { + joinedItems.filter { + (it.first as? ReaderPage)?.chapter == newPage.to + }.minByOrNull { (it.first as? ReaderPage)?.index ?: Int.MAX_VALUE }?.first + } else { + joinedItems.filter { + (it.first as? ReaderPage)?.chapter == newPage.to + }.maxByOrNull { (it.first as? ReaderPage)?.index ?: Int.MIN_VALUE }?.first + } + index = joinedItems.indexOfFirst { it.first == newerPage || it.second == newerPage } + } viewer.pager.setCurrentItem(index, false) } }