Explorar o código

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

Xwite %!s(int64=3) %!d(string=hai) anos
pai
achega
e84b20e7bb

+ 13 - 3
app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@@ -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>) {