diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 61951bac2..23f1177ef 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,10 +6,7 @@ **2020/12/12** * 修复bug * 网络访问框架修改为RxHttp, 有bug及时反馈 - -**2020/12/11** -* 修复bug -* 网络访问框架修改为RxHttp, 有bug及时反馈 +* 优化进度同步 **2020/12/11** * 修复因修改进度同步导致的bug diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 5bbfbd7e6..4724dce6c 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -4,10 +4,7 @@ import androidx.lifecycle.MutableLiveData import com.hankcs.hanlp.HanLP import io.legado.app.App import io.legado.app.constant.BookType -import io.legado.app.data.entities.Book -import io.legado.app.data.entities.BookChapter -import io.legado.app.data.entities.BookSource -import io.legado.app.data.entities.ReadRecord +import io.legado.app.data.entities.* import io.legado.app.help.* import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.webBook.WebBook @@ -78,6 +75,13 @@ object ReadBook { } } + fun upProgress(progress: BookProgress) { + durChapterIndex = progress.durChapterIndex + durChapterPos = progress.durChapterPos + clearTextChapter() + loadContent(resetPageOffset = true) + } + fun clearTextChapter() { prevTextChapter = null curTextChapter = null 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 1e3a7b935..39a001395 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 @@ -20,6 +20,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.constant.Status import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter +import io.legado.app.data.entities.BookProgress import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadTipConfig import io.legado.app.help.storage.Backup @@ -108,6 +109,9 @@ class ReadBookActivity : ReadBookBaseActivity(), upMenu() upView() } + viewModel.processLiveData.observe(this) { + sureSyncProgress(it) + } viewModel.initData(intent) } @@ -218,10 +222,7 @@ class ReadBookActivity : ReadBookBaseActivity(), binding.readView.upPageAnim() } R.id.menu_book_info -> ReadBook.book?.let { - startActivity( - Pair("name", it.name), - Pair("author", it.author) - ) + startActivity(Pair("name", it.name), Pair("author", it.author)) } R.id.menu_toc_regex -> TocRegexDialog.show( supportFragmentManager, @@ -730,6 +731,16 @@ class ReadBookActivity : ReadBookBaseActivity(), } } + private fun sureSyncProgress(progress: BookProgress) { + alert(R.string.get_book_progress) { + message = getString(R.string.current_progress_exceeds_cloud) + okButton { + ReadBook.upProgress(progress) + } + noButton() + }.show() + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (resultCode == Activity.RESULT_OK) { 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 92c3e2277..494123cd6 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,11 +2,13 @@ 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 import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter +import io.legado.app.data.entities.BookProgress import io.legado.app.data.entities.SearchBook import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp @@ -22,9 +24,9 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.withContext class ReadBookViewModel(application: Application) : BaseViewModel(application) { - var isInitFinish = false var searchContentQuery = "" + val processLiveData = MutableLiveData() fun initData(intent: Intent) { execute { @@ -162,13 +164,14 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun syncBookProgress(book: Book) { execute { - BookWebDav.getBookProgress(book)?.let { - book.durChapterIndex = it.durChapterIndex - book.durChapterPos = it.durChapterPos - book.durChapterTime = it.durChapterTime - book.durChapterTitle = it.durChapterTitle - ReadBook.clearTextChapter() - ReadBook.loadContent(resetPageOffset = true) + BookWebDav.getBookProgress(book)?.let { progress -> + if (progress.durChapterIndex < book.durChapterIndex || + (progress.durChapterIndex == book.durChapterIndex && progress.durChapterPos < book.durChapterPos) + ) { + processLiveData.postValue(progress) + } else { + ReadBook.upProgress(progress) + } } } } diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 87e2e6ac9..32146a70e 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -789,5 +789,6 @@ 规则订阅 添加大佬们提供的规则导入地址\n添加后点击可导入规则 拉取云端进度 + 当前进度超过云端进度,是否同步? diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0e73c856f..370eaeb0a 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -790,5 +790,6 @@ 规则订阅 添加大佬们提供的规则导入地址\n添加后点击可导入规则 拉取云端进度 + 当前进度超过云端进度,是否同步? diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 807ebd11e..15c4f5604 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -793,5 +793,6 @@ 规则订阅 添加大佬们提供的规则导入地址\n添加后点击可导入规则 拉取云端进度 + 当前进度超过云端进度,是否同步? diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 281a0a367..18e1473b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -796,5 +796,6 @@ 规则订阅 添加大佬们提供的规则导入地址\n添加后点击可导入规则 拉取云端进度 + 当前进度超过云端进度,是否同步?