From fc2f339ea1cdc43c0041b2fed497dcfda853b85e Mon Sep 17 00:00:00 2001 From: Roshan Varughese <40583749+Animeboynz@users.noreply.github.com> Date: Sun, 27 Oct 2024 02:16:39 +1300 Subject: [PATCH] Allow completely disabling "Update tracker" snackbar on mark as read (#1374) Also fixes #1369 --- .../eu/kanade/domain/track/model/AutoTrackState.kt | 10 ++++++++++ .../kanade/domain/track/service/TrackPreferences.kt | 7 ++++++- .../more/settings/screen/SettingsTrackingScreen.kt | 8 +++++++- .../eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt | 12 +++++++++--- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/eu/kanade/domain/track/model/AutoTrackState.kt diff --git a/app/src/main/java/eu/kanade/domain/track/model/AutoTrackState.kt b/app/src/main/java/eu/kanade/domain/track/model/AutoTrackState.kt new file mode 100644 index 000000000..987999b74 --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/track/model/AutoTrackState.kt @@ -0,0 +1,10 @@ +package eu.kanade.domain.track.model + +import dev.icerock.moko.resources.StringResource +import tachiyomi.i18n.MR + +enum class AutoTrackState(val titleRes: StringResource) { + ALWAYS(MR.strings.lock_always), + ASK(MR.strings.default_category_summary), + NEVER(MR.strings.lock_never), +} 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 e82d3da11..d07bc715d 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 @@ -1,9 +1,11 @@ package eu.kanade.domain.track.service +import eu.kanade.domain.track.model.AutoTrackState import eu.kanade.tachiyomi.data.track.Tracker import eu.kanade.tachiyomi.data.track.anilist.Anilist import tachiyomi.core.common.preference.Preference import tachiyomi.core.common.preference.PreferenceStore +import tachiyomi.core.common.preference.getEnum class TrackPreferences( private val preferenceStore: PreferenceStore, @@ -36,5 +38,8 @@ class TrackPreferences( fun autoUpdateTrack() = preferenceStore.getBoolean("pref_auto_update_manga_sync_key", true) - fun autoUpdateTrackOnMarkRead() = preferenceStore.getBoolean("pref_auto_update_manga_on_mark_read", true) + fun autoUpdateTrackOnMarkRead() = preferenceStore.getEnum( + "pref_auto_update_manga_on_mark_read", + AutoTrackState.ALWAYS, + ) } 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 cec87196a..2a7231112 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 @@ -40,6 +40,7 @@ import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import dev.icerock.moko.resources.StringResource +import eu.kanade.domain.track.model.AutoTrackState import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.presentation.more.settings.Preference import eu.kanade.tachiyomi.data.track.EnhancedTracker @@ -53,6 +54,7 @@ import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.toast import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList +import kotlinx.collections.immutable.toPersistentMap import tachiyomi.core.common.util.lang.launchIO import tachiyomi.core.common.util.lang.withUIContext import tachiyomi.domain.source.service.SourceManager @@ -85,6 +87,7 @@ object SettingsTrackingScreen : SearchableSettings { val trackPreferences = remember { Injekt.get() } val trackerManager = remember { Injekt.get() } val sourceManager = remember { Injekt.get() } + val autoTrackStatePref = trackPreferences.autoUpdateTrackOnMarkRead() var dialog by remember { mutableStateOf(null) } dialog?.run { @@ -125,9 +128,12 @@ object SettingsTrackingScreen : SearchableSettings { pref = trackPreferences.autoUpdateTrack(), title = stringResource(MR.strings.pref_auto_update_manga_sync), ), - Preference.PreferenceItem.SwitchPreference( + Preference.PreferenceItem.ListPreference( pref = trackPreferences.autoUpdateTrackOnMarkRead(), title = stringResource(MR.strings.pref_auto_update_manga_on_mark_read), + entries = AutoTrackState.entries + .associateWith { stringResource(it.titleRes) } + .toPersistentMap(), ), Preference.PreferenceGroup( title = stringResource(MR.strings.services), 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 777bf87e9..75f730f0d 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.model.AutoTrackState import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.presentation.manga.DownloadAction import eu.kanade.presentation.manga.components.ChapterDownloadAction @@ -140,6 +141,7 @@ class MangaScreenModel( val chapterSwipeStartAction = libraryPreferences.swipeToEndAction().get() val chapterSwipeEndAction = libraryPreferences.swipeToStartAction().get() + var autoTrackState = trackPreferences.autoUpdateTrackOnMarkRead().get() private val skipFiltered by readerPreferences.skipFiltered().asState(screenModelScope) @@ -734,15 +736,19 @@ class MangaScreenModel( chapters = chapters.toTypedArray(), ) - if (!read) return@launchIO + if ( + successState?.hasLoggedInTrackers == false || + !read || autoTrackState == AutoTrackState.NEVER + ) { + return@launchIO + } val tracks = getTracks.await(mangaId) val maxChapterNumber = chapters.maxOf { it.chapterNumber } val shouldPromptTrackingUpdate = tracks.any { track -> maxChapterNumber > track.lastChapterRead } if (!shouldPromptTrackingUpdate) return@launchIO - - if (trackPreferences.autoUpdateTrackOnMarkRead().get()) { + if (autoTrackState == AutoTrackState.ALWAYS) { trackChapter.await(context, mangaId, maxChapterNumber) withUIContext { context.toast(context.stringResource(MR.strings.trackers_updated_summary, maxChapterNumber.toInt()))