Skip to content

Commit

Permalink
fix: sync page progress regardless of chapter index
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomNamer committed Jul 21, 2024
1 parent 844460c commit 2006630
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
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
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,
Expand Down Expand Up @@ -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<Application>().toast("Updated page progress")
}
}
insertTrack.await(updatedTrack)
} catch (e: Throwable) {
logcat(LogPriority.WARN, e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 2006630

Please sign in to comment.