From 507df7f39d4c8f944df398b6f951cbbe140eab00 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 20 Aug 2019 21:46:18 +0800 Subject: [PATCH] up --- app/src/main/assets/defaultConfig.json | 76 ------------------- app/src/main/assets/readConfig.json | 73 ++++++++++++++++++ .../java/io/legado/app/help/ReadBookConfig.kt | 34 +++++++-- 3 files changed, 102 insertions(+), 81 deletions(-) delete mode 100644 app/src/main/assets/defaultConfig.json create mode 100644 app/src/main/assets/readConfig.json diff --git a/app/src/main/assets/defaultConfig.json b/app/src/main/assets/defaultConfig.json deleted file mode 100644 index 089a4f3f7..000000000 --- a/app/src/main/assets/defaultConfig.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "readBookSelect": 0, - "readBook": [ - { - "bg": "#F3F3F3", - "bgInt": 0, - "bgType": 0, - "darkStatusIcon": true, - "textColor": "#3E3D3B", - "textSize": 16, - "letterSpacing": 1, - "lineSpacingExtra": 15, - "lineSpacingMultiplier": 3 - }, - { - "bg": "#C6BAA1", - "bgInt": 0, - "bgType": 0, - "darkStatusIcon": true, - "textColor": "#3E3D3B", - "textSize": 16, - "letterSpacing": 1, - "lineSpacingExtra": 15, - "lineSpacingMultiplier": 3, - "paddingLeft": 16, - "paddingRight": 16, - "paddingTop": 0, - "paddingBottom": 0 - }, - { - "bg": "#E1F1DA", - "bgInt": 0, - "bgType": 0, - "darkStatusIcon": true, - "textColor": "#3E3D3B", - "textSize": 16, - "letterSpacing": 1, - "lineSpacingExtra": 15, - "lineSpacingMultiplier": 3, - "paddingLeft": 16, - "paddingRight": 16, - "paddingTop": 0, - "paddingBottom": 0 - }, - { - "bg": "#015A86", - "bgInt": 0, - "bgType": 0, - "darkStatusIcon": false, - "textColor": "#3E3D3B", - "textSize": 16, - "letterSpacing": 1, - "lineSpacingExtra": 15, - "lineSpacingMultiplier": 3, - "paddingLeft": 16, - "paddingRight": 16, - "paddingTop": 0, - "paddingBottom": 0 - }, - { - "bg": "#808080", - "bgInt": 0, - "bgType": 0, - "darkStatusIcon": false, - "textColor": "#3E3D3B", - "textSize": 16, - "letterSpacing": 1, - "lineSpacingExtra": 15, - "lineSpacingMultiplier": 3, - "paddingLeft": 16, - "paddingRight": 16, - "paddingTop": 0, - "paddingBottom": 0 - } - ] -} \ No newline at end of file diff --git a/app/src/main/assets/readConfig.json b/app/src/main/assets/readConfig.json new file mode 100644 index 000000000..726668d1c --- /dev/null +++ b/app/src/main/assets/readConfig.json @@ -0,0 +1,73 @@ +[ + { + "bg": "#F3F3F3", + "bgInt": 0, + "bgType": 0, + "darkStatusIcon": true, + "textColor": "#3E3D3B", + "textSize": 16, + "letterSpacing": 1, + "lineSpacingExtra": 15, + "lineSpacingMultiplier": 3 + }, + { + "bg": "#C6BAA1", + "bgInt": 0, + "bgType": 0, + "darkStatusIcon": true, + "textColor": "#3E3D3B", + "textSize": 16, + "letterSpacing": 1, + "lineSpacingExtra": 15, + "lineSpacingMultiplier": 3, + "paddingLeft": 16, + "paddingRight": 16, + "paddingTop": 0, + "paddingBottom": 0 + }, + { + "bg": "#E1F1DA", + "bgInt": 0, + "bgType": 0, + "darkStatusIcon": true, + "textColor": "#3E3D3B", + "textSize": 16, + "letterSpacing": 1, + "lineSpacingExtra": 15, + "lineSpacingMultiplier": 3, + "paddingLeft": 16, + "paddingRight": 16, + "paddingTop": 0, + "paddingBottom": 0 + }, + { + "bg": "#015A86", + "bgInt": 0, + "bgType": 0, + "darkStatusIcon": false, + "textColor": "#3E3D3B", + "textSize": 16, + "letterSpacing": 1, + "lineSpacingExtra": 15, + "lineSpacingMultiplier": 3, + "paddingLeft": 16, + "paddingRight": 16, + "paddingTop": 0, + "paddingBottom": 0 + }, + { + "bg": "#808080", + "bgInt": 0, + "bgType": 0, + "darkStatusIcon": false, + "textColor": "#3E3D3B", + "textSize": 16, + "letterSpacing": 1, + "lineSpacingExtra": 15, + "lineSpacingMultiplier": 3, + "paddingLeft": 16, + "paddingRight": 16, + "paddingTop": 0, + "paddingBottom": 0 + } +] \ No newline at end of file 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 ed80686a6..1d71b603f 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -3,12 +3,19 @@ package io.legado.app.help import android.graphics.drawable.Drawable import com.jayway.jsonpath.JsonPath import io.legado.app.App -import io.legado.app.utils.readInt +import io.legado.app.utils.GSON +import io.legado.app.utils.getPrefInt +import io.legado.app.utils.putPrefInt +import java.io.BufferedWriter import java.io.File +import java.io.FileWriter +import java.io.IOException object ReadBookConfig { private val configList = arrayListOf() - var styleSelect = 0 + var styleSelect + get() = App.INSTANCE.getPrefInt("readStyleSelect") + set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value) var bg: Drawable? = null init { @@ -16,12 +23,11 @@ object ReadBookConfig { val json = if (configFile.exists()) { String(configFile.readBytes()) } else { - String(App.INSTANCE.assets.open("defaultConfig.json").readBytes()) + String(App.INSTANCE.assets.open("readConfig.json").readBytes()) } JsonPath.parse(json).let { - styleSelect = it.readInt("$.readBookSelect") ?: 0 configList.clear() - configList.addAll(it.read>("$.readBook")) + configList.addAll(it.read>("$")) } } @@ -29,6 +35,24 @@ object ReadBookConfig { return configList[styleSelect] } + fun save() { + val json = GSON.toJson(configList) + val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + "config") + //获取流并存储 + try { + BufferedWriter(FileWriter(configFile)).use { writer -> + writer.write(json) + writer.flush() + } + } catch (e: IOException) { + e.printStackTrace() + } + } + + fun reset() { + + } + data class Config( var bg: String = "#F3F3F3", var bgInt: Int = 0,