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()