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:
parent
da25322572
commit
f94d902bb6
4 changed files with 87 additions and 0 deletions
|
@ -65,6 +65,7 @@ import eu.kanade.tachiyomi.ui.manga.chapterDecimalFormat
|
|||
import eu.kanade.tachiyomi.util.lang.toRelativeString
|
||||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.service.countMissingChapters
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.source.model.StubSource
|
||||
import tachiyomi.presentation.core.components.LazyColumn
|
||||
|
@ -393,6 +394,7 @@ private fun MangaScreenSmallImpl(
|
|||
ChapterHeader(
|
||||
enabled = chapters.fastAll { !it.selected },
|
||||
chapterCount = chapters.size,
|
||||
missingChapters = countMissingChapters(chapters.map { it.chapter.chapterNumber }),
|
||||
onClick = onFilterClicked,
|
||||
)
|
||||
}
|
||||
|
@ -604,6 +606,7 @@ fun MangaScreenLargeImpl(
|
|||
ChapterHeader(
|
||||
enabled = chapters.fastAll { !it.selected },
|
||||
chapterCount = chapters.size,
|
||||
missingChapters = countMissingChapters(chapters.map { it.chapter.chapterNumber }),
|
||||
onClick = onFilterButtonClicked,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import androidx.compose.foundation.clickable
|
|||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.AssistChip
|
||||
import androidx.compose.material3.AssistChipDefaults.assistChipColors
|
||||
import androidx.compose.material3.AssistChipDefaults.assistChipElevation
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
@ -11,6 +14,7 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
||||
|
@ -18,6 +22,7 @@ import eu.kanade.tachiyomi.R
|
|||
fun ChapterHeader(
|
||||
enabled: Boolean,
|
||||
chapterCount: Int?,
|
||||
missingChapters: Int?,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
|
@ -40,5 +45,42 @@ fun ChapterHeader(
|
|||
modifier = Modifier.weight(1f),
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
|
||||
// Missing chapters
|
||||
if (missingChapters == null) {
|
||||
DrawWarning(
|
||||
text = stringResource(R.string.missing_chapters_unknown),
|
||||
)
|
||||
} else if (missingChapters > 0) {
|
||||
DrawWarning(
|
||||
text = pluralStringResource(
|
||||
id = R.plurals.missing_chapters,
|
||||
count = missingChapters,
|
||||
missingChapters,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DrawWarning(text: String) {
|
||||
AssistChip(
|
||||
onClick = {
|
||||
// TODO Show missing chapters
|
||||
},
|
||||
label = {
|
||||
Text(
|
||||
text = text,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
},
|
||||
shape = MaterialTheme.shapes.small,
|
||||
border = null,
|
||||
colors = assistChipColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
),
|
||||
elevation = assistChipElevation(1.dp),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -612,6 +612,11 @@
|
|||
<string name="date">Date</string>
|
||||
|
||||
<!-- Manga info -->
|
||||
<plurals name="missing_chapters">
|
||||
<item quantity="one">Missing %1$s chapter</item>
|
||||
<item quantity="other">Missing %1$s chapters</item>
|
||||
</plurals>
|
||||
<string name="missing_chapters_unknown">Might be missing chapters</string>
|
||||
<string name="ongoing">Ongoing</string>
|
||||
<string name="unknown">Unknown</string>
|
||||
<string name="unknown_author">Unknown author</string>
|
||||
|
|
Reference in a new issue