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("格式不对,添加失败") + } } } }