Merge pull request #2048 from 821938089/fix-preUpdateJs-rule
修复preUpdateJs在其他更新目录的地方不执行
This commit is contained in:
@@ -18,6 +18,7 @@ import io.legado.app.help.BookHelp
|
|||||||
import io.legado.app.help.coroutine.Coroutine
|
import io.legado.app.help.coroutine.Coroutine
|
||||||
import io.legado.app.model.BookCover
|
import io.legado.app.model.BookCover
|
||||||
import io.legado.app.model.ReadBook
|
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.localBook.LocalBook
|
||||||
import io.legado.app.model.webBook.WebBook
|
import io.legado.app.model.webBook.WebBook
|
||||||
import io.legado.app.utils.postEvent
|
import io.legado.app.utils.postEvent
|
||||||
@@ -153,6 +154,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
chapterListData.postValue(emptyList())
|
chapterListData.postValue(emptyList())
|
||||||
} else {
|
} else {
|
||||||
bookSource?.let { bookSource ->
|
bookSource?.let { bookSource ->
|
||||||
|
val preUpdateJs = bookSource.ruleToc?.preUpdateJs
|
||||||
|
if (!preUpdateJs.isNullOrBlank()) {
|
||||||
|
AnalyzeRule(book, bookSource).evalJS(preUpdateJs)
|
||||||
|
}
|
||||||
WebBook.getChapterList(this, bookSource, book)
|
WebBook.getChapterList(this, bookSource, book)
|
||||||
.onSuccess(IO) {
|
.onSuccess(IO) {
|
||||||
if (inBookshelf) {
|
if (inBookshelf) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import io.legado.app.help.config.AppConfig
|
|||||||
import io.legado.app.help.coroutine.Coroutine
|
import io.legado.app.help.coroutine.Coroutine
|
||||||
import io.legado.app.model.ReadAloud
|
import io.legado.app.model.ReadAloud
|
||||||
import io.legado.app.model.ReadBook
|
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.localBook.LocalBook
|
||||||
import io.legado.app.model.webBook.WebBook
|
import io.legado.app.model.webBook.WebBook
|
||||||
import io.legado.app.service.BaseReadAloudService
|
import io.legado.app.service.BaseReadAloudService
|
||||||
@@ -32,6 +33,8 @@ import io.legado.app.utils.postEvent
|
|||||||
import io.legado.app.utils.toStringArray
|
import io.legado.app.utils.toStringArray
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阅读界面数据处理
|
* 阅读界面数据处理
|
||||||
@@ -144,16 +147,22 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ReadBook.bookSource?.let {
|
ReadBook.bookSource?.let {
|
||||||
WebBook.getChapterList(viewModelScope, it, book)
|
viewModelScope.launch(IO) {
|
||||||
.onSuccess(IO) { cList ->
|
val preUpdateJs = it.ruleToc?.preUpdateJs
|
||||||
appDb.bookChapterDao.insert(*cList.toTypedArray())
|
if (!preUpdateJs.isNullOrBlank()) {
|
||||||
appDb.bookDao.update(book)
|
AnalyzeRule(book, it).evalJS(preUpdateJs)
|
||||||
ReadBook.chapterSize = cList.size
|
|
||||||
ReadBook.upMsg(null)
|
|
||||||
ReadBook.loadContent(resetPageOffset = true)
|
|
||||||
}.onError {
|
|
||||||
ReadBook.upMsg(context.getString(R.string.error_load_toc))
|
|
||||||
}
|
}
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user