Don't prompt to add to library multiple times

Fixes #8842

(cherry picked from commit 82ea643c7d2ee75acc7fc17e2b9d492b57fb7a42)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt
This commit is contained in:
arkon 2023-01-11 20:00:50 -05:00 committed by Jobobby04
parent acf51f4d34
commit a55e27c657

View File

@ -173,7 +173,7 @@ class MangaInfoScreenModel(
val source: Source? val source: Source?
get() = successState?.source get() = successState?.source
private val isFavoritedManga: Boolean private val isFavorited: Boolean
get() = manga?.favorite ?: false get() = manga?.favorite ?: false
private val processedChapters: Sequence<ChapterItem>? private val processedChapters: Sequence<ChapterItem>?
@ -688,7 +688,7 @@ class MangaInfoScreenModel(
coroutineScope.launchIO { coroutineScope.launchIO {
val manga = state.manga val manga = state.manga
if (isFavoritedManga) { if (isFavorited) {
// Remove from library // Remove from library
if (updateManga.awaitUpdateFavorite(manga.id, false)) { if (updateManga.awaitUpdateFavorite(manga.id, false)) {
// Remove covers and update last modified in db // Remove covers and update last modified in db
@ -1068,22 +1068,28 @@ class MangaInfoScreenModel(
chapters: List<Chapter>, chapters: List<Chapter>,
startNow: Boolean, startNow: Boolean,
) { ) {
val successState = successState ?: return
if (startNow) { if (startNow) {
val chapterId = chapters.singleOrNull()?.id ?: return val chapterId = chapters.singleOrNull()?.id ?: return
downloadManager.startDownloadNow(chapterId) downloadManager.startDownloadNow(chapterId)
} else { } else {
downloadChapters(chapters) downloadChapters(chapters)
} }
if (!isFavoritedManga) {
if (!isFavorited && !successState.hasPromptedToAddBefore) {
coroutineScope.launch { coroutineScope.launch {
val result = snackbarHostState.showSnackbar( val result = snackbarHostState.showSnackbar(
message = context.getString(R.string.snack_add_to_library), message = context.getString(R.string.snack_add_to_library),
actionLabel = context.getString(R.string.action_add), actionLabel = context.getString(R.string.action_add),
withDismissAction = true, withDismissAction = true,
) )
if (result == SnackbarResult.ActionPerformed && !isFavoritedManga) { if (result == SnackbarResult.ActionPerformed && !isFavorited) {
toggleFavorite() toggleFavorite()
} }
updateSuccessState { successState ->
successState.copy(hasPromptedToAddBefore = true)
}
} }
} }
} }
@ -1585,6 +1591,7 @@ sealed class MangaScreenState {
val trackItems: List<TrackItem> = emptyList(), val trackItems: List<TrackItem> = emptyList(),
val isRefreshingData: Boolean = false, val isRefreshingData: Boolean = false,
val dialog: MangaInfoScreenModel.Dialog? = null, val dialog: MangaInfoScreenModel.Dialog? = null,
val hasPromptedToAddBefore: Boolean = false,
// SY --> // SY -->
val meta: RaisedSearchMetadata?, val meta: RaisedSearchMetadata?,
val mergedData: MergedMangaData?, val mergedData: MergedMangaData?,