From 3d3d9b3a122697c0f956ccecf4bb724bc44b8aef Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 20 Jan 2020 21:59:36 -0500 Subject: [PATCH] Directly pass read chapter when updating tracker --- .../tachiyomi/ui/reader/ReaderPresenter.kt | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) 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 5dc85411f0..bf6d419714 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 @@ -329,7 +329,7 @@ class ReaderPresenter( selectedChapter.chapter.last_page_read = page.index if (selectedChapter.pages?.lastIndex == page.index) { selectedChapter.chapter.read = true - updateTrackLastChapterRead() + updateTrackChapterRead(selectedChapter) enqueueDeleteReadChapters(selectedChapter) } @@ -565,21 +565,11 @@ class ReaderPresenter( * Starts the service that updates the last chapter read in sync services. This operation * will run in a background thread and errors are ignored. */ - private fun updateTrackLastChapterRead() { + private fun updateTrackChapterRead(readerChapter: ReaderChapter) { if (!preferences.autoUpdateTrack()) return - val viewerChapters = viewerChaptersRelay.value ?: return val manga = manga ?: return - val currChapter = viewerChapters.currChapter.chapter - val prevChapter = viewerChapters.prevChapter?.chapter - - // Get the last chapter read from the reader. - val lastChapterRead = if (currChapter.read) - currChapter.chapter_number.toInt() - else if (prevChapter != null && prevChapter.read) - prevChapter.chapter_number.toInt() - else - return + val chapterRead = readerChapter.chapter.chapter_number.toInt() val trackManager = Injekt.get() @@ -587,8 +577,8 @@ class ReaderPresenter( .flatMapCompletable { trackList -> Completable.concat(trackList.map { track -> val service = trackManager.getService(track.sync_id) - if (service != null && service.isLogged && lastChapterRead > track.last_chapter_read) { - track.last_chapter_read = lastChapterRead + if (service != null && service.isLogged && chapterRead > track.last_chapter_read) { + track.last_chapter_read = chapterRead // We wan't these to execute even if the presenter is destroyed and leaks // for a while. The view can still be garbage collected.