From 9f260c351352817f2cceed6323c5ebcceca5e2e9 Mon Sep 17 00:00:00 2001 From: Andreas E Date: Mon, 7 Sep 2020 22:40:05 +0200 Subject: [PATCH] Always show missing chapter warning if there are missing chapters (#3755) * Always show missing chapter warning if there are missing chapters * Change function parameter names --- .../tachiyomi/ui/reader/viewer/MissingChapters.kt | 15 +++++++++++++++ .../ui/reader/viewer/ReaderTransitionView.kt | 5 ++++- .../ui/reader/viewer/pager/PagerViewerAdapter.kt | 9 +++++++-- .../ui/reader/viewer/webtoon/WebtoonAdapter.kt | 9 +++++++-- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/MissingChapters.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/MissingChapters.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/MissingChapters.kt new file mode 100644 index 0000000000..4ee2543eac --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/MissingChapters.kt @@ -0,0 +1,15 @@ +package eu.kanade.tachiyomi.ui.reader.viewer + +import eu.kanade.tachiyomi.data.database.models.Chapter +import kotlin.math.floor + +object MissingChapters { + + fun hasMissingChapters(higher: Chapter, lower: Chapter): Boolean { + return hasMissingChapters(higher.chapter_number, lower.chapter_number) + } + + fun hasMissingChapters(higherChapterNumber: Float, lowerChapterNumber: Float): Boolean { + return floor(higherChapterNumber) - floor(lowerChapterNumber) - 1f > 0f + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderTransitionView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderTransitionView.kt index 5333d551a7..5d442dd223 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderTransitionView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderTransitionView.kt @@ -92,7 +92,10 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At is ChapterTransition.Next -> toChapterNumber - fromChapterNumber - 1f } - val hasMissingChapters = chapterDifference > 0f + val hasMissingChapters = when (transition) { + is ChapterTransition.Prev -> MissingChapters.hasMissingChapters(fromChapterNumber, toChapterNumber) + is ChapterTransition.Next -> MissingChapters.hasMissingChapters(toChapterNumber, fromChapterNumber) + } warning_text.text = resources.getQuantityString(R.plurals.missing_chapters_warning, chapterDifference.toInt(), chapterDifference.toInt()) warning.isVisible = hasMissingChapters 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 720171e4e7..fe2244cfbd 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 @@ -6,6 +6,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters +import eu.kanade.tachiyomi.ui.reader.viewer.MissingChapters import eu.kanade.tachiyomi.widget.ViewPagerAdapter import timber.log.Timber @@ -33,6 +34,10 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { fun setChapters(chapters: ViewerChapters, forceTransition: Boolean) { val newItems = mutableListOf() + // Forces chapter transition if there is missing chapters + val prevHasMissingChapters = if (chapters.prevChapter != null) MissingChapters.hasMissingChapters(chapters.currChapter.chapter, chapters.prevChapter.chapter) else false + val nextHasMissingChapters = if (chapters.nextChapter != null) MissingChapters.hasMissingChapters(chapters.nextChapter.chapter, chapters.currChapter.chapter) else false + // 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 @@ -44,7 +49,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { } // Skip transition page if the chapter is loaded & current page is not a transition page - if (forceTransition || chapters.prevChapter?.state !is ReaderChapter.State.Loaded) { + if (prevHasMissingChapters || forceTransition || chapters.prevChapter?.state !is ReaderChapter.State.Loaded) { newItems.add(ChapterTransition.Prev(chapters.currChapter, chapters.prevChapter)) } @@ -59,7 +64,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { // Add next chapter transition and pages. nextTransition = ChapterTransition.Next(chapters.currChapter, chapters.nextChapter) .also { - if (forceTransition || + if (nextHasMissingChapters || forceTransition || chapters.nextChapter?.state !is ReaderChapter.State.Loaded ) { newItems.add(it) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt index 92cb5192c7..0aa19a2f1f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt @@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters +import eu.kanade.tachiyomi.ui.reader.viewer.MissingChapters /** * RecyclerView Adapter used by this [viewer] to where [ViewerChapters] updates are posted. @@ -29,6 +30,10 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter() + // Forces chapter transition if there is missing chapters + val prevHasMissingChapters = if (chapters.prevChapter != null) MissingChapters.hasMissingChapters(chapters.currChapter.chapter, chapters.prevChapter.chapter) else false + val nextHasMissingChapters = if (chapters.nextChapter != null) MissingChapters.hasMissingChapters(chapters.nextChapter.chapter, chapters.currChapter.chapter) else false + // 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 @@ -40,7 +45,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter