From 7a0467edc4e6bf9b4a9a36c654afda72d4a29702 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 19 Dec 2020 22:51:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 7 +++---- .../legado/app/ui/book/read/ReadBookViewModel.kt | 14 +++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) 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) }