diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingStore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingStore.kt index 862d11e8f..ba3db4406 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingStore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingStore.kt @@ -25,9 +25,9 @@ class DelayedTrackingStore(context: Context) { } } - fun clear() { + fun remove(track: Track) { preferences.edit { - clear() + remove(track.id.toString()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt index 508861e88..929856599 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt @@ -14,9 +14,8 @@ import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.InsertTrack import eu.kanade.domain.track.model.toDbTrack import eu.kanade.tachiyomi.data.track.TrackManager +import eu.kanade.tachiyomi.util.lang.withIOContext import eu.kanade.tachiyomi.util.system.logcat -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext import logcat.LogPriority import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -33,9 +32,9 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters) val trackManager = Injekt.get() val delayedTrackingStore = Injekt.get() - withContext(Dispatchers.IO) { + withIOContext { val tracks = delayedTrackingStore.getItems().mapNotNull { - val manga = getManga.await(it.mangaId) ?: return@withContext + val manga = getManga.await(it.mangaId) ?: return@withIOContext getTracks.await(manga.id) .find { track -> track.id == it.trackId } ?.copy(lastChapterRead = it.lastChapterRead.toDouble()) @@ -48,12 +47,11 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters) service.update(track.toDbTrack(), true) insertTrack.await(track) } + delayedTrackingStore.remove(track) } catch (e: Exception) { logcat(LogPriority.ERROR, e) } } - - delayedTrackingStore.clear() } return Result.success() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 5b1bcfc73..aa7149516 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -843,12 +843,14 @@ class ReaderPresenter( // for a while. The view can still be garbage collected. async { runCatching { - if (context.isOnline()) { + try { + if (!context.isOnline()) error("Couldn't update tracker as device is offline") service.update(updatedTrack.toDbTrack(), true) insertTrack.await(updatedTrack) - } else { + } catch (e: Exception) { delayedTrackingStore.addItem(updatedTrack) DelayedTrackingUpdateJob.setupTask(context) + throw e } } }