From 8eadbde32328befc70b05f939834793508db6e30 Mon Sep 17 00:00:00 2001 From: TraceL Date: Thu, 13 Apr 2023 04:51:50 +0700 Subject: [PATCH] fix: add skip duplicate chapters logic to ranged downloads --- .../tachiyomi/ui/manga/MangaScreenModel.kt | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index bdb3f83f9d..2c7b6f926b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -580,8 +580,22 @@ class MangaInfoScreenModel( ) { when (action) { ChapterDownloadAction.START -> { - startDownload(items.map { it.chapter }, false) - if (items.any { it.downloadState == Download.State.ERROR }) { + val filteredItems: List = if (downloadPreferences.skipDupe().get()) { + mutableListOf().apply { + val firstChapter = items.first().chapter + for (chapterItems in items.groupBy { it.chapter.chapterNumber }.values) { + add( + chapterItems.find { it.chapter.scanlator == firstChapter.scanlator } + ?: chapterItems.first(), + ) + } + } + } else { + items + } + + startDownload(filteredItems.map { it.chapter }, false) + if (filteredItems.any { it.downloadState == Download.State.ERROR }) { downloadManager.startDownloads() } } @@ -613,14 +627,12 @@ class MangaInfoScreenModel( if (downloadPreferences.skipDupe().get()) { mutableListOf().apply { val firstChapter = validChapters.firstOrNull() ?: return - for (chapterEntry in validChapters.groupBy { it.chapterNumber }) { + for (chapters in validChapters.groupBy { it.chapterNumber }.values) { if (size == amount) break - if (any { it.chapterNumber == chapterEntry.key }) continue add( - chapterEntry.value.find { it.id == firstChapter.id } - ?: chapterEntry.value.find { it.scanlator == firstChapter.scanlator } - ?: chapterEntry.value.first(), + chapters.find { it.scanlator == firstChapter.scanlator } + ?: chapters.first(), ) } }