From abfb72c89c008973db866bf4b696b699db155574 Mon Sep 17 00:00:00 2001 From: Roshan Varughese <40583749+Animeboynz@users.noreply.github.com> Date: Tue, 3 Sep 2024 09:41:44 +1200 Subject: [PATCH] Option to update trackers when chapter marked as read (#1177) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Track when marked as read * Add dismiss to snack bar * i18n & ignore decimal chapters * Detekt would have caught that 🤣 * `Ok` > `Yes` * Dont prompt if untracked or current > new * Move to MangaScreenModel * Suggestions Co-Authored-By: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * Review 2 * toggleAllSelections first --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --- .../tachiyomi/ui/manga/MangaScreenModel.kt | 24 ++++++++++++++++++- .../moko-resources/base/strings.xml | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) 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 287176b00..316dae4db 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 @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.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.manga.model.chaptersFiltered 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.presentation.manga.DownloadAction import eu.kanade.presentation.manga.components.ChapterDownloadAction import eu.kanade.presentation.util.formattedMessage @@ -92,6 +94,7 @@ class MangaScreenModel( private val libraryPreferences: LibraryPreferences = Injekt.get(), readerPreferences: ReaderPreferences = Injekt.get(), private val trackerManager: TrackerManager = Injekt.get(), + private val trackChapter: TrackChapter = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), private val downloadCache: DownloadCache = Injekt.get(), private val getMangaAndChapters: GetMangaWithChapters = Injekt.get(), @@ -721,13 +724,32 @@ 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 90262137a..035047acd 100644 --- a/i18n/src/commonMain/moko-resources/base/strings.xml +++ b/i18n/src/commonMain/moko-resources/base/strings.xml @@ -726,6 +726,7 @@ Are you sure? Exclude scanlators No scanlators found + Update trackers to chapter %d? Tracking