From 2006630cc692b27cd22d10fca7b937a3beff5615 Mon Sep 17 00:00:00 2001 From: RandomNamer Date: Sun, 21 Jul 2024 13:18:51 -0400 Subject: [PATCH] fix: sync page progress regardless of chapter index --- .../track/interactor/SyncChapterProgressWithTrack.kt | 12 +++++++++++- .../kanade/domain/track/interactor/TrackChapter.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/track/interactor/SyncChapterProgressWithTrack.kt b/app/src/main/java/eu/kanade/domain/track/interactor/SyncChapterProgressWithTrack.kt index 59eab2ee73..b85111f333 100644 --- a/app/src/main/java/eu/kanade/domain/track/interactor/SyncChapterProgressWithTrack.kt +++ b/app/src/main/java/eu/kanade/domain/track/interactor/SyncChapterProgressWithTrack.kt @@ -1,11 +1,14 @@ package eu.kanade.domain.track.interactor +import android.app.Application import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.track.model.toDbTrack +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.data.database.models.toDomainChapter import eu.kanade.tachiyomi.data.track.EnhancedTracker import eu.kanade.tachiyomi.data.track.PageTracker import eu.kanade.tachiyomi.data.track.Tracker +import eu.kanade.tachiyomi.util.system.toast import logcat.LogPriority import tachiyomi.core.common.util.system.logcat import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId @@ -13,6 +16,8 @@ import tachiyomi.domain.chapter.interactor.UpdateChapter import tachiyomi.domain.chapter.model.toChapterUpdate import tachiyomi.domain.track.interactor.InsertTrack import tachiyomi.domain.track.model.Track +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get class SyncChapterProgressWithTrack( private val updateChapter: UpdateChapter, @@ -49,10 +54,15 @@ class SyncChapterProgressWithTrack( if (page >= 0) chapter.toDomainChapter()?.copy(lastPageRead = page.toLong())?.toChapterUpdate() else null } }?.getOrNull() ?: listOf() - if (pageReadProgressUpdates.isNotEmpty()) logcat(LogPriority.INFO) { pageReadProgressUpdates.toString() } try { tracker.update(updatedTrack.toDbTrack()) updateChapter.awaitAll(chapterUpdates + pageReadProgressUpdates) + if (pageReadProgressUpdates.isNotEmpty()) { + logcat(LogPriority.INFO) { pageReadProgressUpdates.toString() } + if (BuildConfig.APPLICATION_ID == "app.mihon.debug") { + Injekt.get().toast("Updated page progress") + } + } insertTrack.await(updatedTrack) } catch (e: Throwable) { logcat(LogPriority.WARN, e) diff --git a/app/src/main/java/eu/kanade/domain/track/interactor/TrackChapter.kt b/app/src/main/java/eu/kanade/domain/track/interactor/TrackChapter.kt index 08fc390c1b..91c939c24b 100644 --- a/app/src/main/java/eu/kanade/domain/track/interactor/TrackChapter.kt +++ b/app/src/main/java/eu/kanade/domain/track/interactor/TrackChapter.kt @@ -58,14 +58,14 @@ class TrackChapter( } } - suspend fun reportPageProgress(mangaId: Long, chapterNumber: Double, chapterUrl: String, pageIndex: Int) { + suspend fun reportPageProgress(mangaId: Long, chapterUrl: String, pageIndex: Int) { withNonCancellableContext { val tracks = getTracks.await(mangaId) if (tracks.isEmpty()) return@withNonCancellableContext tracks.mapNotNull { track -> val service = trackerManager.get(track.trackerId) - if (service == null || !service.isLoggedIn || chapterNumber <= track.lastChapterRead || service !is PageTracker) { + if (service == null || !service.isLoggedIn || service !is PageTracker) { return@mapNotNull null } async { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index d71663ca12..0af1763092 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -894,7 +894,7 @@ class ReaderViewModel @JvmOverloads constructor( val manga = manga ?: return viewModelScope.launchNonCancellable { - trackChapter.reportPageProgress(manga.id, readerChapter.chapter.chapter_number.toDouble(), readerChapter.chapter.url, chapterPageIndex) + trackChapter.reportPageProgress(manga.id, readerChapter.chapter.url, chapterPageIndex) } }