mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 08:37:48 +01:00
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
This commit is contained in:
parent
b55d394a1f
commit
9f260c3513
4 changed files with 33 additions and 5 deletions
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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<Any>()
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -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<RecyclerV
|
|||
fun setChapters(chapters: ViewerChapters, forceTransition: Boolean) {
|
||||
val newItems = mutableListOf<Any>()
|
||||
|
||||
// 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<RecyclerV
|
|||
}
|
||||
|
||||
// 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))
|
||||
}
|
||||
|
||||
|
@ -53,7 +58,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
|
|||
currentChapter = chapters.currChapter
|
||||
|
||||
// Add next chapter transition and pages.
|
||||
if (forceTransition || chapters.nextChapter?.state !is ReaderChapter.State.Loaded) {
|
||||
if (nextHasMissingChapters || forceTransition || chapters.nextChapter?.state !is ReaderChapter.State.Loaded) {
|
||||
newItems.add(ChapterTransition.Next(chapters.currChapter, chapters.nextChapter))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue