Merge pull request #765

* 深浅色切换问题

* 代码优化

* Merge branch 'HapeLee:main' into darkmode-fix

* toolbar 反色修复

* 代码优化
This commit is contained in:
5151561
2026-03-27 01:24:59 +08:00
committed by GitHub
parent b69235243c
commit 4bc40c3dbb
2 changed files with 21 additions and 44 deletions
@@ -320,12 +320,6 @@ class ReadBookActivity : BaseReadBookActivity(),
upScreenTimeOut()
ReadBook.register(this)
binding.readMenu.colorSurfaceContainer =
themeColor(com.google.android.material.R.attr.colorSurfaceContainer)
binding.readMenu.colorSecondary =
themeColor(androidx.appcompat.R.attr.colorPrimary)
binding.readMenu.colorSecondaryContainer =
themeColor(com.google.android.material.R.attr.colorSecondaryContainer)
binding.cursorLeft.setOnTouchListener(this)
binding.cursorRight.setOnTouchListener(this)
@@ -5,6 +5,7 @@ import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.RippleDrawable
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
@@ -94,20 +95,14 @@ class ReadMenu @JvmOverloads constructor(
fillAfter = true
}
var colorSurfaceContainer: Int = context.themeColor(com.google.android.material.R.attr.colorSurfaceContainer)
set(value) {
field = value
}
private val colorSurfaceContainer: Int
get() = context.themeColor(com.google.android.material.R.attr.colorSurfaceContainer)
var colorSecondary: Int = context.themeColor(androidx.appcompat.R.attr.colorPrimary)
set(value) {
field = value
}
private val colorSecondary: Int
get() = context.themeColor(androidx.appcompat.R.attr.colorPrimary)
var colorSecondaryContainer: Int = context.themeColor(com.google.android.material.R.attr.colorSecondaryContainer)
set(value) {
field = value
}
private val colorSecondaryContainer: Int
get() = context.themeColor(com.google.android.material.R.attr.colorSecondaryContainer)
private val bgColor: Int
get() = when (AppConfig.readBarStyle) {
@@ -210,6 +205,10 @@ class ReadMenu @JvmOverloads constructor(
}
private fun initView() = binding.run {
val bgColor = this@ReadMenu.bgColor
val acColor = this@ReadMenu.acColor
val bgcColor = this@ReadMenu.bgcColor
val alphaBgColor = ColorUtils.setAlphaComponent(bgColor, (AppConfig.menuAlpha / 100f * 255).toInt())
initAnimation()
updateSliderVisibility()
val brightnessBackground = GradientDrawable()
@@ -233,9 +232,12 @@ class ReadMenu @JvmOverloads constructor(
val allButtons = getUserButtons()
renderButtons(binding.bottomView, allButtons)
}
val alpha = (AppConfig.menuAlpha / 100f * 255).toInt()
titleBar.setBackgroundColor(ColorUtils.setAlphaComponent(bgColor, alpha))
cdSlider.setCardBackgroundColor(ColorUtils.setAlphaComponent(bgColor, alpha))
titleBar.setBackgroundColor(alphaBgColor)
titleBar.toolbar.setBackgroundColor(alphaBgColor)
bottomView.setBackgroundColor(alphaBgColor)
(tvPre.background as? RippleDrawable)?.setColor(ColorStateList.valueOf(bgcColor))
(tvNext.background as? RippleDrawable)?.setColor(ColorStateList.valueOf(bgcColor))
cdSlider.setCardBackgroundColor(alphaBgColor)
seekReadPage.trackInactiveTintList = ColorStateList.valueOf(bgcColor)
seekReadPage.trackActiveTintList = ColorStateList.valueOf(acColor)
seekReadPage.thumbTintList = ColorStateList.valueOf(acColor)
@@ -258,12 +260,12 @@ class ReadMenu @JvmOverloads constructor(
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
binding.bottomMenu.applyNavigationBarPadding()
} else {
bottomView.setBackgroundColor(ColorUtils.setAlphaComponent(bgColor, alpha))
binding.bottomView.applyNavigationBarPadding()
}
}
fun updateToolBarColor(){
fun updateToolBarColor() {
val acColor = this@ReadMenu.acColor
binding.titleBar.toolbar.navigationIcon?.setTint(acColor)
binding.titleBar.toolbar.apply {
setTitleTextColor(acColor)
@@ -276,8 +278,8 @@ class ReadMenu @JvmOverloads constructor(
}
fun reset() {
upColorConfig()
initView()
updateToolBarColor()
upBookView()
}
@@ -287,25 +289,6 @@ class ReadMenu @JvmOverloads constructor(
// }
}
private fun upColorConfig() {
// bgColor = if (immersiveMenu) {
// kotlin.runCatching {
// Color.parseColor(ReadBookConfig.durConfig.curBgStr())
// }.getOrDefault(context.bottomBackground)
// } else {
// context.bottomBackground
// }
// textColor = if (immersiveMenu) {
// ReadBookConfig.durConfig.curTextColor()
// } else {
// context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
// }
// bottomBackgroundList = Selector.colorBuild()
// .setDefaultColor(bgColor)
// .setPressedColor(ColorUtils.darkenColor(bgColor))
// .create()
}
fun upBrightnessState() {
if (brightnessAuto()) {
binding.ivBrightnessAuto.setColorFilter(context.themeColor(androidx.appcompat.R.attr.colorPrimary))
@@ -942,4 +925,4 @@ class ReadMenu @JvmOverloads constructor(
val onCheck: (() -> Unit)? = null,// 可选
var state: Boolean = false // 动态
)
}
}