Added missing chapters count in MangaInfoHeader (#9184)

* Added missing chapters count in MangaInfoHeader

* Added "Might be missing chapters"

* Added missing chapters to MangaAndSourceTitlesLarge function

* Removed comments

* Reworked getMissingChapters to countMissingChapters, moved -1 check

* Attempting detecting sub-chapters

* Moved MissingChapters to ChapterHeader; Adapted design to fit in

* Fixed block comment in one-line-element

* Fixed critical missing-chapter counting bug

* Undid unintentional & unnecessary changes

* Moved & refactored countMissingChapters

* Fixed import order; Mapping chapter object to chapterNumber

* Optimized "No (valid) chapters" detection

---------

Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
Felix Kaiser
2023-03-25 03:44:58 +01:00
committed by GitHub
parent da25322572
commit f94d902bb6
4 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package tachiyomi.domain.chapter.service
import kotlin.math.floor
fun countMissingChapters(chaptersInput: List<Float>): Int? {
if (chaptersInput.isEmpty()) {
return 0
}
val chapters = chaptersInput
// Remove any invalid chapters
.filter { it != -1f }
// Convert to integers, as we cannot check if 16.5 is missing
.map { floor(it.toDouble()).toInt() }
// Only keep unique chapters so that -1 or 16 are not counted multiple times
.distinct()
.sortedBy { it }
if (chapters.isEmpty()) {
return null
}
var missingChaptersCount = 0
var previousChapter = 0 // The actual chapter number, not the array index
// We go from 0 to lastChapter - Make sure to use the current index instead of the value
for (i in chapters.indices) {
val currentChapter = chapters[i]
if (currentChapter > previousChapter + 1) {
// Add the amount of missing chapters
missingChaptersCount += currentChapter - previousChapter - 1
}
previousChapter = currentChapter
}
return missingChaptersCount
}