diff --git a/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt b/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt index 8bb119625..e893e34c4 100644 --- a/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt @@ -2,6 +2,7 @@ package io.legado.app.base import android.os.Bundle import androidx.fragment.app.DialogFragment +import io.legado.app.help.coroutine.Coroutine import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -21,4 +22,12 @@ abstract class BaseDialogFragment : DialogFragment(), CoroutineScope { super.onDestroy() job.cancel() } + + fun execute( + scope: CoroutineScope = this, + context: CoroutineContext = Dispatchers.IO, + block: suspend CoroutineScope.() -> T + ): Coroutine { + return Coroutine.async(scope, context) { block() } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index f72484338..87d87e8d6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -147,7 +147,7 @@ class FontSelectDialog : BaseDialogFragment(), @SuppressLint("DefaultLocale") private fun getFontFiles(doc: DocumentFile) { - launch(IO) { + execute { val docItems = DocumentUtils.listFiles(App.INSTANCE, doc.uri) fontCacheFolder.listFiles()?.forEach { fontFile -> var contain = false @@ -182,6 +182,8 @@ class FontSelectDialog : BaseDialogFragment(), } catch (e: Exception) { toast(e.localizedMessage ?: "") } + }.onError { + toast("getFontFiles:${it.localizedMessage}") } }