From 79a39927447364ad182134486ed4ef12a43e8450 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 12 Dec 2020 19:23:43 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/help/ReadBook.kt | 12 ++++++++---- .../app/ui/book/read/ReadBookActivity.kt | 14 ++++++++++++++ .../app/ui/book/read/ReadBookViewModel.kt | 19 +++++++++++-------- 3 files changed, 33 insertions(+), 12 deletions(-) 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..ac2e1de8f 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) } @@ -730,6 +734,16 @@ class ReadBookActivity : ReadBookBaseActivity(), } } + private fun sureSyncProgress(progress: BookProgress) { + alert(R.string.get_book_progress) { + message = "当前进度超过云端进度,是否同步?" + 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) + } } } } From a936bc635363bd4a809e09161d6f5312807d31b9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 12 Dec 2020 19:26:58 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 5 +---- 1 file changed, 1 insertion(+), 4 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 ac2e1de8f..02568c2f9 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 @@ -222,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, From 1f7b4bbad04f574333d7dcf479932120152733f2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 12 Dec 2020 19:29:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 2 +- app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) 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 02568c2f9..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 @@ -733,7 +733,7 @@ class ReadBookActivity : ReadBookBaseActivity(), private fun sureSyncProgress(progress: BookProgress) { alert(R.string.get_book_progress) { - message = "当前进度超过云端进度,是否同步?" + message = getString(R.string.current_progress_exceeds_cloud) okButton { 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添加后点击可导入规则 拉取云端进度 + 当前进度超过云端进度,是否同步? From 3c5a1907653fed81daebcdfba4ca34d6408e719d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 12 Dec 2020 19:31:24 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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