pull/32/head
kunfei 5 years ago
parent e4784e6200
commit ab2072fcf9
  1. 43
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 26
      app/src/main/java/io/legado/app/ui/readbook/Help.kt
  3. 6
      app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt
  4. 18
      app/src/main/res/layout/dialog_read_book_style.xml
  5. 2
      app/src/main/res/values/strings.xml

@ -17,31 +17,37 @@ import java.io.IOException
* 阅读界面配置
*/
object ReadBookConfig {
private val configList: ArrayList<Config> by lazy {
val list: ArrayList<Config> = arrayListOf()
val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + "config")
const val fileName = "readConfig.json"
private val configList: ArrayList<Config> = arrayListOf<Config>()
.apply {
upConfig(this)
}
var styleSelect
get() = App.INSTANCE.getPrefInt("readStyleSelect")
set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value)
var bg: Drawable? = null
fun getConfig(index: Int = styleSelect): Config {
return configList[index]
}
fun upConfig(list: ArrayList<Config> = configList) {
val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + fileName)
val json = if (configFile.exists()) {
String(configFile.readBytes())
} else {
String(App.INSTANCE.assets.open("readConfig.json").readBytes())
String(App.INSTANCE.assets.open(fileName).readBytes())
}
try {
GSON.fromJsonArray<Config>(json)?.let {
list.clear()
list.addAll(it)
}
} catch (e: Exception) {
list.clear()
list.addAll(getOnError())
}
list
}
var styleSelect
get() = App.INSTANCE.getPrefInt("readStyleSelect")
set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value)
var bg: Drawable? = null
fun getConfig(index: Int = styleSelect): Config {
return configList[index]
}
fun upBg() {
@ -50,7 +56,7 @@ object ReadBookConfig {
fun save() {
val json = GSON.toJson(configList)
val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + "config")
val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + fileName)
//获取流并存储
try {
BufferedWriter(FileWriter(configFile)).use { writer ->
@ -64,7 +70,7 @@ object ReadBookConfig {
fun reset() {
try {
val json = String(App.INSTANCE.assets.open("readConfig.json").readBytes())
val json = String(App.INSTANCE.assets.open(fileName).readBytes())
GSON.fromJsonArray<Config>(json)?.let {
configList.clear()
configList.addAll(it)
@ -109,7 +115,10 @@ object ReadBookConfig {
when (bgType) {
0 -> bgDrawable = ColorDrawable(Color.parseColor(bgStr))
1 -> bgDrawable =
Drawable.createFromStream(App.INSTANCE.assets.open("bg" + File.separator + bgStr), "bg")
Drawable.createFromStream(
App.INSTANCE.assets.open("bg" + File.separator + bgStr),
"bg"
)
else -> runCatching {
bgDrawable = Drawable.createFromPath(bgStr)
}

@ -1,12 +1,18 @@
package io.legado.app.ui.readbook
import android.app.Activity
import android.view.View
import android.view.View.NO_ID
import android.view.ViewGroup
import android.view.Window
import io.legado.app.App
import io.legado.app.utils.getPrefBoolean
object Help {
private const val NAVIGATION = "navigationBarBackground"
fun upSystemUiVisibility(window: Window, hide: Boolean = true) {
var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@ -28,4 +34,24 @@ object Help {
window.decorView.systemUiVisibility = flag
}
// 该方法需要在View完全被绘制出来之后调用,否则判断不了
//在比如 onWindowFocusChanged()方法中可以得到正确的结果
fun isNavigationBarExist(activity: Activity?): Boolean {
activity?.let {
val vp = it.window.decorView as? ViewGroup
if (vp != null) {
for (i in 0 until vp.childCount) {
vp.getChildAt(i).context.packageName
if (vp.getChildAt(i).id != NO_ID && NAVIGATION == activity.resources.getResourceEntryName(
vp.getChildAt(i).id
)
) {
return true
}
}
}
}
return false
}
}

@ -182,7 +182,11 @@ class ReadMenu : FrameLayout {
override fun onAnimationEnd(animation: Animation) {
vw_menu_bg.onClick { runMenuOut() }
val lp = vwNavigationBar.layoutParams
lp.height = if (context.getPrefBoolean("hideNavigationBar"))
lp.height =
if (context.getPrefBoolean("hideNavigationBar") and Help.isNavigationBarExist(
activity
)
)
context.getNavigationBarHeight() else 0
vwNavigationBar.layoutParams = lp
}

@ -14,6 +14,22 @@
android:background="@color/btn_bg_press"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_anim"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="@string/page_anim"
app:layout_constraintTop_toBottomOf="@+id/vw_bg_fg" />
<View
android:id="@+id/vw_bg_fg1"
android:layout_width="match_parent"
android:layout_height="0.8dp"
android:background="@color/btn_bg_press"
app:layout_constraintTop_toBottomOf="@+id/tv_anim" />
<TextView
android:id="@+id/tv_bg_ts"
android:layout_width="match_parent"
@ -21,7 +37,7 @@
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="@string/text_bg_style"
app:layout_constraintTop_toBottomOf="@+id/vw_bg_fg" />
app:layout_constraintTop_toBottomOf="@+id/vw_bg_fg1" />
<io.legado.app.ui.widget.image.CircleImageView
android:id="@+id/bg0"

@ -169,7 +169,7 @@
<string name="volume_key_page">音量键翻页</string>
<string name="click_open_page">点击翻页</string>
<string name="click_all_next_page">点击总是翻下一页</string>
<string name="open_page_anim">翻页动画</string>
<string name="page_anim">翻页动画</string>
<string name="keep_light">屏幕超时</string>
<string name="back">返回</string>
<string name="menu">菜单</string>

Loading…
Cancel
Save