|
|
@ -3,9 +3,9 @@ package io.legado.app.help |
|
|
|
import android.graphics.Color |
|
|
|
import android.graphics.Color |
|
|
|
import android.graphics.drawable.ColorDrawable |
|
|
|
import android.graphics.drawable.ColorDrawable |
|
|
|
import android.graphics.drawable.Drawable |
|
|
|
import android.graphics.drawable.Drawable |
|
|
|
|
|
|
|
import com.google.gson.reflect.TypeToken |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.fromJsonArray |
|
|
|
|
|
|
|
import io.legado.app.utils.getPrefInt |
|
|
|
import io.legado.app.utils.getPrefInt |
|
|
|
import io.legado.app.utils.putPrefInt |
|
|
|
import io.legado.app.utils.putPrefInt |
|
|
|
import java.io.BufferedWriter |
|
|
|
import java.io.BufferedWriter |
|
|
@ -14,24 +14,29 @@ import java.io.FileWriter |
|
|
|
import java.io.IOException |
|
|
|
import java.io.IOException |
|
|
|
|
|
|
|
|
|
|
|
object ReadBookConfig { |
|
|
|
object ReadBookConfig { |
|
|
|
private val configList = arrayListOf<Config>() |
|
|
|
private val configList: ArrayList<Config> by lazy { |
|
|
|
private var styleSelect |
|
|
|
val list: ArrayList<Config> = arrayListOf() |
|
|
|
get() = App.INSTANCE.getPrefInt("readStyleSelect") |
|
|
|
|
|
|
|
set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value) |
|
|
|
|
|
|
|
var bg: Drawable? = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
|
|
|
val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + "config") |
|
|
|
val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + "config") |
|
|
|
val json = if (configFile.exists()) { |
|
|
|
val json = if (configFile.exists()) { |
|
|
|
String(configFile.readBytes()) |
|
|
|
String(configFile.readBytes()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
String(App.INSTANCE.assets.open("readConfig.json").readBytes()) |
|
|
|
String(App.INSTANCE.assets.open("readConfig.json").readBytes()) |
|
|
|
} |
|
|
|
} |
|
|
|
GSON.fromJsonArray<Config>(json)?.let { |
|
|
|
try { |
|
|
|
configList.clear() |
|
|
|
val listType = object : TypeToken<List<Config>>() {}.type |
|
|
|
configList.addAll(it) |
|
|
|
GSON.fromJson<List<Config>>(json, listType)?.let { |
|
|
|
} ?: reset() |
|
|
|
list.addAll(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
list.addAll(getOnError()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
list |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var styleSelect |
|
|
|
|
|
|
|
get() = App.INSTANCE.getPrefInt("readStyleSelect") |
|
|
|
|
|
|
|
set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value) |
|
|
|
|
|
|
|
var bg: Drawable? = null |
|
|
|
|
|
|
|
|
|
|
|
fun getConfig(): Config { |
|
|
|
fun getConfig(): Config { |
|
|
|
return configList[styleSelect] |
|
|
|
return configList[styleSelect] |
|
|
@ -41,7 +46,8 @@ object ReadBookConfig { |
|
|
|
getConfig().apply { |
|
|
|
getConfig().apply { |
|
|
|
when (bgType) { |
|
|
|
when (bgType) { |
|
|
|
0 -> bg = ColorDrawable(Color.parseColor(bgStr)) |
|
|
|
0 -> bg = ColorDrawable(Color.parseColor(bgStr)) |
|
|
|
|
|
|
|
1 -> bg = Drawable.createFromStream(App.INSTANCE.assets.open("bg" + File.separator + bgStr), "bg") |
|
|
|
|
|
|
|
2 -> bg = Drawable.createFromPath(bgStr) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -61,23 +67,40 @@ object ReadBookConfig { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun reset() { |
|
|
|
fun reset() { |
|
|
|
|
|
|
|
try { |
|
|
|
val json = String(App.INSTANCE.assets.open("readConfig.json").readBytes()) |
|
|
|
val json = String(App.INSTANCE.assets.open("readConfig.json").readBytes()) |
|
|
|
GSON.fromJsonArray<Config>(json)?.let { |
|
|
|
val listType = object : TypeToken<List<Config>>() {}.type |
|
|
|
|
|
|
|
GSON.fromJson<List<Config>>(json, listType)?.let { |
|
|
|
configList.clear() |
|
|
|
configList.clear() |
|
|
|
configList.addAll(it) |
|
|
|
configList.addAll(it) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
configList.clear() |
|
|
|
|
|
|
|
configList.addAll(getOnError()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getOnError(): ArrayList<Config> { |
|
|
|
|
|
|
|
val list = arrayListOf<Config>() |
|
|
|
|
|
|
|
list.add(Config()) |
|
|
|
|
|
|
|
list.add(Config()) |
|
|
|
|
|
|
|
list.add(Config()) |
|
|
|
|
|
|
|
list.add(Config()) |
|
|
|
|
|
|
|
return list |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data class Config( |
|
|
|
data class Config( |
|
|
|
var bgStr: String = "#F3F3F3", |
|
|
|
var bgStr: String = "#015A86", |
|
|
|
var bgInt: Int = 0, |
|
|
|
|
|
|
|
var bgType: Int = 0, |
|
|
|
var bgType: Int = 0, |
|
|
|
var darkStatusIcon: Boolean = true, |
|
|
|
var darkStatusIcon: Boolean = true, |
|
|
|
var textColor: String = "#3E3D3B", |
|
|
|
|
|
|
|
var textSize: Int = 16, |
|
|
|
|
|
|
|
var letterSpacing: Int = 1, |
|
|
|
var letterSpacing: Int = 1, |
|
|
|
var lineSpacingExtra: Int = 15, |
|
|
|
var lineSpacingExtra: Int = 15, |
|
|
|
var lineSpacingMultiplier: Int = 3 |
|
|
|
var lineSpacingMultiplier: Int = 3, |
|
|
|
|
|
|
|
var paddingBottom: Int = 0, |
|
|
|
|
|
|
|
var paddingLeft: Int = 16, |
|
|
|
|
|
|
|
var paddingRight: Int = 16, |
|
|
|
|
|
|
|
var paddingTop: Int = 0, |
|
|
|
|
|
|
|
var textColor: String = "#3E3D3B", |
|
|
|
|
|
|
|
var textSize: Int = 15 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |