mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Reset requested page in reader for read content
Also fixed page index not being remembered when switching chapters in reader
This commit is contained in:
parent
d75a2318a9
commit
72e35f590b
1 changed files with 10 additions and 7 deletions
|
@ -157,14 +157,18 @@ class ReaderViewModel(
|
|||
}
|
||||
|
||||
init {
|
||||
var secondRun = false
|
||||
// To save state
|
||||
state.map { it.viewerChapters?.currChapter }
|
||||
.distinctUntilChanged()
|
||||
.filterNotNull()
|
||||
.onEach { currentChapter ->
|
||||
chapterId = currentChapter.chapter.id!!
|
||||
if (secondRun || !currentChapter.chapter.read) {
|
||||
currentChapter.requestedPage = currentChapter.chapter.last_page_read
|
||||
}
|
||||
secondRun = true
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
|
@ -224,7 +228,9 @@ class ReaderViewModel(
|
|||
val manga = db.getManga(mangaId).executeAsBlocking()
|
||||
if (manga != null) {
|
||||
mutableState.update { it.copy(manga = manga) }
|
||||
if (chapterId == -1L) chapterId = initialChapterId
|
||||
if (chapterId == -1L) {
|
||||
chapterId = initialChapterId
|
||||
}
|
||||
|
||||
checkTrackers(manga)
|
||||
|
||||
|
@ -417,21 +423,18 @@ class ReaderViewModel(
|
|||
val loader = loader ?: return -1
|
||||
|
||||
Timber.d("Loading adjacent ${chapter.chapter.url}")
|
||||
var lastPage: Int? = null
|
||||
var lastPage: Int? = if (chapter.chapter.pages_left <= 1) 0 else chapter.chapter.last_page_read
|
||||
mutableState.update { it.copy(isLoadingAdjacentChapter = true) }
|
||||
try {
|
||||
withIOContext {
|
||||
loadChapter(loader, chapter)
|
||||
lastPage =
|
||||
if (chapter.chapter.pages_left <= 1) 0 else chapter.chapter.last_page_read
|
||||
withUIContext {
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
if (e is CancellationException) {
|
||||
throw e
|
||||
}
|
||||
Timber.e(e)
|
||||
lastPage = null
|
||||
} finally {
|
||||
mutableState.update { it.copy(isLoadingAdjacentChapter = false) }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue