新增一个电子书主题

This commit is contained in:
HapeLee
2025-10-27 23:07:20 +08:00
parent afbe56d853
commit 878f5c4a4b
10 changed files with 191 additions and 36 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ class App : Application() {
override fun onCreate() {
if (getPrefString("app_theme", "0") == "11") {
if (getPrefString("app_theme", "0") == "12") {
if (AppConfig.customMode == "accent")
setTheme(R.style.ThemeOverlay_WhiteBackground)
@@ -163,14 +163,15 @@ abstract class BaseActivity<VB : ViewBinding>(
"1" -> setTheme(R.style.Theme_Base_GR)
"2" -> setTheme(R.style.Theme_Base_Lemon)
"3" -> setTheme(R.style.Theme_Base_WH)
"4" -> setTheme(R.style.Theme_Base_Sora)
"5" -> setTheme(R.style.Theme_Base_August)
"6" -> setTheme(R.style.Theme_Base_Carlotta)
"7" -> setTheme(R.style.Theme_Base_Koharu)
"8" -> setTheme(R.style.Theme_Base_Yuuka)
"9" -> setTheme(R.style.Theme_Base_Phoebe)
"10" -> setTheme(R.style.Theme_Base_Mujika)
"11" -> {
"4" -> setTheme(R.style.Theme_Base_Elink)
"5" -> setTheme(R.style.Theme_Base_Sora)
"6" -> setTheme(R.style.Theme_Base_August)
"7" -> setTheme(R.style.Theme_Base_Carlotta)
"8" -> setTheme(R.style.Theme_Base_Koharu)
"9" -> setTheme(R.style.Theme_Base_Yuuka)
"10" -> setTheme(R.style.Theme_Base_Phoebe)
"11" -> setTheme(R.style.Theme_Base_Mujika)
"12" -> {
if (AppConfig.customMode == "accent")
setTheme(R.style.ThemeOverlay_WhiteBackground)
@@ -203,7 +204,7 @@ abstract class BaseActivity<VB : ViewBinding>(
}
}
"12" -> setTheme(R.style.AppTheme_Transparent)
"13" -> setTheme(R.style.AppTheme_Transparent)
}
if (AppConfig.pureBlack)
@@ -124,15 +124,16 @@ class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(co
"1" to R.style.Theme_Base_GR,
"2" to R.style.Theme_Base_Lemon,
"3" to R.style.Theme_Base_WH,
"4" to R.style.Theme_Base_Sora,
"5" to R.style.Theme_Base_August,
"6" to R.style.Theme_Base_Carlotta,
"7" to R.style.Theme_Base_Koharu,
"8" to R.style.Theme_Base_Yuuka,
"9" to R.style.Theme_Base_Phoebe,
"10" to R.style.Theme_Base_Mujika,
"11" to R.style.ThemeOverlay_WhiteBackground,
"12" to R.style.AppTheme_Transparent)
"4" to R.style.Theme_Base_Elink,
"5" to R.style.Theme_Base_Sora,
"6" to R.style.Theme_Base_August,
"7" to R.style.Theme_Base_Carlotta,
"8" to R.style.Theme_Base_Koharu,
"9" to R.style.Theme_Base_Yuuka,
"10" to R.style.Theme_Base_Phoebe,
"11" to R.style.Theme_Base_Mujika,
"12" to R.style.ThemeOverlay_WhiteBackground,
"13" to R.style.AppTheme_Transparent)
private fun getThemeColors(value: String): List<Int> {
val themeResId = themeResIdMap[value] ?: return listOf(Color.GRAY, Color.GRAY, Color.GRAY, Color.GRAY)
@@ -2,6 +2,7 @@ package io.legato.kazusa.ui.book.read
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet
@@ -14,6 +15,7 @@ import android.widget.FrameLayout
import android.widget.SeekBar
import androidx.appcompat.widget.PopupMenu
import androidx.core.graphics.ColorUtils
import androidx.core.view.doOnAttach
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.google.android.material.button.MaterialButton
@@ -47,6 +49,7 @@ import io.legato.kazusa.utils.putPrefBoolean
import io.legato.kazusa.utils.startActivity
import io.legato.kazusa.utils.themeColor
import io.legato.kazusa.utils.visible
import org.checkerframework.checker.units.qual.cd
import splitties.views.onClick
/**
@@ -167,19 +170,16 @@ class ReadMenu @JvmOverloads constructor(
}
init {
initView()
upBrightnessState()
bindEvent()
doOnAttach {
initView()
upBrightnessState()
bindEvent()
}
}
private fun initView() = binding.run {
initAnimation()
updateSliderVisibility()
binding.bottomView.post {
val allButtons = getUserButtons()
renderButtons(binding.bottomView, allButtons)
}
val brightnessBackground = GradientDrawable()
brightnessBackground.cornerRadius = 5F.dpToPx()
llBrightness.background = brightnessBackground
@@ -198,10 +198,16 @@ class ReadMenu @JvmOverloads constructor(
} else {
titleBarAddition.gone()
}
binding.bottomView.post {
val allButtons = getUserButtons()
renderButtons(binding.bottomView, allButtons)
}
val alpha = (AppConfig.menuAlpha / 100f * 255).toInt()
val color = context.themeColor(com.google.android.material.R.attr.colorSurfaceContainer)
titleBar.setBackgroundColor(ColorUtils.setAlphaComponent(color, alpha))
llSlider.alpha = AppConfig.menuAlpha / 100f
cdSlider.setCardBackgroundColor(ColorUtils.setAlphaComponent(color, alpha))
tvPre.alpha = AppConfig.menuAlpha / 100f * 255
tvNext.alpha = AppConfig.menuAlpha / 100f * 255
upBrightnessVwPos()
/**
* 确保视图不被导航栏遮挡
@@ -503,12 +509,7 @@ class ReadMenu @JvmOverloads constructor(
buttonMap.clear()
buttons.forEach { btn ->
val style =
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE)
com.google.android.material.R.attr.materialIconButtonFilledTonalStyle
else
com.google.android.material.R.attr.materialIconButtonOutlinedStyle
val style = com.google.android.material.R.attr.materialIconButtonOutlinedStyle
val button = MaterialButton(group.context, null, style).apply {
id = btn.id.hashCode()
setIconResource(btn.iconRes)
@@ -517,6 +518,7 @@ class ReadMenu @JvmOverloads constructor(
strokeWidth = 0
iconGravity = MaterialButton.ICON_GRAVITY_TEXT_START
maxLines = 1
iconTint = ColorStateList.valueOf(context.themeColor(androidx.appcompat.R.attr.colorPrimary))
setOnClickListener { btn.onClick() }
btn.onLongClick?.let { longAction ->
setOnLongClickListener {
@@ -561,7 +563,7 @@ class ReadMenu @JvmOverloads constructor(
iconRes = R.drawable.ic_read_aloud,
description = context.getString(R.string.read_aloud),
onClick = { runMenuOut { callBack.onClickReadAloud() } },
onLongClick = { callBack.showReadAloudDialog() }
onLongClick = { runMenuOut { callBack.onClickReadAloud() } }
),
ToolButton(
id = "setting",
@@ -653,7 +655,9 @@ class ReadMenu @JvmOverloads constructor(
fun upBookView() {
val bookName = ReadBook.book?.name ?: ""
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
val isTablet = (resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
if (isTablet || resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
binding.titleBar.title = bookName
binding.tvBookName.gone()
} else {