diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 7b4032ced..61dc898f2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -108,9 +108,6 @@ class ReadBookActivity : ReadBookBaseActivity(), upMenu() upView() } - viewModel.processLiveData.observe(this) { - sureSyncProgress(it) - } viewModel.initData(intent) } @@ -232,7 +229,9 @@ class ReadBookActivity : ReadBookBaseActivity(), } R.id.menu_set_charset -> showCharsetConfig() R.id.menu_get_progress -> ReadBook.book?.let { - viewModel.syncBookProgress(it) + viewModel.syncBookProgress(it) { progress -> + sureSyncProgress(progress) + } } R.id.menu_help -> showReadMenuHelp() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 6d7eecd02..0257337aa 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -2,7 +2,6 @@ package io.legado.app.ui.book.read import android.app.Application import android.content.Intent -import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseViewModel @@ -26,7 +25,6 @@ import kotlinx.coroutines.withContext class ReadBookViewModel(application: Application) : BaseViewModel(application) { var isInitFinish = false var searchContentQuery = "" - val processLiveData = MutableLiveData() fun initData(intent: Intent) { execute { @@ -162,14 +160,20 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } - fun syncBookProgress(book: Book, syncBookProgress: Boolean = AppConfig.syncBookProgress) { + fun syncBookProgress( + book: Book, + syncBookProgress: Boolean = AppConfig.syncBookProgress, + alertSync: ((progress: BookProgress) -> Unit)? = null + ) { if (syncBookProgress) execute { - BookWebDav.getBookProgress(book)?.let { progress -> + BookWebDav.getBookProgress(book) + }.onSuccess { + it?.let { progress -> if (progress.durChapterIndex < book.durChapterIndex || (progress.durChapterIndex == book.durChapterIndex && progress.durChapterPos < book.durChapterPos) ) { - processLiveData.postValue(progress) + alertSync?.invoke(progress) } else { ReadBook.setProgress(progress) }