From 45b6f77ebe4bcf74474a7eed707776e52b18f51d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Feb 2022 21:34:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/service/CheckSourceService.kt | 2 +- .../ui/association/FileAssociationActivity.kt | 8 ++- .../java/io/legado/app/utils/ToastUtils.kt | 56 +++++++++++-------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 2cf89b6e4..2dbbfbc67 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -146,7 +146,7 @@ class CheckSourceService : BaseService() { if (source.hasGroup("搜索失效") && url.isNullOrBlank()) { throw NoStackTraceException("搜索内容为空并且没有发现") } - books = WebBook.exploreBookAwait(this, source, url) + books = WebBook.exploreBookAwait(this, source, url!!) if (books.isEmpty()) { throw NoStackTraceException("发现书籍为空") } diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index 8ee117e3f..389ce22d5 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -137,7 +137,13 @@ class FileAssociationActivity : } } }.onFailure { - toastOnUi(it.localizedMessage) + when (it) { + is SecurityException -> localBookTreeSelect.launch { + title = "选择保存书籍的文件夹" + mode = HandleFileContract.DIR_SYS + } + else -> toastOnUi(it.localizedMessage) + } } } } diff --git a/app/src/main/java/io/legado/app/utils/ToastUtils.kt b/app/src/main/java/io/legado/app/utils/ToastUtils.kt index 7a5f2cc83..a2373f819 100644 --- a/app/src/main/java/io/legado/app/utils/ToastUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ToastUtils.kt @@ -10,49 +10,57 @@ private var toast: Toast? = null fun Context.toastOnUi(message: Int) { runOnUI { - if (toast == null) { - toast = Toast.makeText(this, message, Toast.LENGTH_SHORT) - } else { - toast?.setText(message) - toast?.duration = Toast.LENGTH_SHORT + kotlin.runCatching { + if (toast == null) { + toast = Toast.makeText(this, message, Toast.LENGTH_SHORT) + } else { + toast?.setText(message) + toast?.duration = Toast.LENGTH_SHORT + } + toast?.show() } - toast?.show() } } fun Context.toastOnUi(message: CharSequence?) { runOnUI { - if (toast == null) { - toast = Toast.makeText(this, message, Toast.LENGTH_SHORT) - } else { - toast?.setText(message) - toast?.duration = Toast.LENGTH_SHORT + kotlin.runCatching { + if (toast == null) { + toast = Toast.makeText(this, message, Toast.LENGTH_SHORT) + } else { + toast?.setText(message) + toast?.duration = Toast.LENGTH_SHORT + } + toast?.show() } - toast?.show() } } fun Context.longToastOnUi(message: Int) { runOnUI { - if (toast == null) { - toast = Toast.makeText(this, message, Toast.LENGTH_LONG) - } else { - toast?.setText(message) - toast?.duration = Toast.LENGTH_LONG + kotlin.runCatching { + if (toast == null) { + toast = Toast.makeText(this, message, Toast.LENGTH_LONG) + } else { + toast?.setText(message) + toast?.duration = Toast.LENGTH_LONG + } + toast?.show() } - toast?.show() } } fun Context.longToastOnUi(message: CharSequence?) { runOnUI { - if (toast == null) { - toast = Toast.makeText(this, message, Toast.LENGTH_LONG) - } else { - toast?.setText(message) - toast?.duration = Toast.LENGTH_LONG + kotlin.runCatching { + if (toast == null) { + toast = Toast.makeText(this, message, Toast.LENGTH_LONG) + } else { + toast?.setText(message) + toast?.duration = Toast.LENGTH_LONG + } + toast?.show() } - toast?.show() } }