Make option to mark duplicate chapter as read apply when reading (#1839)
(cherry picked from commit 22b5fb58ff8e89635d646f8fa29256b53c41ffbf) # Conflicts: # CHANGELOG.md # app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt
This commit is contained in:
parent
aad2bf4645
commit
ac8dab75fe
@ -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 exh.source.isEhBasedManga
|
||||
import tachiyomi.data.chapter.ChapterSanitizer
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
@ -20,7 +21,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
|
||||
@ -36,7 +36,7 @@ class SyncChaptersWithSource(
|
||||
private val updateChapter: UpdateChapter,
|
||||
private val getChaptersByMangaId: GetChaptersByMangaId,
|
||||
private val getExcludedScanlators: GetExcludedScanlators,
|
||||
private val libraryPreferences: LibraryPreferences,
|
||||
private val readerPreferences: ReaderPreferences,
|
||||
) {
|
||||
|
||||
/**
|
||||
@ -173,7 +173,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.
|
||||
|
@ -228,10 +228,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),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -238,6 +238,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),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -19,6 +19,7 @@ import eu.kanade.domain.sync.SyncPreferences
|
||||
import eu.kanade.domain.track.interactor.TrackChapter
|
||||
import eu.kanade.domain.track.service.TrackPreferences
|
||||
import eu.kanade.domain.ui.UiPreferences
|
||||
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
|
||||
@ -701,21 +702,6 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
// SY <--
|
||||
readerChapter.chapter.read = true
|
||||
// SY -->
|
||||
if (readerChapter.chapter.chapter_number >= 0 && readerPreferences.markReadDupe().get()) {
|
||||
getChaptersByMangaId.await(manga!!.id).sortedByDescending { it.sourceOrder }
|
||||
.filter {
|
||||
it.id != readerChapter.chapter.id &&
|
||||
!it.read &&
|
||||
it.chapterNumber.toFloat() == readerChapter.chapter.chapter_number
|
||||
}
|
||||
.ifEmpty { null }
|
||||
?.also {
|
||||
setReadStatus.await(true, *it.toTypedArray())
|
||||
it.forEach { chapter ->
|
||||
deleteChapterIfNeeded(ReaderChapter(chapter))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (manga?.isEhBasedManga() == true) {
|
||||
viewModelScope.launchNonCancellable {
|
||||
val chapterUpdates = chapterList
|
||||
@ -733,6 +719,24 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
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)
|
||||
// SY -->
|
||||
.also { deleteChapterIfNeeded(ReaderChapter(chapter)) }
|
||||
// SY <--
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
updateChapter.awaitAll(duplicateUnreadChapters)
|
||||
|
||||
// Check if syncing is enabled for chapter read:
|
||||
if (isSyncEnabled && syncTriggerOpt.syncOnChapterRead) {
|
||||
SyncDataJob.startNow(Injekt.get<Application>())
|
||||
|
@ -143,6 +143,8 @@ class ReaderPreferences(
|
||||
|
||||
fun showNavigationOverlayOnStart() = preferenceStore.getBoolean("reader_navigation_overlay_on_start", false)
|
||||
|
||||
fun markDuplicateReadChapterAsRead() = preferenceStore.getBoolean("mark_duplicate_chapter_read", false)
|
||||
|
||||
// endregion
|
||||
|
||||
// SY -->
|
||||
|
@ -128,8 +128,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())
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user