Skip to content

Commit

Permalink
add toggle to auto mark read dupe chapter (#1078)
Browse files Browse the repository at this point in the history
* add toggle to auto mark read dupe chapter

https: //github.com/tachiyomiorg/tachiyomi/pull/9662
Co-Authored-By: Trace <[email protected]>

* Update LibraryUpdateJob.kt

---------

Co-authored-by: Trace <[email protected]>
  • Loading branch information
Riztard and TraceLTRC authored Feb 17, 2024
1 parent 30dcc68 commit ca81f48
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -392,7 +396,19 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
) {
try {
val newChapters = updateManga(manga, fetchWindow)
.sortedByDescending { it.sourceOrder }
// SY -->
.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
}
}
//SY <--

if (newChapters.isNotEmpty()) {
val categoryIds = getCategories.await(manga.id).map { it.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions i18n/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@
<string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string>
<string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string>

<string name="pref_library_mark_duplicate_chapters">Mark new duplicate chapters as read</string>
<string name="pref_library_mark_duplicate_chapters_summary">Automatically mark new chapters as read if it has been read before</string>

<string name="default_category">Default category</string>
<string name="default_category_summary">Always ask</string>
<string name="categorized_display_settings">Per-category settings for sort</string>
Expand Down

0 comments on commit ca81f48

Please sign in to comment.