diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreenModel.kt index 645c97719..0797cad8b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreenModel.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.entries.anime import android.content.Context +import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarResult import androidx.compose.runtime.Immutable @@ -17,6 +18,7 @@ import eu.kanade.domain.entries.anime.model.toSAnime import eu.kanade.domain.items.episode.interactor.SetSeenStatus import eu.kanade.domain.items.episode.interactor.SyncEpisodesWithSource import eu.kanade.domain.track.anime.interactor.AddAnimeTracks +import eu.kanade.domain.track.anime.interactor.TrackEpisode import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.presentation.entries.DownloadAction import eu.kanade.presentation.entries.anime.components.EpisodeDownloadAction @@ -94,6 +96,7 @@ class AnimeScreenModel( private val trackPreferences: TrackPreferences = Injekt.get(), internal val playerPreferences: PlayerPreferences = Injekt.get(), private val trackerManager: TrackerManager = Injekt.get(), + private val trackEpisode: TrackEpisode = Injekt.get(), private val downloadManager: AnimeDownloadManager = Injekt.get(), private val downloadCache: AnimeDownloadCache = Injekt.get(), private val getAnimeAndEpisodes: GetAnimeWithEpisodes = Injekt.get(), @@ -721,13 +724,32 @@ class AnimeScreenModel( * @param seen whether to mark episodes as seen or unseen. */ fun markEpisodesSeen(episodes: List, seen: Boolean) { + toggleAllSelection(false) screenModelScope.launchIO { setSeenStatus.await( seen = seen, episodes = episodes.toTypedArray(), ) + + if (!seen) return@launchIO + + val tracks = getTracks.await(animeId) + val maxEpisodeNumber = episodes.maxOf { it.episodeNumber } + val shouldPromptTrackingUpdate = tracks.any { track -> maxEpisodeNumber > track.lastEpisodeSeen } + + if (!shouldPromptTrackingUpdate) return@launchIO + + val result = snackbarHostState.showSnackbar( + message = context.stringResource(MR.strings.confirm_tracker_update_anime, maxEpisodeNumber.toInt()), + actionLabel = context.stringResource(MR.strings.action_ok), + duration = SnackbarDuration.Short, + withDismissAction = true, + ) + + if (result == SnackbarResult.ActionPerformed) { + trackEpisode.await(context, animeId, maxEpisodeNumber) + } } - toggleAllSelection(false) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreenModel.kt index b03295c27..3f0b5e2ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreenModel.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.entries.manga import android.content.Context +import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarResult import androidx.compose.runtime.Immutable @@ -23,6 +24,7 @@ import eu.kanade.domain.items.chapter.interactor.GetAvailableScanlators import eu.kanade.domain.items.chapter.interactor.SetReadStatus import eu.kanade.domain.items.chapter.interactor.SyncChaptersWithSource import eu.kanade.domain.track.manga.interactor.AddMangaTracks +import eu.kanade.domain.track.manga.interactor.TrackChapter import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.presentation.entries.DownloadAction import eu.kanade.presentation.entries.manga.components.ChapterDownloadAction @@ -94,6 +96,7 @@ class MangaScreenModel( readerPreferences: ReaderPreferences = Injekt.get(), private val trackPreferences: TrackPreferences = Injekt.get(), private val trackerManager: TrackerManager = Injekt.get(), + private val trackChapter: TrackChapter = Injekt.get(), private val downloadManager: MangaDownloadManager = Injekt.get(), private val downloadCache: MangaDownloadCache = Injekt.get(), private val getMangaAndChapters: GetMangaWithChapters = Injekt.get(), @@ -744,13 +747,28 @@ class MangaScreenModel( * @param read whether to mark chapters as read or unread. */ fun markChaptersRead(chapters: List, read: Boolean) { + toggleAllSelection(false) screenModelScope.launchIO { setReadStatus.await( read = read, chapters = chapters.toTypedArray(), ) + + if (!read) 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 + val result = snackbarHostState.showSnackbar( + message = context.stringResource(MR.strings.confirm_tracker_update, maxChapterNumber.toInt()), + actionLabel = context.stringResource(MR.strings.action_ok), + duration = SnackbarDuration.Short, + withDismissAction = true, + ) + if (result == SnackbarResult.ActionPerformed) { + trackChapter.await(context, mangaId, maxChapterNumber) + } } - toggleAllSelection(false) } /** diff --git a/i18n/src/commonMain/moko-resources/base/strings.xml b/i18n/src/commonMain/moko-resources/base/strings.xml index a019609c3..84bb8aa71 100644 --- a/i18n/src/commonMain/moko-resources/base/strings.xml +++ b/i18n/src/commonMain/moko-resources/base/strings.xml @@ -642,6 +642,8 @@ Are you sure? Exclude scanlators No scanlators found + Update trackers to chapter %d? + Update trackers to episode %d? Tracking Add tracking Unread