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