fix block UI

pull/2048/head
821938089 2 years ago
parent 664eca08d6
commit e233acc3af
  1. 32
      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,20 +147,24 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} else { } else {
ReadBook.bookSource?.let { ReadBook.bookSource?.let {
val preUpdateJs = it.ruleToc?.preUpdateJs viewModelScope.launch {
if (!preUpdateJs.isNullOrBlank()) { withContext(IO) {
AnalyzeRule(book, it).evalJS(preUpdateJs) val preUpdateJs = it.ruleToc?.preUpdateJs
} if (!preUpdateJs.isNullOrBlank()) {
WebBook.getChapterList(viewModelScope, it, book) AnalyzeRule(book, it).evalJS(preUpdateJs)
.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))
} }
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))
}
}
} }
} }
} }

Loading…
Cancel
Save