mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Cleanup the reader save logic a bit
This commit is contained in:
parent
66d65dff2f
commit
ab98376091
2 changed files with 4 additions and 22 deletions
|
@ -360,9 +360,6 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
|||
.filterNotNull()
|
||||
.onEach(::setChapters)
|
||||
.launchIn(lifecycleScope)
|
||||
viewModel.state.value.viewerChapters?.currChapter?.let { currChapter ->
|
||||
currChapter.requestedPage = currChapter.chapter.last_page_read
|
||||
}
|
||||
|
||||
viewModel.eventFlow
|
||||
.onEach { event ->
|
||||
|
@ -452,11 +449,7 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!isChangingConfigurations) {
|
||||
viewModel.onSaveInstanceStateNonConfigurationChange()
|
||||
} else {
|
||||
viewModel.onSave()
|
||||
}
|
||||
viewModel.onSaveInstanceState()
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
|
|
|
@ -172,17 +172,6 @@ class ReaderViewModel(
|
|||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the presenter instance is being saved. It saves the currently active chapter
|
||||
* id and the last page read.
|
||||
*/
|
||||
fun onSave() {
|
||||
val currentChapter = getCurrentChapter()
|
||||
if (currentChapter != null) {
|
||||
currentChapter.requestedPage = currentChapter.chapter.last_page_read
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user pressed the back button and is going to leave the reader. Used to
|
||||
* trigger deletion of the downloaded chapters.
|
||||
|
@ -205,7 +194,7 @@ class ReaderViewModel(
|
|||
* Called when the activity is saved and not changing configurations. It updates the database
|
||||
* to persist the current progress of the active chapter.
|
||||
*/
|
||||
fun onSaveInstanceStateNonConfigurationChange() {
|
||||
fun onSaveInstanceState() {
|
||||
val currentChapter = getCurrentChapter() ?: return
|
||||
saveChapterProgress(currentChapter)
|
||||
}
|
||||
|
@ -595,11 +584,11 @@ class ReaderViewModel(
|
|||
fun saveCurrentChapterReadingProgress() = getCurrentChapter()?.let { saveReadingProgress(it) }
|
||||
|
||||
/**
|
||||
* Saves this [readerChapter] progress (last read page and whether it's read).
|
||||
* Saves this [readerChapter]'s progress (last read page and whether it's read).
|
||||
* If incognito mode isn't on or has at least 1 tracker
|
||||
*/
|
||||
private fun saveChapterProgress(readerChapter: ReaderChapter) {
|
||||
onSave()
|
||||
readerChapter.requestedPage = readerChapter.chapter.last_page_read
|
||||
db.getChapter(readerChapter.chapter.id!!).executeAsBlocking()?.let { dbChapter ->
|
||||
readerChapter.chapter.bookmark = dbChapter.bookmark
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue