Skip to content

Commit

Permalink
Allow completely disabling "Update tracker" snackbar on mark as read (m…
Browse files Browse the repository at this point in the history
…ihonapp/mihon#1374)

Also fixes mihonapp/mihon#1369

(cherry picked from commit fc2f339)
  • Loading branch information
Animeboynz authored and cuong-tran committed Oct 28, 2024
1 parent b5705a1 commit b803d4e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/eu/kanade/domain/track/model/AutoTrackState.kt
Original file line number Diff line number Diff line change
@@ -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),
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -36,7 +38,10 @@ 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,
)

// KMK -->
fun autoSyncReadChapters() = preferenceStore.getBoolean("pref_auto_sync_read_chapters_key", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -87,6 +89,7 @@ object SettingsTrackingScreen : SearchableSettings {
val trackPreferences = remember { Injekt.get<TrackPreferences>() }
val trackerManager = remember { Injekt.get<TrackerManager>() }
val sourceManager = remember { Injekt.get<SourceManager>() }
val autoTrackStatePref = trackPreferences.autoUpdateTrackOnMarkRead()

var dialog by remember { mutableStateOf<Any?>(null) }
dialog?.run {
Expand Down Expand Up @@ -127,9 +130,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(),
),
// KMK -->
Preference.PreferenceItem.SwitchPreference(
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.domain.track.interactor.AddTracks
import eu.kanade.domain.track.interactor.RefreshTracks
import eu.kanade.domain.track.interactor.TrackChapter
import eu.kanade.domain.track.model.AutoTrackState
import eu.kanade.domain.track.model.toDomainTrack
import eu.kanade.domain.track.service.TrackPreferences
import eu.kanade.domain.ui.UiPreferences
Expand Down Expand Up @@ -241,6 +242,7 @@ class MangaScreenModel(

val chapterSwipeStartAction = libraryPreferences.swipeToEndAction().get()
val chapterSwipeEndAction = libraryPreferences.swipeToStartAction().get()
private var autoTrackState = trackPreferences.autoUpdateTrackOnMarkRead().get()

private val skipFiltered by readerPreferences.skipFiltered().asState(screenModelScope)

Expand Down Expand Up @@ -1338,15 +1340,20 @@ 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()))
Expand Down

0 comments on commit b803d4e

Please sign in to comment.