pull/32/head
kunfei 5 years ago
parent 863568f309
commit 507df7f39d
  1. 76
      app/src/main/assets/defaultConfig.json
  2. 73
      app/src/main/assets/readConfig.json
  3. 34
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt

@ -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
}
]
}

@ -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
}
]

@ -3,12 +3,19 @@ package io.legado.app.help
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import io.legado.app.App 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.File
import java.io.FileWriter
import java.io.IOException
object ReadBookConfig { object ReadBookConfig {
private val configList = arrayListOf<Config>() private val configList = arrayListOf<Config>()
var styleSelect = 0 var styleSelect
get() = App.INSTANCE.getPrefInt("readStyleSelect")
set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value)
var bg: Drawable? = null var bg: Drawable? = null
init { init {
@ -16,12 +23,11 @@ object ReadBookConfig {
val json = if (configFile.exists()) { val json = if (configFile.exists()) {
String(configFile.readBytes()) String(configFile.readBytes())
} else { } else {
String(App.INSTANCE.assets.open("defaultConfig.json").readBytes()) String(App.INSTANCE.assets.open("readConfig.json").readBytes())
} }
JsonPath.parse(json).let { JsonPath.parse(json).let {
styleSelect = it.readInt("$.readBookSelect") ?: 0
configList.clear() configList.clear()
configList.addAll(it.read<Array<Config>>("$.readBook")) configList.addAll(it.read<Array<Config>>("$"))
} }
} }
@ -29,6 +35,24 @@ object ReadBookConfig {
return configList[styleSelect] 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( data class Config(
var bg: String = "#F3F3F3", var bg: String = "#F3F3F3",
var bgInt: Int = 0, var bgInt: Int = 0,

Loading…
Cancel
Save