Save current chapter progress when navigating to adjacent chapters
Fixes #9295
This commit is contained in:
parent
182e642cfc
commit
776d36caf1
2 changed files with 15 additions and 18 deletions
|
@ -99,10 +99,6 @@ import uy.kohesive.injekt.injectLazy
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
/**
|
|
||||||
* Activity containing the reader of Tachiyomi. This activity is mostly a container of the
|
|
||||||
* viewers, to which calls from the presenter or UI events are delegated.
|
|
||||||
*/
|
|
||||||
class ReaderActivity : BaseActivity() {
|
class ReaderActivity : BaseActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -661,7 +657,7 @@ class ReaderActivity : BaseActivity() {
|
||||||
* Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer
|
* Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer
|
||||||
* and the toolbar title.
|
* and the toolbar title.
|
||||||
*/
|
*/
|
||||||
fun setManga(manga: Manga) {
|
private fun setManga(manga: Manga) {
|
||||||
val prevViewer = viewer
|
val prevViewer = viewer
|
||||||
|
|
||||||
val viewerMode = ReadingModeType.fromPreference(viewModel.getMangaReadingMode(resolveDefault = false))
|
val viewerMode = ReadingModeType.fromPreference(viewModel.getMangaReadingMode(resolveDefault = false))
|
||||||
|
@ -776,7 +772,7 @@ class ReaderActivity : BaseActivity() {
|
||||||
* Called from the presenter if the initial load couldn't load the pages of the chapter. In
|
* Called from the presenter if the initial load couldn't load the pages of the chapter. In
|
||||||
* this case the activity is closed and a toast is shown to the user.
|
* this case the activity is closed and a toast is shown to the user.
|
||||||
*/
|
*/
|
||||||
fun setInitialChapterError(error: Throwable) {
|
private fun setInitialChapterError(error: Throwable) {
|
||||||
logcat(LogPriority.ERROR, error)
|
logcat(LogPriority.ERROR, error)
|
||||||
finish()
|
finish()
|
||||||
toast(error.message)
|
toast(error.message)
|
||||||
|
|
|
@ -200,17 +200,6 @@ class ReaderViewModel(
|
||||||
|
|
||||||
private val incognitoMode = preferences.incognitoMode().get()
|
private val incognitoMode = preferences.incognitoMode().get()
|
||||||
|
|
||||||
override fun onCleared() {
|
|
||||||
val currentChapters = state.value.viewerChapters
|
|
||||||
if (currentChapters != null) {
|
|
||||||
currentChapters.unref()
|
|
||||||
saveReadingProgress(currentChapters.currChapter)
|
|
||||||
chapterToDownload?.let {
|
|
||||||
downloadManager.addDownloadsToStartOfQueue(listOf(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// To save state
|
// To save state
|
||||||
state.map { it.viewerChapters?.currChapter }
|
state.map { it.viewerChapters?.currChapter }
|
||||||
|
@ -225,6 +214,17 @@ class ReaderViewModel(
|
||||||
.launchIn(viewModelScope)
|
.launchIn(viewModelScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
val currentChapters = state.value.viewerChapters
|
||||||
|
if (currentChapters != null) {
|
||||||
|
currentChapters.unref()
|
||||||
|
saveReadingProgress(currentChapters.currChapter)
|
||||||
|
chapterToDownload?.let {
|
||||||
|
downloadManager.addDownloadsToStartOfQueue(listOf(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user pressed the back button and is going to leave the reader. Used to
|
* Called when the user pressed the back button and is going to leave the reader. Used to
|
||||||
* trigger deletion of the downloaded chapters.
|
* trigger deletion of the downloaded chapters.
|
||||||
|
@ -337,10 +337,11 @@ class ReaderViewModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user is going to load the prev/next chapter through the menu button.
|
* Called when the user is going to load the prev/next chapter through the toolbar buttons.
|
||||||
*/
|
*/
|
||||||
private suspend fun loadAdjacent(chapter: ReaderChapter) {
|
private suspend fun loadAdjacent(chapter: ReaderChapter) {
|
||||||
val loader = loader ?: return
|
val loader = loader ?: return
|
||||||
|
saveCurrentChapterReadingProgress()
|
||||||
|
|
||||||
logcat { "Loading adjacent ${chapter.chapter.url}" }
|
logcat { "Loading adjacent ${chapter.chapter.url}" }
|
||||||
|
|
||||||
|
|
Reference in a new issue