fix: skip duplicate chapters on download ahead if option to skip duplicates is enabled (#9334)
* fix: skip duplicate chapters on download ahead if option is enabled * fix: Use a function to filter duplicates
This commit is contained in:
parent
60d8650860
commit
4816b4b53a
2 changed files with 25 additions and 8 deletions
|
@ -35,6 +35,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
|
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
|
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
|
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
|
||||||
|
import eu.kanade.tachiyomi.util.chapter.removeDuplicates
|
||||||
import eu.kanade.tachiyomi.util.editCover
|
import eu.kanade.tachiyomi.util.editCover
|
||||||
import eu.kanade.tachiyomi.util.lang.byteSize
|
import eu.kanade.tachiyomi.util.lang.byteSize
|
||||||
import eu.kanade.tachiyomi.util.lang.takeBytes
|
import eu.kanade.tachiyomi.util.lang.takeBytes
|
||||||
|
@ -175,12 +176,7 @@ class ReaderViewModel(
|
||||||
else -> chapters
|
else -> chapters
|
||||||
}.run {
|
}.run {
|
||||||
if (readerPreferences.skipDupe().get()) {
|
if (readerPreferences.skipDupe().get()) {
|
||||||
groupBy { it.chapterNumber }
|
removeDuplicates(selectedChapter)
|
||||||
.map { (_, chapters) ->
|
|
||||||
chapters.find { it.id == selectedChapter.id }
|
|
||||||
?: chapters.find { it.scanlator == selectedChapter.scanlator }
|
|
||||||
?: chapters.first()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
@ -456,8 +452,14 @@ class ReaderViewModel(
|
||||||
)
|
)
|
||||||
if (!isNextChapterDownloaded) return@launchIO
|
if (!isNextChapterDownloaded) return@launchIO
|
||||||
|
|
||||||
val chaptersToDownload = getNextChapters.await(manga.id, nextChapter.id!!)
|
val chaptersToDownload = getNextChapters.await(manga.id, nextChapter.id!!).run {
|
||||||
.take(amount)
|
if (readerPreferences.skipDupe().get()) {
|
||||||
|
removeDuplicates(nextChapter.toDomainChapter()!!)
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
}.take(amount)
|
||||||
|
|
||||||
downloadManager.downloadChapters(
|
downloadManager.downloadChapters(
|
||||||
manga,
|
manga,
|
||||||
chaptersToDownload,
|
chaptersToDownload,
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package eu.kanade.tachiyomi.util.chapter
|
||||||
|
|
||||||
|
import tachiyomi.domain.chapter.model.Chapter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a copy of the list with duplicate chapters removed
|
||||||
|
*/
|
||||||
|
fun List<Chapter>.removeDuplicates(currentChapter: Chapter): List<Chapter> {
|
||||||
|
return groupBy { it.chapterNumber }
|
||||||
|
.map { (_, chapters) ->
|
||||||
|
chapters.find { it.id == currentChapter.id }
|
||||||
|
?: chapters.find { it.scanlator == currentChapter.scanlator }
|
||||||
|
?: chapters.first()
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue