Skip to content

Commit 49aaf5b

Browse files
AntsyLichcuong-tran
authored andcommittedMar 9, 2025··
Make option to mark duplicate chapter as read apply when reading (mihonapp/mihon#1839)
(cherry picked from commit 22b5fb58ff8e89635d646f8fa29256b53c41ffbf)
1 parent b22a8ac commit 49aaf5b

File tree

9 files changed

+30
-11
lines changed

9 files changed

+30
-11
lines changed
 

‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
2121
- Add private tracking support for Kitsu ([@MajorTanya](https://github.com/MajorTanya)) ([#1774](https://github.com/mihonapp/mihon/pull/1774))
2222
- Add option to export minimal library information to a CSV file ([@Animeboynz](https://github.com/Animeboynz), [@AntsyLich](https://github.com/AntsyLich)) ([#1161](https://github.com/mihonapp/mihon/pull/1161))
2323
- Add back support for drag-and-drop category reordering ([@cuong-tran](https://github.com/cuong-tran)) ([#1427](https://github.com/mihonapp/mihon/pull/1427))
24-
- Add option to mark new duplicate read chapters as read
24+
- Add option to mark duplicate read chapters as read
2525
- Display staff information on Anilist tracker search results ([@NarwhalHorns](https://github.com/NarwhalHorns)) ([#1810](https://github.com/mihonapp/mihon/pull/1810))
2626

2727
### Changed

‎app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.data.download.DownloadProvider
1010
import eu.kanade.tachiyomi.source.Source
1111
import eu.kanade.tachiyomi.source.model.SChapter
1212
import eu.kanade.tachiyomi.source.online.HttpSource
13+
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
1314
import exh.source.isEhBasedManga
1415
import tachiyomi.data.chapter.ChapterSanitizer
1516
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
@@ -20,7 +21,6 @@ import tachiyomi.domain.chapter.model.NoChaptersException
2021
import tachiyomi.domain.chapter.model.toChapterUpdate
2122
import tachiyomi.domain.chapter.repository.ChapterRepository
2223
import tachiyomi.domain.chapter.service.ChapterRecognition
23-
import tachiyomi.domain.library.service.LibraryPreferences
2424
import tachiyomi.domain.manga.model.Manga
2525
import tachiyomi.source.local.isLocal
2626
import java.lang.Long.max
@@ -36,7 +36,7 @@ class SyncChaptersWithSource(
3636
private val updateChapter: UpdateChapter,
3737
private val getChaptersByMangaId: GetChaptersByMangaId,
3838
private val getExcludedScanlators: GetExcludedScanlators,
39-
private val libraryPreferences: LibraryPreferences,
39+
private val readerPreferences: ReaderPreferences,
4040
) {
4141

4242
/**
@@ -176,7 +176,7 @@ class SyncChaptersWithSource(
176176
val deletedChapterNumberDateFetchMap = removedChapters.sortedByDescending { it.dateFetch }
177177
.associate { it.chapterNumber to it.dateFetch }
178178

179-
val markDuplicateAsRead = libraryPreferences.markDuplicateChapterRead().get()
179+
val markDuplicateAsRead = readerPreferences.markDuplicateReadChapterAsRead().get()
180180

181181
// Date fetch is set in such a way that the upper ones will have bigger value than the lower ones
182182
// Sources MUST return the chapters from most to less recent, which is common.

‎app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt

-4
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,6 @@ object SettingsLibraryScreen : SearchableSettings {
231231
preference = libraryPreferences.newShowUpdatesCount(),
232232
title = stringResource(MR.strings.pref_library_update_show_tab_badge),
233233
),
234-
Preference.PreferenceItem.SwitchPreference(
235-
preference = libraryPreferences.markDuplicateChapterRead(),
236-
title = stringResource(MR.strings.pref_mark_duplicate_chapter_read),
237-
),
238234
// KMK -->
239235
Preference.PreferenceItem.SwitchPreference(
240236
preference = libraryPreferences.showUpdatingProgressBanner(),

‎app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt

+4
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ object SettingsReaderScreen : SearchableSettings {
239239
preference = readerPreferences.alwaysShowChapterTransition(),
240240
title = stringResource(MR.strings.pref_always_show_chapter_transition),
241241
),
242+
Preference.PreferenceItem.SwitchPreference(
243+
preference = readerPreferences.markDuplicateReadChapterAsRead(),
244+
title = stringResource(MR.strings.pref_mark_duplicate_read_chapter_read),
245+
),
242246
),
243247
)
244248
}

‎app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.kt

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ interface Chapter : SChapter, Serializable {
2727
var version: Long
2828
}
2929

30+
val Chapter.isRecognizedNumber: Boolean
31+
get() = chapter_number >= 0f
32+
3033
fun Chapter.toDomainChapter(): DomainChapter? {
3134
if (id == null || manga_id == null) return null
3235
return DomainChapter(

‎app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import eu.kanade.domain.sync.SyncPreferences
1919
import eu.kanade.domain.track.interactor.TrackChapter
2020
import eu.kanade.domain.track.service.TrackPreferences
2121
import eu.kanade.domain.ui.UiPreferences
22+
import eu.kanade.tachiyomi.data.database.models.isRecognizedNumber
2223
import eu.kanade.tachiyomi.data.database.models.toDomainChapter
2324
import eu.kanade.tachiyomi.data.download.DownloadManager
2425
import eu.kanade.tachiyomi.data.download.DownloadProvider
@@ -747,6 +748,21 @@ class ReaderViewModel @JvmOverloads constructor(
747748
updateTrackChapterRead(readerChapter)
748749
deleteChapterIfNeeded(readerChapter)
749750

751+
val duplicateUnreadChapters = chapterList
752+
.mapNotNull {
753+
val chapter = it.chapter
754+
if (
755+
!chapter.read &&
756+
chapter.isRecognizedNumber &&
757+
chapter.chapter_number == readerChapter.chapter.chapter_number
758+
) {
759+
ChapterUpdate(id = chapter.id!!, read = true)
760+
} else {
761+
null
762+
}
763+
}
764+
updateChapter.awaitAll(duplicateUnreadChapters)
765+
750766
// Check if syncing is enabled for chapter read:
751767
if (isSyncEnabled && syncTriggerOpt.syncOnChapterRead) {
752768
SyncDataJob.startNow(Injekt.get<Application>())

‎app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class ReaderPreferences(
143143

144144
fun showNavigationOverlayOnStart() = preferenceStore.getBoolean("reader_navigation_overlay_on_start", false)
145145

146+
fun markDuplicateReadChapterAsRead() = preferenceStore.getBoolean("mark_duplicate_chapter_read", false)
147+
146148
// endregion
147149

148150
// SY -->

‎domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt

-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ class LibraryPreferences(
152152

153153
fun categorizedDisplaySettings() = preferenceStore.getBoolean("categorized_display", false)
154154

155-
fun markDuplicateChapterRead() = preferenceStore.getBoolean("mark_duplicate_chapter_read", false)
156-
157155
// KMK -->
158156
fun showHiddenCategories() = preferenceStore.getBoolean("hide_hidden_categories", false)
159157
// KMK <--

‎i18n/src/commonMain/moko-resources/base/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
<string name="pref_update_only_started">Skip unstarted entries</string>
295295
<string name="pref_update_only_in_release_period">Predict next release time</string>
296296
<string name="pref_library_update_show_tab_badge">Show unread count on Updates icon</string>
297-
<string name="pref_mark_duplicate_chapter_read">Mark new duplicate read chapters as read</string>
297+
<string name="pref_mark_duplicate_read_chapter_read">Mark duplicate read chapters as read</string>
298298

299299
<string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string>
300300
<string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string>

0 commit comments

Comments
 (0)
Please sign in to comment.