Option to update trackers when chapter marked as read (mihonapp/mihon#1177)
* 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>
(cherry picked from commit abfb72c89c008973db866bf4b696b699db155574)
# Conflicts:
# app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt
This commit is contained in:
parent
8845c2c317
commit
11c2ae70dd
2 changed files with 20 additions and 28 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.kanade.tachiyomi.ui.manga
|
package eu.kanade.tachiyomi.ui.manga
|
||||||
|
|
||||||
import android.app.Application
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.compose.material3.SnackbarDuration
|
||||||
import androidx.compose.material3.SnackbarHostState
|
import androidx.compose.material3.SnackbarHostState
|
||||||
import androidx.compose.material3.SnackbarResult
|
import androidx.compose.material3.SnackbarResult
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
|
@ -174,9 +174,9 @@ class MangaScreenModel(
|
||||||
// KMK -->
|
// KMK -->
|
||||||
private val sourcePreferences: SourcePreferences = Injekt.get(),
|
private val sourcePreferences: SourcePreferences = Injekt.get(),
|
||||||
private val trackPreferences: TrackPreferences = Injekt.get(),
|
private val trackPreferences: TrackPreferences = Injekt.get(),
|
||||||
private val trackChapter: TrackChapter = Injekt.get(),
|
|
||||||
// KMK <--
|
// KMK <--
|
||||||
private val trackerManager: TrackerManager = Injekt.get(),
|
private val trackerManager: TrackerManager = Injekt.get(),
|
||||||
|
private val trackChapter: TrackChapter = Injekt.get(),
|
||||||
private val downloadManager: DownloadManager = Injekt.get(),
|
private val downloadManager: DownloadManager = Injekt.get(),
|
||||||
private val downloadCache: DownloadCache = Injekt.get(),
|
private val downloadCache: DownloadCache = Injekt.get(),
|
||||||
private val getMangaAndChapters: GetMangaWithChapters = Injekt.get(),
|
private val getMangaAndChapters: GetMangaWithChapters = Injekt.get(),
|
||||||
|
|
@ -1194,11 +1194,6 @@ class MangaScreenModel(
|
||||||
when (swipeAction) {
|
when (swipeAction) {
|
||||||
LibraryPreferences.ChapterSwipeAction.ToggleRead -> {
|
LibraryPreferences.ChapterSwipeAction.ToggleRead -> {
|
||||||
markChaptersRead(listOf(chapter), !chapter.read)
|
markChaptersRead(listOf(chapter), !chapter.read)
|
||||||
// KMK -->
|
|
||||||
if (!chapter.read) {
|
|
||||||
updateTrackChapterMarkedAsRead(chapter)
|
|
||||||
}
|
|
||||||
// KMK <--
|
|
||||||
}
|
}
|
||||||
LibraryPreferences.ChapterSwipeAction.ToggleBookmark -> {
|
LibraryPreferences.ChapterSwipeAction.ToggleBookmark -> {
|
||||||
bookmarkChapters(listOf(chapter), !chapter.bookmark)
|
bookmarkChapters(listOf(chapter), !chapter.bookmark)
|
||||||
|
|
@ -1336,37 +1331,33 @@ class MangaScreenModel(
|
||||||
* @param read whether to mark chapters as read or unread.
|
* @param read whether to mark chapters as read or unread.
|
||||||
*/
|
*/
|
||||||
fun markChaptersRead(chapters: List<Chapter>, read: Boolean) {
|
fun markChaptersRead(chapters: List<Chapter>, read: Boolean) {
|
||||||
|
toggleAllSelection(false)
|
||||||
screenModelScope.launchIO {
|
screenModelScope.launchIO {
|
||||||
setReadStatus.await(
|
setReadStatus.await(
|
||||||
read = read,
|
read = read,
|
||||||
chapters = chapters.toTypedArray(),
|
chapters = chapters.toTypedArray(),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
// KMK -->
|
|
||||||
if (read) {
|
|
||||||
chapters.maxByOrNull { it.chapterNumber }
|
|
||||||
?.also { updateTrackChapterMarkedAsRead(it) }
|
|
||||||
}
|
|
||||||
// KMK <--
|
|
||||||
toggleAllSelection(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// KMK -->
|
if (!read) return@launchIO
|
||||||
/**
|
|
||||||
* Starts the service that updates the chapter marked as read in sync services. This operation
|
|
||||||
* will run in a background thread and errors are ignored.
|
|
||||||
*/
|
|
||||||
private fun updateTrackChapterMarkedAsRead(chapter: Chapter) {
|
|
||||||
if (!trackPreferences.updateTrackMarkedRead().get()) return
|
|
||||||
|
|
||||||
val manga = manga ?: return
|
val tracks = getTracks.await(mangaId)
|
||||||
val context = Injekt.get<Application>()
|
val maxChapterNumber = chapters.maxOf { it.chapterNumber }
|
||||||
|
val shouldPromptTrackingUpdate = tracks.any { track -> maxChapterNumber > track.lastChapterRead }
|
||||||
|
|
||||||
screenModelScope.launchNonCancellable {
|
if (!shouldPromptTrackingUpdate) return@launchIO
|
||||||
trackChapter.await(context, manga.id, chapter.chapterNumber)
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// KMK <--
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the given list of chapters with the manager.
|
* Downloads the given list of chapters with the manager.
|
||||||
|
|
|
||||||
|
|
@ -728,6 +728,7 @@
|
||||||
<string name="are_you_sure">Are you sure?</string>
|
<string name="are_you_sure">Are you sure?</string>
|
||||||
<string name="exclude_scanlators">Exclude scanlators</string>
|
<string name="exclude_scanlators">Exclude scanlators</string>
|
||||||
<string name="no_scanlators_found">No scanlators found</string>
|
<string name="no_scanlators_found">No scanlators found</string>
|
||||||
|
<string name="confirm_tracker_update">Update trackers to chapter %d?</string>
|
||||||
|
|
||||||
<!-- Tracking Screen -->
|
<!-- Tracking Screen -->
|
||||||
<string name="manga_tracking_tab">Tracking</string>
|
<string name="manga_tracking_tab">Tracking</string>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue