fix block UI

pull/2048/head
821938089 2 years ago
parent 664eca08d6
commit e233acc3af
  1. 6
      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.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
/** /**
* 阅读界面数据处理 * 阅读界面数据处理
@ -145,10 +147,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} else { } else {
ReadBook.bookSource?.let { ReadBook.bookSource?.let {
viewModelScope.launch {
withContext(IO) {
val preUpdateJs = it.ruleToc?.preUpdateJs val preUpdateJs = it.ruleToc?.preUpdateJs
if (!preUpdateJs.isNullOrBlank()) { if (!preUpdateJs.isNullOrBlank()) {
AnalyzeRule(book, it).evalJS(preUpdateJs) AnalyzeRule(book, it).evalJS(preUpdateJs)
} }
}
WebBook.getChapterList(viewModelScope, it, book) WebBook.getChapterList(viewModelScope, it, book)
.onSuccess(IO) { cList -> .onSuccess(IO) { cList ->
appDb.bookChapterDao.insert(*cList.toTypedArray()) appDb.bookChapterDao.insert(*cList.toTypedArray())
@ -162,6 +167,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} }
} }
}
/** /**
* 同步进度 * 同步进度

Loading…
Cancel
Save