From c153ac01f545ce9259c58aa5d5f7223d2f8f628b Mon Sep 17 00:00:00 2001 From: Roshan Varughese <40583749+Animeboynz@users.noreply.github.com> Date: Fri, 25 Oct 2024 01:23:28 +1300 Subject: [PATCH] Rework Auto Track on Mark as Read (#1365) --- .../kanade/domain/track/service/TrackPreferences.kt | 2 ++ .../more/settings/screen/SettingsTrackingScreen.kt | 4 ++++ .../eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt | 11 +++++++++++ i18n/src/commonMain/moko-resources/base/strings.xml | 2 ++ 4 files changed, 19 insertions(+) diff --git a/app/src/main/java/eu/kanade/domain/track/service/TrackPreferences.kt b/app/src/main/java/eu/kanade/domain/track/service/TrackPreferences.kt index ab000a9ea..e82d3da11 100644 --- a/app/src/main/java/eu/kanade/domain/track/service/TrackPreferences.kt +++ b/app/src/main/java/eu/kanade/domain/track/service/TrackPreferences.kt @@ -35,4 +35,6 @@ class TrackPreferences( fun anilistScoreType() = preferenceStore.getString("anilist_score_type", Anilist.POINT_10) fun autoUpdateTrack() = preferenceStore.getBoolean("pref_auto_update_manga_sync_key", true) + + fun autoUpdateTrackOnMarkRead() = preferenceStore.getBoolean("pref_auto_update_manga_on_mark_read", true) } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt index 021f0ceb2..cec87196a 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt @@ -125,6 +125,10 @@ object SettingsTrackingScreen : SearchableSettings { pref = trackPreferences.autoUpdateTrack(), title = stringResource(MR.strings.pref_auto_update_manga_sync), ), + Preference.PreferenceItem.SwitchPreference( + pref = trackPreferences.autoUpdateTrackOnMarkRead(), + title = stringResource(MR.strings.pref_auto_update_manga_on_mark_read), + ), Preference.PreferenceGroup( title = stringResource(MR.strings.services), preferenceItems = persistentListOf( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 316dae4db..777bf87e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -25,6 +25,7 @@ import eu.kanade.domain.manga.model.downloadedFilter import eu.kanade.domain.manga.model.toSManga import eu.kanade.domain.track.interactor.AddTracks import eu.kanade.domain.track.interactor.TrackChapter +import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.presentation.manga.DownloadAction import eu.kanade.presentation.manga.components.ChapterDownloadAction import eu.kanade.presentation.util.formattedMessage @@ -38,6 +39,7 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.util.chapter.getNextUnread import eu.kanade.tachiyomi.util.removeCovers +import eu.kanade.tachiyomi.util.system.toast import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.async @@ -92,6 +94,7 @@ class MangaScreenModel( private val mangaId: Long, private val isFromSource: Boolean, private val libraryPreferences: LibraryPreferences = Injekt.get(), + private val trackPreferences: TrackPreferences = Injekt.get(), readerPreferences: ReaderPreferences = Injekt.get(), private val trackerManager: TrackerManager = Injekt.get(), private val trackChapter: TrackChapter = Injekt.get(), @@ -739,6 +742,14 @@ class MangaScreenModel( if (!shouldPromptTrackingUpdate) return@launchIO + if (trackPreferences.autoUpdateTrackOnMarkRead().get()) { + trackChapter.await(context, mangaId, maxChapterNumber) + withUIContext { + context.toast(context.stringResource(MR.strings.trackers_updated_summary, maxChapterNumber.toInt())) + } + return@launchIO + } + val result = snackbarHostState.showSnackbar( message = context.stringResource(MR.strings.confirm_tracker_update, maxChapterNumber.toInt()), actionLabel = context.stringResource(MR.strings.action_ok), diff --git a/i18n/src/commonMain/moko-resources/base/strings.xml b/i18n/src/commonMain/moko-resources/base/strings.xml index 6b888a3e3..d6020896a 100644 --- a/i18n/src/commonMain/moko-resources/base/strings.xml +++ b/i18n/src/commonMain/moko-resources/base/strings.xml @@ -509,6 +509,7 @@ Tracking guide Update progress after reading + Update progress when marked as read Trackers One-way sync to update the chapter progress in external tracker services. Set up tracking for individual entries from their tracking button. Enhanced trackers @@ -739,6 +740,7 @@ Exclude scanlators No scanlators found Update trackers to chapter %d? + Trackers updated to chapter %d Tracking