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. 67
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  4. 16
      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", "bgStr": "#F3F3F3",
"bgInt": 0,
"bgType": 0, "bgType": 0,
"darkStatusIcon": true, "darkStatusIcon": true,
"textColor": "#3E3D3B", "textColor": "#3E3D3B",
"textSize": 16, "textSize": 16,
"letterSpacing": 1, "letterSpacing": 1,
"lineSpacingExtra": 15, "lineSpacingExtra": 15,
"lineSpacingMultiplier": 3 "lineSpacingMultiplier": 3,
"paddingLeft": 16,
"paddingRight": 16,
"paddingTop": 0,
"paddingBottom": 0
}, },
{ {
"bgStr": "#C6BAA1", "bgStr": "#C6BAA1",
"bgInt": 0,
"bgType": 0, "bgType": 0,
"darkStatusIcon": true, "darkStatusIcon": true,
"textColor": "#3E3D3B", "textColor": "#3E3D3B",
@ -27,7 +29,6 @@
}, },
{ {
"bgStr": "#E1F1DA", "bgStr": "#E1F1DA",
"bgInt": 0,
"bgType": 0, "bgType": 0,
"darkStatusIcon": true, "darkStatusIcon": true,
"textColor": "#3E3D3B", "textColor": "#3E3D3B",
@ -42,7 +43,6 @@
}, },
{ {
"bgStr": "#015A86", "bgStr": "#015A86",
"bgInt": 0,
"bgType": 0, "bgType": 0,
"darkStatusIcon": false, "darkStatusIcon": false,
"textColor": "#3E3D3B", "textColor": "#3E3D3B",
@ -57,7 +57,6 @@
}, },
{ {
"bgStr": "#808080", "bgStr": "#808080",
"bgInt": 0,
"bgType": 0, "bgType": 0,
"darkStatusIcon": false, "darkStatusIcon": false,
"textColor": "#3E3D3B", "textColor": "#3E3D3B",

@ -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,25 +14,30 @@ 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() {
val json = String(App.INSTANCE.assets.open("readConfig.json").readBytes()) try {
GSON.fromJsonArray<Config>(json)?.let { val json = String(App.INSTANCE.assets.open("readConfig.json").readBytes())
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.clear()
configList.addAll(it) 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
) )
} }

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

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

Loading…
Cancel
Save