From a2b21e5ad6fffea279e096250a0daa8a24a27955 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sun, 16 Oct 2022 00:22:58 +0600 Subject: [PATCH] Retain bookmark of readded chapters (#8205) * Retain bookmark of readded chapters * Fix typo --- .../interactor/SyncChaptersWithSource.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt index 02076a436c..a7d4f35322 100644 --- a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt +++ b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt @@ -136,11 +136,11 @@ class SyncChaptersWithSource( val deletedChapterNumbers = TreeSet() val deletedReadChapterNumbers = TreeSet() + val deletedBookmarkedChapterNumbers = TreeSet() toDelete.forEach { chapter -> - if (chapter.read) { - deletedReadChapterNumbers.add(chapter.chapterNumber) - } + if (chapter.read) deletedReadChapterNumbers.add(chapter.chapterNumber) + if (chapter.bookmark) deletedBookmarkedChapterNumbers.add(chapter.chapterNumber) deletedChapterNumbers.add(chapter.chapterNumber) } @@ -149,20 +149,19 @@ class SyncChaptersWithSource( // Date fetch is set in such a way that the upper ones will have bigger value than the lower ones // Sources MUST return the chapters from most to less recent, which is common. - var itemCount = toAdd.size var updatedToAdd = toAdd.map { toAddItem -> var chapter = toAddItem.copy(dateFetch = rightNow + itemCount--) if (chapter.isRecognizedNumber.not() || chapter.chapterNumber !in deletedChapterNumbers) return@map chapter - if (chapter.chapterNumber in deletedReadChapterNumbers) { - chapter = chapter.copy(read = true) - } + chapter = chapter.copy( + read = chapter.chapterNumber in deletedReadChapterNumbers, + bookmark = chapter.chapterNumber in deletedBookmarkedChapterNumbers, + ) // Try to to use the fetch date of the original entry to not pollute 'Updates' tab - val oldDateFetch = deletedChapterNumberDateFetchMap[chapter.chapterNumber] - oldDateFetch?.let { + deletedChapterNumberDateFetchMap[chapter.chapterNumber]?.let { chapter = chapter.copy(dateFetch = it) }