parent
d874f20362
commit
af0fdfa3b7
1 changed files with 16 additions and 3 deletions
|
@ -79,8 +79,8 @@ import java.util.Date
|
|||
/**
|
||||
* Presenter used by the activity to perform background operations.
|
||||
*/
|
||||
class ReaderViewModel(
|
||||
private val savedState: SavedStateHandle = SavedStateHandle(),
|
||||
class ReaderViewModel @JvmOverloads constructor(
|
||||
private val savedState: SavedStateHandle,
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val downloadManager: DownloadManager = Injekt.get(),
|
||||
private val downloadProvider: DownloadProvider = Injekt.get(),
|
||||
|
@ -120,6 +120,15 @@ class ReaderViewModel(
|
|||
field = value
|
||||
}
|
||||
|
||||
/**
|
||||
* The visible page index of the currently loaded chapter. Used to restore from process kill.
|
||||
*/
|
||||
private var chapterPageIndex = savedState.get<Int>("page_index") ?: -1
|
||||
set(value) {
|
||||
savedState["page_index"] = value
|
||||
field = value
|
||||
}
|
||||
|
||||
/**
|
||||
* The chapter loader for the loaded manga. It'll be null until [manga] is set.
|
||||
*/
|
||||
|
@ -198,7 +207,10 @@ class ReaderViewModel(
|
|||
.distinctUntilChanged()
|
||||
.filterNotNull()
|
||||
.onEach { currentChapter ->
|
||||
if (!currentChapter.chapter.read) {
|
||||
if (chapterPageIndex >= 0) {
|
||||
// Restore from SavedState
|
||||
currentChapter.requestedPage = chapterPageIndex
|
||||
} else if (!currentChapter.chapter.read) {
|
||||
currentChapter.requestedPage = currentChapter.chapter.last_page_read
|
||||
}
|
||||
chapterId = currentChapter.chapter.id!!
|
||||
|
@ -490,6 +502,7 @@ class ReaderViewModel(
|
|||
it.copy(currentPage = pageIndex + 1)
|
||||
}
|
||||
readerChapter.requestedPage = pageIndex
|
||||
chapterPageIndex = pageIndex
|
||||
|
||||
if (!incognitoMode && page.status != Page.State.ERROR) {
|
||||
readerChapter.chapter.last_page_read = pageIndex
|
||||
|
|
Reference in a new issue