fix for downloading when all chapters are read

This commit is contained in:
Finnley Somdahl 2023-12-27 06:34:09 -06:00
parent d177087ae6
commit c352222e3a

View file

@ -196,26 +196,27 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
override fun onScanlatorsSelected() { override fun onScanlatorsSelected() {
updateChapters() updateChapters()
} }
fun multiDownload(n: Int) { fun multiDownload(n: Int) {
//get last viewed chapter //get last viewed chapter
val selected = media.userProgress val selected = media.userProgress
val chapters = media.manga?.chapters?.values?.toList() val chapters = media.manga?.chapters?.values?.toList()
//filter by selected language //filter by selected language
val progressChapterIndex = chapters?.indexOfFirst { MangaNameAdapter.findChapterNumber(it.number)?.toInt() == selected }?:0 val progressChapterIndex = chapters?.indexOfFirst { MangaNameAdapter.findChapterNumber(it.number)?.toInt() == selected } ?: 0
if (progressChapterIndex < 0 || n < 1) return
val chaptersToDownload = chapters?.subList(
progressChapterIndex + 1,
progressChapterIndex + n + 1
)
if (chaptersToDownload != null) {
for (chapter in chaptersToDownload) {
onMangaChapterDownloadClick(chapter.title!!)
}
}
if (progressChapterIndex < 0 || n < 1 || chapters == null) return
// Calculate the end index
val endIndex = minOf(progressChapterIndex + n, chapters.size)
//make sure there are enough chapters
val chaptersToDownload = chapters.subList(progressChapterIndex + 1, endIndex)
for (chapter in chaptersToDownload) {
onMangaChapterDownloadClick(chapter.title!!)
}
} }
private fun updateChapters() { private fun updateChapters() {
val loadedChapters = model.getMangaChapters().value val loadedChapters = model.getMangaChapters().value
if (loadedChapters != null) { if (loadedChapters != null) {