fix Can't create handler inside thread that has not called Looper.prepare ()

This commit is contained in:
Xwite
2023-03-08 08:23:04 +08:00
parent b18b75b3e9
commit e84b20e7bb
@@ -30,6 +30,7 @@ import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.isContentScheme import io.legado.app.utils.isContentScheme
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.runOnUI
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@@ -274,7 +275,11 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun <T> importOrDownloadWebFile(webFile: WebFile, success: ((T) -> Unit)?) { fun <T> importOrDownloadWebFile(webFile: WebFile, success: ((T) -> Unit)?) {
bookSource ?: return bookSource ?: return
execute { execute {
callBack?.onWebFileProcessStart() callBack?.run {
runOnUI {
onWebFileProcessStart()
}
}
if (webFile.isSupported) { if (webFile.isSupported) {
val book = LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource) val book = LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource)
changeToLocalBook(book) changeToLocalBook(book)
@@ -286,8 +291,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}.onError { }.onError {
context.toastOnUi("ImportWebFileError\n${it.localizedMessage}") context.toastOnUi("ImportWebFileError\n${it.localizedMessage}")
}.onFinally { }.onFinally {
callBack?.onWebFileProcessFinally() callBack?.run {
} runOnUI {
onWebFileProcessFinally()
}
}
}
} }
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) { fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {