Skip to content

Commit

Permalink
Make option to mark duplicate chapter as read apply when reading (#1839)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntsyLich authored Mar 9, 2025
1 parent 4f06c1c commit 22b5fb5
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- Add private tracking support for Kitsu ([@MajorTanya](https://github.com/MajorTanya)) ([#1774](https://github.com/mihonapp/mihon/pull/1774))
- 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))
- Add back support for drag-and-drop category reordering ([@cuong-tran](https://github.com/cuong-tran)) ([#1427](https://github.com/mihonapp/mihon/pull/1427))
- Add option to mark new duplicate read chapters as read
- Add option to mark duplicate read chapters as read
- Display staff information on Anilist tracker search results ([@NarwhalHorns](https://github.com/NarwhalHorns)) ([#1810](https://github.com/mihonapp/mihon/pull/1810))

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import tachiyomi.data.chapter.ChapterSanitizer
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
import tachiyomi.domain.chapter.interactor.ShouldUpdateDbChapter
Expand All @@ -19,7 +20,6 @@ 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
Expand All @@ -35,7 +35,7 @@ class SyncChaptersWithSource(
private val updateChapter: UpdateChapter,
private val getChaptersByMangaId: GetChaptersByMangaId,
private val getExcludedScanlators: GetExcludedScanlators,
private val libraryPreferences: LibraryPreferences,
private val readerPreferences: ReaderPreferences,
) {

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ class SyncChaptersWithSource(
val deletedChapterNumberDateFetchMap = removedChapters.sortedByDescending { it.dateFetch }
.associate { it.chapterNumber to it.dateFetch }

val markDuplicateAsRead = libraryPreferences.markDuplicateChapterRead().get()
val markDuplicateAsRead = readerPreferences.markDuplicateReadChapterAsRead().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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@ 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),
),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ object SettingsReaderScreen : SearchableSettings {
preference = readerPreferences.alwaysShowChapterTransition(),
title = stringResource(MR.strings.pref_always_show_chapter_transition),
),
Preference.PreferenceItem.SwitchPreference(
preference = readerPreferences.markDuplicateReadChapterAsRead(),
title = stringResource(MR.strings.pref_mark_duplicate_read_chapter_read),
),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ interface Chapter : SChapter, Serializable {
var version: Long
}

val Chapter.isRecognizedNumber: Boolean
get() = chapter_number >= 0f

fun Chapter.toDomainChapter(): DomainChapter? {
if (id == null || manga_id == null) return null
return DomainChapter(
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import eu.kanade.domain.manga.model.readingMode
import eu.kanade.domain.source.interactor.GetIncognitoState
import eu.kanade.domain.track.interactor.TrackChapter
import eu.kanade.domain.track.service.TrackPreferences
import eu.kanade.tachiyomi.data.database.models.isRecognizedNumber
import eu.kanade.tachiyomi.data.database.models.toDomainChapter
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider
Expand Down Expand Up @@ -537,6 +538,21 @@ class ReaderViewModel @JvmOverloads constructor(
readerChapter.chapter.read = true
updateTrackChapterRead(readerChapter)
deleteChapterIfNeeded(readerChapter)

val duplicateUnreadChapters = chapterList
.mapNotNull {
val chapter = it.chapter
if (
!chapter.read &&
chapter.isRecognizedNumber &&
chapter.chapter_number == readerChapter.chapter.chapter_number
) {
ChapterUpdate(id = chapter.id!!, read = true)
} else {
null
}
}
updateChapter.awaitAll(duplicateUnreadChapters)
}

updateChapter.await(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class ReaderPreferences(

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

fun markDuplicateReadChapterAsRead() = preferenceStore.getBoolean("mark_duplicate_chapter_read", false)

// endregion

enum class FlashColor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ class LibraryPreferences(

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

fun markDuplicateChapterRead() = preferenceStore.getBoolean("mark_duplicate_chapter_read", false)

fun updateCategories() = preferenceStore.getStringSet(LIBRARY_UPDATE_CATEGORIES_PREF_KEY, emptySet())

fun updateCategoriesExclude() = preferenceStore.getStringSet(LIBRARY_UPDATE_CATEGORIES_EXCLUDE_PREF_KEY, emptySet())
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
<string name="pref_update_only_started">Skip unstarted entries</string>
<string name="pref_update_only_in_release_period">Predict next release time</string>
<string name="pref_library_update_show_tab_badge">Show unread count on Updates icon</string>
<string name="pref_mark_duplicate_chapter_read">Mark new duplicate read chapters as read</string>
<string name="pref_mark_duplicate_read_chapter_read">Mark duplicate read chapters as read</string>

<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>
Expand Down

0 comments on commit 22b5fb5

Please sign in to comment.