mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-21 20:27:06 +03:00
Option to update trackers when chapter marked as read
* 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: Roshan Varughese <40583749+Animeboynz@users.noreply.github.com>
Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
parent
e0e69b3085
commit
67af9a79ba
3 changed files with 44 additions and 2 deletions
|
@ -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<Episode>, 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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<Chapter>, 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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -642,6 +642,8 @@
|
|||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="exclude_scanlators">Exclude scanlators</string>
|
||||
<string name="no_scanlators_found">No scanlators found</string>
|
||||
<string name="confirm_tracker_update">Update trackers to chapter %d?</string>
|
||||
<string name="confirm_tracker_update_anime">Update trackers to episode %d?</string>
|
||||
<string name="manga_tracking_tab">Tracking</string>
|
||||
<string name="add_tracking">Add tracking</string>
|
||||
<string name="unread">Unread</string>
|
||||
|
|
Loading…
Reference in a new issue