From 3a5ef948c46403ea55c091f6a062065107b53dc5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 11 Sep 2020 17:40:15 +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 --- app/src/main/java/io/legado/app/help/ThemeConfig.kt | 6 ++++-- .../main/java/io/legado/app/ui/config/ThemeListDialog.kt | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) 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 2b19e0136..f0434680b 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -41,10 +41,12 @@ object ThemeConfig { } } - fun addConfig(json: String) { - GSON.fromJsonObject(json)?.let { + fun addConfig(json: String): Boolean { + GSON.fromJsonObject(json.trim { it < ' ' })?.let { addConfig(it) + return true } + return false } private fun addConfig(newConfig: Config) { diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index a1b93262d..b090332e4 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -21,6 +21,7 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.GSON import io.legado.app.utils.applyTint import io.legado.app.utils.getClipText +import io.legado.app.utils.toast import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_theme_config.view.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -74,8 +75,11 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { when (item?.itemId) { R.id.menu_import -> { requireContext().getClipText()?.let { - ThemeConfig.addConfig(it) - initData() + if (ThemeConfig.addConfig(it)) { + initData() + } else { + toast("格式不对,添加失败") + } } } }