Retain bookmark of readded chapters (#8205)

* Retain bookmark of readded chapters

* Fix typo
This commit is contained in:
AntsyLich 2022-10-16 00:22:58 +06:00 committed by GitHub
parent dbd93cf5d1
commit a2b21e5ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,11 +136,11 @@ class SyncChaptersWithSource(
val deletedChapterNumbers = TreeSet<Float>() val deletedChapterNumbers = TreeSet<Float>()
val deletedReadChapterNumbers = TreeSet<Float>() val deletedReadChapterNumbers = TreeSet<Float>()
val deletedBookmarkedChapterNumbers = TreeSet<Float>()
toDelete.forEach { chapter -> toDelete.forEach { chapter ->
if (chapter.read) { if (chapter.read) deletedReadChapterNumbers.add(chapter.chapterNumber)
deletedReadChapterNumbers.add(chapter.chapterNumber) if (chapter.bookmark) deletedBookmarkedChapterNumbers.add(chapter.chapterNumber)
}
deletedChapterNumbers.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 // 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. // Sources MUST return the chapters from most to less recent, which is common.
var itemCount = toAdd.size var itemCount = toAdd.size
var updatedToAdd = toAdd.map { toAddItem -> var updatedToAdd = toAdd.map { toAddItem ->
var chapter = toAddItem.copy(dateFetch = rightNow + itemCount--) var chapter = toAddItem.copy(dateFetch = rightNow + itemCount--)
if (chapter.isRecognizedNumber.not() || chapter.chapterNumber !in deletedChapterNumbers) return@map chapter if (chapter.isRecognizedNumber.not() || chapter.chapterNumber !in deletedChapterNumbers) return@map chapter
if (chapter.chapterNumber in deletedReadChapterNumbers) { chapter = chapter.copy(
chapter = chapter.copy(read = true) 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 // Try to to use the fetch date of the original entry to not pollute 'Updates' tab
val oldDateFetch = deletedChapterNumberDateFetchMap[chapter.chapterNumber] deletedChapterNumberDateFetchMap[chapter.chapterNumber]?.let {
oldDateFetch?.let {
chapter = chapter.copy(dateFetch = it) chapter = chapter.copy(dateFetch = it)
} }