From 17a7f1e5207e0bdbb565a6d2ac6d62f67ff8a4f1 Mon Sep 17 00:00:00 2001
From: Riztard Lanthorn <16263232+Riztard@users.noreply.github.com>
Date: Sat, 13 Jan 2024 11:59:17 +0700
Subject: [PATCH 1/2] add toggle to auto mark read dupe chapter
https: //github.com/tachiyomiorg/tachiyomi/pull/9662
Co-Authored-By: Trace <49712094+traceltrc@users.noreply.github.com>
---
.../settings/screen/SettingsLibraryScreen.kt | 5 +++++
.../tachiyomi/data/library/LibraryUpdateJob.kt | 16 +++++++++++++++-
.../domain/library/service/LibraryPreferences.kt | 2 ++
.../src/commonMain/resources/MR/base/strings.xml | 3 +++
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt
index 6f97e3eabfcf..6e9c1c53e81d 100644
--- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt
+++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt
@@ -235,6 +235,11 @@ object SettingsLibraryScreen : SearchableSettings {
pref = libraryPreferences.newShowUpdatesCount(),
title = stringResource(MR.strings.pref_library_update_show_tab_badge),
),
+ Preference.PreferenceItem.SwitchPreference(
+ pref = libraryPreferences.libraryReadDuplicateChapters(),
+ title = stringResource(MR.strings.pref_library_mark_duplicate_chapters),
+ subtitle = stringResource(MR.strings.pref_library_mark_duplicate_chapters_summary),
+ ),
),
)
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt
index af70fcf268b3..e05d0a4e9100 100755
--- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt
@@ -16,6 +16,7 @@ import androidx.work.WorkInfo
import androidx.work.WorkQuery
import androidx.work.WorkerParameters
import androidx.work.workDataOf
+import eu.kanade.domain.chapter.interactor.SetReadStatus
import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource
import eu.kanade.domain.manga.interactor.UpdateManga
import eu.kanade.domain.manga.model.copyFrom
@@ -100,6 +101,7 @@ import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
+import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
class LibraryUpdateJob(private val context: Context, workerParams: WorkerParameters) :
CoroutineWorker(context, workerParams) {
@@ -125,6 +127,8 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
private val insertTrack: InsertTrack = Injekt.get()
private val trackerManager: TrackerManager = Injekt.get()
private val mdList = trackerManager.mdList
+ private val getChaptersByMangaId: GetChaptersByMangaId = Injekt.get()
+ private val setReadStatus: SetReadStatus = Injekt.get()
// SY <--
private val notifier = LibraryUpdateNotifier(context)
@@ -392,7 +396,17 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
) {
try {
val newChapters = updateManga(manga, fetchWindow)
- .sortedByDescending { it.sourceOrder }
+ .sortedByDescending { it.sourceOrder }.run {
+ if (libraryPreferences.libraryReadDuplicateChapters().get()) {
+ val readChapters = getChaptersByMangaId.await(manga.id).filter { it.read }
+ val newReadChapters = this.filter { chapter -> readChapters.any { it.chapterNumber == chapter.chapterNumber } }
+ .also { setReadStatus.await(true, *it.toTypedArray()) }
+
+ this.filterNot { newReadChapters.contains(it) }
+ } else {
+ this
+ }
+ }
if (newChapters.isNotEmpty()) {
val categoryIds = getCategories.await(manga.id).map { it.id }
diff --git a/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt b/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt
index 62999b3373ee..0ab92e9d1a8f 100644
--- a/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt
+++ b/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt
@@ -92,6 +92,8 @@ class LibraryPreferences(
"pref_filter_library_lewd_v2",
TriState.DISABLED,
)
+
+ fun libraryReadDuplicateChapters() = preferenceStore.getBoolean("pref_library_mark_duplicate_chapters", false)
// SY <--
fun filterTracking(id: Int) = preferenceStore.getEnum(
diff --git a/i18n/src/commonMain/resources/MR/base/strings.xml b/i18n/src/commonMain/resources/MR/base/strings.xml
index 92075a425781..bba159c9170a 100755
--- a/i18n/src/commonMain/resources/MR/base/strings.xml
+++ b/i18n/src/commonMain/resources/MR/base/strings.xml
@@ -284,6 +284,9 @@
Automatically refresh metadata
Check for new cover and details when updating library
+ Mark new duplicate chapters as read
+ Automatically mark new chapters as read if it has been read before
+
Default category
Always ask
Per-category settings for sort
From 62d19c6ba0949c3cb8a45981da3502798ca2dd75 Mon Sep 17 00:00:00 2001
From: jobobby04
Date: Sat, 17 Feb 2024 15:31:03 -0500
Subject: [PATCH 2/2] Update LibraryUpdateJob.kt
---
.../java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt | 2 ++
1 file changed, 2 insertions(+)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt
index e05d0a4e9100..6e23bec01468 100755
--- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt
@@ -396,6 +396,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
) {
try {
val newChapters = updateManga(manga, fetchWindow)
+ // SY -->
.sortedByDescending { it.sourceOrder }.run {
if (libraryPreferences.libraryReadDuplicateChapters().get()) {
val readChapters = getChaptersByMangaId.await(manga.id).filter { it.read }
@@ -407,6 +408,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
this
}
}
+ //SY <--
if (newChapters.isNotEmpty()) {
val categoryIds = getCategories.await(manga.id).map { it.id }