mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Add option to mark new duplicate read chapters as read (#1785)
This commit is contained in:
		| @@ -153,7 +153,7 @@ class DomainModule : InjektModule { | ||||
|         addFactory { UpdateChapter(get()) } | ||||
|         addFactory { SetReadStatus(get(), get(), get(), get()) } | ||||
|         addFactory { ShouldUpdateDbChapter() } | ||||
|         addFactory { SyncChaptersWithSource(get(), get(), get(), get(), get(), get(), get(), get()) } | ||||
|         addFactory { SyncChaptersWithSource(get(), get(), get(), get(), get(), get(), get(), get(), get()) } | ||||
|         addFactory { GetAvailableScanlators(get()) } | ||||
|         addFactory { FilterChaptersForDownload(get(), get(), get()) } | ||||
|  | ||||
|   | ||||
| @@ -19,6 +19,7 @@ import tachiyomi.domain.chapter.model.NoChaptersException | ||||
| import tachiyomi.domain.chapter.model.toChapterUpdate | ||||
| import tachiyomi.domain.chapter.repository.ChapterRepository | ||||
| import tachiyomi.domain.chapter.service.ChapterRecognition | ||||
| import tachiyomi.domain.library.service.LibraryPreferences | ||||
| import tachiyomi.domain.manga.model.Manga | ||||
| import tachiyomi.source.local.isLocal | ||||
| import java.lang.Long.max | ||||
| @@ -34,6 +35,7 @@ class SyncChaptersWithSource( | ||||
|     private val updateChapter: UpdateChapter, | ||||
|     private val getChaptersByMangaId: GetChaptersByMangaId, | ||||
|     private val getExcludedScanlators: GetExcludedScanlators, | ||||
|     private val libraryPreferences: LibraryPreferences, | ||||
| ) { | ||||
|  | ||||
|     /** | ||||
| @@ -145,12 +147,18 @@ class SyncChaptersWithSource( | ||||
|             return emptyList() | ||||
|         } | ||||
|  | ||||
|         val reAdded = mutableListOf<Chapter>() | ||||
|         val changedOrDuplicateReadUrls = mutableSetOf<String>() | ||||
|  | ||||
|         val deletedChapterNumbers = TreeSet<Double>() | ||||
|         val deletedReadChapterNumbers = TreeSet<Double>() | ||||
|         val deletedBookmarkedChapterNumbers = TreeSet<Double>() | ||||
|  | ||||
|         val readChapterNumbers = dbChapters | ||||
|             .asSequence() | ||||
|             .filter { it.read && it.isRecognizedNumber } | ||||
|             .map { it.chapterNumber } | ||||
|             .toSet() | ||||
|  | ||||
|         removedChapters.forEach { chapter -> | ||||
|             if (chapter.read) deletedReadChapterNumbers.add(chapter.chapterNumber) | ||||
|             if (chapter.bookmark) deletedBookmarkedChapterNumbers.add(chapter.chapterNumber) | ||||
| @@ -160,12 +168,19 @@ class SyncChaptersWithSource( | ||||
|         val deletedChapterNumberDateFetchMap = removedChapters.sortedByDescending { it.dateFetch } | ||||
|             .associate { it.chapterNumber to it.dateFetch } | ||||
|  | ||||
|         val markDuplicateAsRead = libraryPreferences.markDuplicateChapterRead().get() | ||||
|  | ||||
|         // 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 = newChapters.size | ||||
|         var updatedToAdd = newChapters.map { toAddItem -> | ||||
|             var chapter = toAddItem.copy(dateFetch = nowMillis + itemCount--) | ||||
|  | ||||
|             if (chapter.chapterNumber in readChapterNumbers && markDuplicateAsRead) { | ||||
|                 changedOrDuplicateReadUrls.add(chapter.url) | ||||
|                 chapter = chapter.copy(read = true) | ||||
|             } | ||||
|  | ||||
|             if (!chapter.isRecognizedNumber || chapter.chapterNumber !in deletedChapterNumbers) return@map chapter | ||||
|  | ||||
|             chapter = chapter.copy( | ||||
| @@ -178,7 +193,7 @@ class SyncChaptersWithSource( | ||||
|                 chapter = chapter.copy(dateFetch = it) | ||||
|             } | ||||
|  | ||||
|             reAdded.add(chapter) | ||||
|             changedOrDuplicateReadUrls.add(chapter.url) | ||||
|  | ||||
|             chapter | ||||
|         } | ||||
| @@ -202,12 +217,8 @@ class SyncChaptersWithSource( | ||||
|         // Note that last_update actually represents last time the chapter list changed at all | ||||
|         updateManga.awaitUpdateLastUpdate(manga.id) | ||||
|  | ||||
|         val reAddedUrls = reAdded.map { it.url }.toHashSet() | ||||
|  | ||||
|         val excludedScanlators = getExcludedScanlators.await(manga.id).toHashSet() | ||||
|  | ||||
|         return updatedToAdd.filterNot { | ||||
|             it.url in reAddedUrls || it.scanlator in excludedScanlators | ||||
|         } | ||||
|         return updatedToAdd.filterNot { it.url in changedOrDuplicateReadUrls || it.scanlator in excludedScanlators } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -205,6 +205,10 @@ object SettingsLibraryScreen : SearchableSettings { | ||||
|                     preference = libraryPreferences.newShowUpdatesCount(), | ||||
|                     title = stringResource(MR.strings.pref_library_update_show_tab_badge), | ||||
|                 ), | ||||
|                 Preference.PreferenceItem.SwitchPreference( | ||||
|                     preference = libraryPreferences.markDuplicateChapterRead(), | ||||
|                     title = stringResource(MR.strings.pref_mark_duplicate_chapter_read), | ||||
|                 ), | ||||
|             ), | ||||
|         ) | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user