Directly pass read chapter when updating tracker

(cherry picked from commit b642e019e8)
This commit is contained in:
arkon 2020-01-20 21:59:36 -05:00
parent 7a4763ee68
commit 0fd00331e1

View File

@ -319,7 +319,7 @@ class ReaderPresenter(
selectedChapter.chapter.last_page_read = page.index selectedChapter.chapter.last_page_read = page.index
if (selectedChapter.pages?.lastIndex == page.index) { if (selectedChapter.pages?.lastIndex == page.index) {
selectedChapter.chapter.read = true selectedChapter.chapter.read = true
updateTrackLastChapterRead() updateTrackChapterRead(selectedChapter)
enqueueDeleteReadChapters(selectedChapter) enqueueDeleteReadChapters(selectedChapter)
} }
@ -554,21 +554,11 @@ class ReaderPresenter(
* Starts the service that updates the last chapter read in sync services. This operation * Starts the service that updates the last chapter read in sync services. This operation
* will run in a background thread and errors are ignored. * will run in a background thread and errors are ignored.
*/ */
private fun updateTrackLastChapterRead() { private fun updateTrackChapterRead(readerChapter: ReaderChapter) {
if (!preferences.autoUpdateTrack()) return if (!preferences.autoUpdateTrack()) return
val viewerChapters = viewerChaptersRelay.value ?: return
val manga = manga ?: return val manga = manga ?: return
val currChapter = viewerChapters.currChapter.chapter val chapterRead = readerChapter.chapter.chapter_number.toInt()
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 trackManager = Injekt.get<TrackManager>() val trackManager = Injekt.get<TrackManager>()
@ -576,8 +566,8 @@ class ReaderPresenter(
.flatMapCompletable { trackList -> .flatMapCompletable { trackList ->
Completable.concat(trackList.map { track -> Completable.concat(trackList.map { track ->
val service = trackManager.getService(track.sync_id) val service = trackManager.getService(track.sync_id)
if (service != null && service.isLogged && lastChapterRead > track.last_chapter_read) { if (service != null && service.isLogged && chapterRead > track.last_chapter_read) {
track.last_chapter_read = lastChapterRead track.last_chapter_read = chapterRead
// We wan't these to execute even if the presenter is destroyed and leaks // We wan't these to execute even if the presenter is destroyed and leaks
// for a while. The view can still be garbage collected. // for a while. The view can still be garbage collected.