From 664eca08d6923a4f1f5dc0708673b79918307281 Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Sun, 10 Jul 2022 07:37:34 +0800 Subject: [PATCH 1/3] fix preUpdateJs rule --- .../java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 5 +++++ .../java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index a7df33ffe..73a737bb1 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -18,6 +18,7 @@ import io.legado.app.help.BookHelp import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.BookCover import io.legado.app.model.ReadBook +import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.localBook.LocalBook import io.legado.app.model.webBook.WebBook import io.legado.app.utils.postEvent @@ -153,6 +154,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { chapterListData.postValue(emptyList()) } else { bookSource?.let { bookSource -> + val preUpdateJs = bookSource.ruleToc?.preUpdateJs + if (!preUpdateJs.isNullOrBlank()) { + AnalyzeRule(book, bookSource).evalJS(preUpdateJs) + } WebBook.getChapterList(this, bookSource, book) .onSuccess(IO) { if (inBookshelf) { 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 eee1250eb..f1e58f667 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 @@ -21,6 +21,7 @@ import io.legado.app.help.config.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.ReadAloud import io.legado.app.model.ReadBook +import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.localBook.LocalBook import io.legado.app.model.webBook.WebBook import io.legado.app.service.BaseReadAloudService @@ -144,6 +145,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } else { ReadBook.bookSource?.let { + val preUpdateJs = it.ruleToc?.preUpdateJs + if (!preUpdateJs.isNullOrBlank()) { + AnalyzeRule(book, it).evalJS(preUpdateJs) + } WebBook.getChapterList(viewModelScope, it, book) .onSuccess(IO) { cList -> appDb.bookChapterDao.insert(*cList.toTypedArray()) From e233acc3afc67be2a592fe05b3e99895a0f1b3d8 Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Sun, 10 Jul 2022 08:35:23 +0800 Subject: [PATCH 2/3] fix block UI --- .../app/ui/book/read/ReadBookViewModel.kt | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) 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 f1e58f667..59cf27d53 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 @@ -33,6 +33,8 @@ import io.legado.app.utils.postEvent import io.legado.app.utils.toStringArray import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext /** * 阅读界面数据处理 @@ -145,20 +147,24 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } else { ReadBook.bookSource?.let { - val preUpdateJs = it.ruleToc?.preUpdateJs - if (!preUpdateJs.isNullOrBlank()) { - AnalyzeRule(book, it).evalJS(preUpdateJs) - } - WebBook.getChapterList(viewModelScope, it, book) - .onSuccess(IO) { cList -> - appDb.bookChapterDao.insert(*cList.toTypedArray()) - appDb.bookDao.update(book) - ReadBook.chapterSize = cList.size - ReadBook.upMsg(null) - ReadBook.loadContent(resetPageOffset = true) - }.onError { - ReadBook.upMsg(context.getString(R.string.error_load_toc)) + viewModelScope.launch { + withContext(IO) { + val preUpdateJs = it.ruleToc?.preUpdateJs + if (!preUpdateJs.isNullOrBlank()) { + AnalyzeRule(book, it).evalJS(preUpdateJs) + } } + WebBook.getChapterList(viewModelScope, it, book) + .onSuccess(IO) { cList -> + appDb.bookChapterDao.insert(*cList.toTypedArray()) + appDb.bookDao.update(book) + ReadBook.chapterSize = cList.size + ReadBook.upMsg(null) + ReadBook.loadContent(resetPageOffset = true) + }.onError { + ReadBook.upMsg(context.getString(R.string.error_load_toc)) + } + } } } } From af6d50be4f9c8808f240724b2f17392f90f2f3b6 Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Sun, 10 Jul 2022 09:26:15 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 59cf27d53..ef1ea642a 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 @@ -147,12 +147,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } else { ReadBook.bookSource?.let { - viewModelScope.launch { - withContext(IO) { - val preUpdateJs = it.ruleToc?.preUpdateJs - if (!preUpdateJs.isNullOrBlank()) { - AnalyzeRule(book, it).evalJS(preUpdateJs) - } + viewModelScope.launch(IO) { + val preUpdateJs = it.ruleToc?.preUpdateJs + if (!preUpdateJs.isNullOrBlank()) { + AnalyzeRule(book, it).evalJS(preUpdateJs) } WebBook.getChapterList(viewModelScope, it, book) .onSuccess(IO) { cList ->