pull/32/head
kunfei 5 years ago
parent 7d9adece7c
commit 61cc1aba06
  1. 0
      app/src/main/assets/bg/bg1.jpg
  2. 11
      app/src/main/assets/readConfig.json
  3. 63
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  4. 8
      app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt
  5. 12
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

Before

Width:  |  Height:  |  Size: 312 KiB

After

Width:  |  Height:  |  Size: 312 KiB

@ -1,18 +1,20 @@
[
{
"bgStr": "#F3F3F3",
"bgInt": 0,
"bgType": 0,
"darkStatusIcon": true,
"textColor": "#3E3D3B",
"textSize": 16,
"letterSpacing": 1,
"lineSpacingExtra": 15,
"lineSpacingMultiplier": 3
"lineSpacingMultiplier": 3,
"paddingLeft": 16,
"paddingRight": 16,
"paddingTop": 0,
"paddingBottom": 0
},
{
"bgStr": "#C6BAA1",
"bgInt": 0,
"bgType": 0,
"darkStatusIcon": true,
"textColor": "#3E3D3B",
@ -27,7 +29,6 @@
},
{
"bgStr": "#E1F1DA",
"bgInt": 0,
"bgType": 0,
"darkStatusIcon": true,
"textColor": "#3E3D3B",
@ -42,7 +43,6 @@
},
{
"bgStr": "#015A86",
"bgInt": 0,
"bgType": 0,
"darkStatusIcon": false,
"textColor": "#3E3D3B",
@ -57,7 +57,6 @@
},
{
"bgStr": "#808080",
"bgInt": 0,
"bgType": 0,
"darkStatusIcon": false,
"textColor": "#3E3D3B",

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

@ -1,6 +1,7 @@
package io.legado.app.ui.widget.page
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.widget.FrameLayout
@ -34,13 +35,14 @@ class ContentView : FrameLayout {
}
fun setBg(bg: Drawable?) {
if (bg is ColorDrawable) {
bgImage.background = bg
bgImage
} else {
ImageLoader.load(context, bg)
.centerCrop()
.setAsDrawable(bgImage)
}
fun setBgColor(color: Int) {
page_panel.setBackgroundColor(color)
}
fun upTime() {

@ -6,7 +6,7 @@ import android.graphics.Canvas
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
import io.legado.app.R
import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.widget.page.delegate.CoverPageDelegate
import io.legado.app.ui.widget.page.delegate.PageDelegate
@ -169,10 +169,12 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
}
fun upBg() {
val bg = context.getDrawable(R.drawable.bg1)
curPage?.setBg(bg)
prevPage?.setBg(bg)
nextPage?.setBg(bg)
ReadBookConfig.bg ?: let {
ReadBookConfig.upBg()
}
curPage?.setBg(ReadBookConfig.bg)
prevPage?.setBg(ReadBookConfig.bg)
nextPage?.setBg(ReadBookConfig.bg)
}
fun upTime() {

Loading…
Cancel
Save