From 80ee1a837bb9e83dc96d4afb6e61b3740449257b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 21 Aug 2019 15:04:10 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/constant/Bus.kt | 1 + .../java/io/legado/app/help/ReadBookConfig.kt | 2 +- .../app/ui/readbook/ReadBookActivity.kt | 9 +++ .../app/ui/readbook/config/ReadStylePopup.kt | 76 +++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 12e72949d..03b4d7078 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -9,4 +9,5 @@ object Bus { const val BATTERY_CHANGED = "batteryChanged" const val TIME_CHANGED = "timeChanged" const val READ_ALOUD = "readAloud" + const val UP_CONFIG = "upConfig" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 45097ff16..cd6a77adf 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -32,7 +32,7 @@ object ReadBookConfig { list } - private var styleSelect + var styleSelect get() = App.INSTANCE.getPrefInt("readStyleSelect") set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value) var bg: Drawable? = null diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 191e93f2c..2cb79f9de 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -327,5 +327,14 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea observeEvent(Bus.TIME_CHANGED) { page_view.upTime() } observeEvent(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEventSticky(Bus.READ_ALOUD) { onClickReadAloud() } + observeEventSticky(Bus.UP_CONFIG) { + when (it) { + 0 -> { + upBg() + upStyle() + } + 1 -> upStyle() + } + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStylePopup.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStylePopup.kt index b0a533d3a..5a3931388 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStylePopup.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStylePopup.kt @@ -1,12 +1,88 @@ package io.legado.app.ui.readbook.config +import android.annotation.SuppressLint import android.content.Context +import android.view.LayoutInflater 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) { 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 + } + } + } } \ No newline at end of file