Jumping to a new chapter in reader now saves progress

and jumping back goes back to the last page you were on
This commit is contained in:
Jay 2020-05-11 15:22:15 -04:00
parent bb422743dd
commit f438933fc3

View File

@ -288,14 +288,17 @@ class ReaderPresenter(
fun loadChapter(chapter: Chapter) { fun loadChapter(chapter: Chapter) {
val loader = loader ?: return val loader = loader ?: return
Timber.d("Loading adjacent ${chapter.url}") viewerChaptersRelay.value?.currChapter?.let(::onChapterChanged)
Timber.d("Loading ${chapter.url}")
activeChapterSubscription?.unsubscribe() activeChapterSubscription?.unsubscribe()
activeChapterSubscription = getLoadObservable(loader, ReaderChapter(chapter)) activeChapterSubscription = getLoadObservable(loader, ReaderChapter(chapter))
.doOnSubscribe { isLoadingAdjacentChapterRelay.call(true) } .doOnSubscribe { isLoadingAdjacentChapterRelay.call(true) }
.doOnUnsubscribe { isLoadingAdjacentChapterRelay.call(false) } .doOnUnsubscribe { isLoadingAdjacentChapterRelay.call(false) }
.subscribeFirst({ view, _ -> .subscribeFirst({ view, _ ->
view.moveToPageIndex(0) val lastPage = if (chapter.pages_left <= 1) 0 else chapter.last_page_read
view.moveToPageIndex(lastPage)
view.refreshChapters() view.refreshChapters()
}, { _, _ -> }, { _, _ ->
// Ignore onError event, viewers handle that state // Ignore onError event, viewers handle that state
@ -351,7 +354,7 @@ class ReaderPresenter(
if (selectedChapter != currentChapters.currChapter) { if (selectedChapter != currentChapters.currChapter) {
Timber.d("Setting ${selectedChapter.chapter.url} as active") Timber.d("Setting ${selectedChapter.chapter.url} as active")
onChapterChanged(currentChapters.currChapter, selectedChapter) onChapterChanged(currentChapters.currChapter)
loadNewChapter(selectedChapter) loadNewChapter(selectedChapter)
return true return true
} }
@ -362,7 +365,7 @@ class ReaderPresenter(
* Called when a chapter changed from [fromChapter] to [toChapter]. It updates [fromChapter] * Called when a chapter changed from [fromChapter] to [toChapter]. It updates [fromChapter]
* on the database. * on the database.
*/ */
private fun onChapterChanged(fromChapter: ReaderChapter, toChapter: ReaderChapter) { private fun onChapterChanged(fromChapter: ReaderChapter) {
saveChapterProgress(fromChapter) saveChapterProgress(fromChapter)
saveChapterHistory(fromChapter) saveChapterHistory(fromChapter)
} }