From 6f3f109723b86e2b3a22b11eef91f05709694524 Mon Sep 17 00:00:00 2001 From: Luqman <16263232+Riztard@users.noreply.github.com> Date: Sat, 2 Mar 2024 23:55:09 +0700 Subject: [PATCH] add mark read dupes on reading (#1079) * Feature: mark read dupes * dupe chapter reading add summary * Update ReaderViewModel.kt * Update i18n/src/commonMain/resources/MR/base/strings.xml * Update app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt --------- Co-authored-by: jobobby04 --- .../more/settings/screen/SettingsReaderScreen.kt | 5 +++++ .../eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt | 9 +++++++++ .../tachiyomi/ui/reader/setting/ReaderPreferences.kt | 2 ++ i18n/src/commonMain/resources/MR/base/strings.xml | 2 ++ 4 files changed, 18 insertions(+) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt index 04af7edc77ed..7422c3f50799 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt @@ -178,6 +178,11 @@ object SettingsReaderScreen : SearchableSettings { pref = readerPreferences.skipDupe(), title = stringResource(MR.strings.pref_skip_dupe_chapters), ), + Preference.PreferenceItem.SwitchPreference( + pref = readerPreferences.markReadDupe(), + title = stringResource(MR.strings.pref_mark_read_dupe_chapters), + subtitle = stringResource(MR.strings.pref_mark_read_dupe_chapters_summary), + ), Preference.PreferenceItem.SwitchPreference( pref = readerPreferences.alwaysShowChapterTransition(), title = stringResource(MR.strings.pref_always_show_chapter_transition), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index 93274f254c72..cb17c5fd1d31 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -9,6 +9,7 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import eu.kanade.domain.base.BasePreferences +import eu.kanade.domain.chapter.interactor.SetReadStatus import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.interactor.SetMangaViewerFlags import eu.kanade.domain.manga.model.readerOrientation @@ -129,6 +130,7 @@ class ReaderViewModel @JvmOverloads constructor( private val getMergedMangaById: GetMergedMangaById = Injekt.get(), private val getMergedReferencesById: GetMergedReferencesById = Injekt.get(), private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId = Injekt.get(), + private val setReadStatus: SetReadStatus = Injekt.get() // SY <-- ) : ViewModel() { @@ -691,6 +693,13 @@ class ReaderViewModel @JvmOverloads constructor( // SY <-- readerChapter.chapter.read = true // SY --> + if (readerPreferences.markReadDupe().get()) { + getChaptersByMangaId.await(manga!!.id).sortedByDescending { it.sourceOrder } + .filter { + !it.read && it.chapterNumber > 0.0 && it.chapterNumber.toFloat() == readerChapter.chapter.chapter_number + } + .also { setReadStatus.await(true, *it.toTypedArray()) } + } if (manga?.isEhBasedManga() == true) { viewModelScope.launchNonCancellable { val chapterUpdates = chapterList diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt index e81d948b0789..d5cf6d844adb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt @@ -78,6 +78,8 @@ class ReaderPreferences( fun skipDupe() = preferenceStore.getBoolean("skip_dupe", false) + fun markReadDupe() = preferenceStore.getBoolean("mark_read_dupe", false) + // endregion // region Split two page spread diff --git a/i18n/src/commonMain/resources/MR/base/strings.xml b/i18n/src/commonMain/resources/MR/base/strings.xml index bba159c9170a..22ede657df4d 100755 --- a/i18n/src/commonMain/resources/MR/base/strings.xml +++ b/i18n/src/commonMain/resources/MR/base/strings.xml @@ -384,6 +384,8 @@ Skip chapters marked read Skip filtered chapters Skip duplicate chapters + Mark duplicate chapters as read + Mark duplicate chapters as read after reading Navigation Volume keys Invert volume keys