From 98fc831706c2994591a333b4470cbd005afea9c3 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 1 Jan 2021 21:35:22 +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 --- .../main/java/io/legado/app/data/entities/ReplaceRule.kt | 3 +-- app/src/main/java/io/legado/app/help/IntentHelp.kt | 8 ++++---- app/src/main/java/io/legado/app/help/ThemeConfig.kt | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt index 1b5f7f8f0..d805d9dd0 100644 --- a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt @@ -49,8 +49,7 @@ data class ReplaceRule( if (isRegex){ try { Pattern.compile(pattern) - } - catch (ex: PatternSyntaxException){ + } catch (ex: PatternSyntaxException) { return false } } diff --git a/app/src/main/java/io/legado/app/help/IntentHelp.kt b/app/src/main/java/io/legado/app/help/IntentHelp.kt index 05b580272..7524bed78 100644 --- a/app/src/main/java/io/legado/app/help/IntentHelp.kt +++ b/app/src/main/java/io/legado/app/help/IntentHelp.kt @@ -13,23 +13,23 @@ object IntentHelp { fun toTTSSetting(context: Context) { //跳转到文字转语音设置界面 - try { + kotlin.runCatching { val intent = Intent() intent.action = "com.android.settings.TTS_SETTINGS" intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK context.startActivity(intent) - } catch (ignored: Exception) { + }.onFailure { context.toast(R.string.tip_cannot_jump_setting_page) } } fun toInstallUnknown(context: Context) { - try { + kotlin.runCatching { val intent = Intent() intent.action = "android.settings.MANAGE_UNKNOWN_APP_SOURCES" intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK context.startActivity(intent) - } catch (ignored: Exception) { + }.onFailure { context.toast("无法打开设置") } } diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index b4875ef8b..9de5ceade 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -61,11 +61,11 @@ object ThemeConfig { private fun getConfigs(): List? { val configFile = File(configFilePath) if (configFile.exists()) { - try { + kotlin.runCatching { val json = configFile.readText() return GSON.fromJsonArray(json) - } catch (e: Exception) { - e.printStackTrace() + }.onFailure { + it.printStackTrace() } } return null