mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-19 23:22:26 -07:00
Delete downloads of duplicates read along with a chapter (#3030)
Closes #3030 Fixes #2454 Co-authored-by: Leodyver Semilla <leodyversemilla07@gmail.com>
This commit is contained in:
co-authored by
Leodyver Semilla
parent
0c1be369b0
commit
36ec043a5c
@@ -77,6 +77,7 @@ import tachiyomi.core.common.util.lang.withUIContext
|
||||
import tachiyomi.core.common.util.system.logcat
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.model.ChapterUpdate
|
||||
import tachiyomi.domain.chapter.service.getChapterSort
|
||||
import tachiyomi.domain.download.service.DownloadPreferences
|
||||
@@ -564,9 +565,23 @@ class ReaderViewModel(
|
||||
// If chapter is completely read, no need to download it
|
||||
chapterToDownload = null
|
||||
|
||||
if (chapterToDelete != null) {
|
||||
enqueueDeleteReadChapters(chapterToDelete)
|
||||
if (chapterToDelete == null || !chapterToDelete.chapter.read) return
|
||||
|
||||
val markDuplicateAsRead = libraryPreferences.markDuplicateReadChapterAsRead.get()
|
||||
.contains(LibraryPreferences.MARK_DUPLICATE_CHAPTER_READ_EXISTING)
|
||||
val duplicateChapters = if (markDuplicateAsRead) {
|
||||
unfilteredChapterList
|
||||
.filter {
|
||||
it.id != chapterToDelete.chapter.id &&
|
||||
it.isRecognizedNumber &&
|
||||
it.chapterNumber.toFloat() == chapterToDelete.chapter.chapter_number
|
||||
}
|
||||
// The list is loaded once, before these were marked read along with chapterToDelete
|
||||
.map { it.copy(read = true) }
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
enqueueDeleteChapters(listOf(chapterToDelete.chapter.toDomainChapter()!!) + duplicateChapters)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -959,15 +974,14 @@ class ReaderViewModel(
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues this [chapter] to be deleted when [deletePendingChapters] is called. The download
|
||||
* manager handles persisting it across process deaths.
|
||||
* Enqueues these [chapters] to be deleted when [deletePendingChapters] is called. The download
|
||||
* manager handles persisting them across process deaths.
|
||||
*/
|
||||
private fun enqueueDeleteReadChapters(chapter: ReaderChapter) {
|
||||
if (!chapter.chapter.read) return
|
||||
private fun enqueueDeleteChapters(chapters: List<Chapter>) {
|
||||
val manga = manga ?: return
|
||||
|
||||
viewModelScope.launchNonCancellable {
|
||||
downloadManager.enqueueChaptersToDelete(listOf(chapter.chapter.toDomainChapter()!!), manga)
|
||||
downloadManager.enqueueChaptersToDelete(chapters, manga)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user