mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-21 18:48:54 +02:00
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:
@@ -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
|
||||
}
|
Reference in New Issue
Block a user