From a477e46c2596468cd49d0e005f22bc5636d0246b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 12 Feb 2020 09:07:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ReadBookConfig.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 77958aa9e..6f980b5b3 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -18,6 +18,10 @@ object ReadBookConfig { private val configFilePath = App.INSTANCE.filesDir.absolutePath + File.separator + readConfigFileName val configList: ArrayList = arrayListOf() + private val defaultConfigs by lazy { + val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) + GSON.fromJsonArray(json)!! + } var styleSelect get() = App.INSTANCE.getPrefInt("readStyleSelect") @@ -37,7 +41,7 @@ object ReadBookConfig { } fun upConfig() { - (getConfigs() ?: getDefaultConfigs()).let { + (getConfigs() ?: defaultConfigs).let { configList.clear() configList.addAll(it) } @@ -55,11 +59,6 @@ object ReadBookConfig { return null } - private fun getDefaultConfigs(): List { - val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) - return GSON.fromJsonArray(json)!! - } - fun upBg() { val resources = App.INSTANCE.resources val dm = resources.displayMetrics @@ -76,7 +75,7 @@ object ReadBookConfig { } fun resetDur() { - getDefaultConfigs()[styleSelect].let { + defaultConfigs[styleSelect].let { getConfig().setBg(it.bgType(), it.bgStr()) getConfig().setTextColor(it.textColor()) upBg() @@ -85,7 +84,7 @@ object ReadBookConfig { } private fun resetAll() { - getDefaultConfigs().let { + defaultConfigs.let { configList.clear() configList.addAll(it) save()