pull/32/head
kunfei 5 years ago
parent 40fc6da347
commit 80ee1a837b
  1. 1
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 2
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  3. 9
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  4. 76
      app/src/main/java/io/legado/app/ui/readbook/config/ReadStylePopup.kt

@ -9,4 +9,5 @@ object Bus {
const val BATTERY_CHANGED = "batteryChanged" const val BATTERY_CHANGED = "batteryChanged"
const val TIME_CHANGED = "timeChanged" const val TIME_CHANGED = "timeChanged"
const val READ_ALOUD = "readAloud" const val READ_ALOUD = "readAloud"
const val UP_CONFIG = "upConfig"
} }

@ -32,7 +32,7 @@ object ReadBookConfig {
list list
} }
private var styleSelect var styleSelect
get() = App.INSTANCE.getPrefInt("readStyleSelect") get() = App.INSTANCE.getPrefInt("readStyleSelect")
set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value) set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value)
var bg: Drawable? = null var bg: Drawable? = null

@ -327,5 +327,14 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
observeEvent<String>(Bus.TIME_CHANGED) { page_view.upTime() } observeEvent<String>(Bus.TIME_CHANGED) { page_view.upTime() }
observeEvent<Int>(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEvent<Int>(Bus.BATTERY_CHANGED) { page_view.upBattery(it) }
observeEventSticky<String>(Bus.READ_ALOUD) { onClickReadAloud() } observeEventSticky<String>(Bus.READ_ALOUD) { onClickReadAloud() }
observeEventSticky<Int>(Bus.UP_CONFIG) {
when (it) {
0 -> {
upBg()
upStyle()
}
1 -> upStyle()
}
}
} }
} }

@ -1,12 +1,88 @@
package io.legado.app.ui.readbook.config package io.legado.app.ui.readbook.config
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.view.LayoutInflater
import android.widget.PopupWindow import android.widget.PopupWindow
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.pop_read_book_style.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class ReadStylePopup(context: Context?) : PopupWindow(context) { class ReadStylePopup(context: Context?) : PopupWindow(context) {
init { init {
@SuppressLint("InflateParams")
contentView = LayoutInflater.from(context).inflate(R.layout.pop_read_book_style, null)
initData()
initOnClick()
} }
private fun initData() = with(contentView) {
upBg()
}
private fun initOnClick() = with(contentView) {
bg0.onClick {
ReadBookConfig.styleSelect = 0
ReadBookConfig.upBg()
upBg()
postEvent(Bus.UP_CONFIG, 0)
}
bg1.onClick {
ReadBookConfig.styleSelect = 1
ReadBookConfig.upBg()
upBg()
postEvent(Bus.UP_CONFIG, 0)
}
bg2.onClick {
ReadBookConfig.styleSelect = 2
ReadBookConfig.upBg()
upBg()
postEvent(Bus.UP_CONFIG, 0)
}
bg3.onClick {
ReadBookConfig.styleSelect = 3
ReadBookConfig.upBg()
upBg()
postEvent(Bus.UP_CONFIG, 0)
}
bg4.onClick {
ReadBookConfig.styleSelect = 4
ReadBookConfig.upBg()
upBg()
postEvent(Bus.UP_CONFIG, 0)
}
}
private fun upBg() = with(contentView) {
bg0.borderColor = context.primaryTextColor
bg1.borderColor = context.primaryTextColor
bg2.borderColor = context.primaryTextColor
bg3.borderColor = context.primaryTextColor
bg4.borderColor = context.primaryTextColor
when (ReadBookConfig.styleSelect) {
1 -> {
bg1.borderColor = context.accentColor
}
2 -> {
bg2.borderColor = context.accentColor
}
3 -> {
bg3.borderColor = context.accentColor
}
4 -> {
bg4.borderColor = context.accentColor
}
else -> {
bg0.borderColor = context.accentColor
}
}
}
} }
Loading…
Cancel
Save