阅读工具栏更多自定义

This commit is contained in:
XieJC 2022-09-08 10:14:56 +08:00
parent 7e0e6f5b0a
commit 7c838a71d9
16 changed files with 110 additions and 9 deletions

View File

@ -124,5 +124,7 @@ object PreferKey {
const val cNBBackground = "colorBottomBackgroundNight"
const val bgImageN = "backgroundImageNight"
const val bgImageNBlurring = "backgroundImageNightBlurring"
const val showReadTitleAddition = "showReadTitleAddition"
const val readBarStyleFollowPage = "readBarStyleFollowPage"
const val updateReadActionBar = "updateReadActionBar"
}

View File

@ -342,5 +342,16 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
set(value) {
appCtx.putPrefInt(PreferKey.bitmapCacheSize, value)
}
var showReadTitleBarAddition : Boolean
get() = appCtx.getPrefBoolean(PreferKey.showReadTitleAddition, true)
set(value) {
appCtx.putPrefBoolean(PreferKey.showReadTitleAddition, value)
}
var readBarStyleFollowPage : Boolean
get() = appCtx.getPrefBoolean(PreferKey.readBarStyleFollowPage, false)
set(value) {
appCtx.putPrefBoolean(PreferKey.readBarStyleFollowPage, value)
}
}

View File

@ -229,6 +229,7 @@ class ReadBookActivity : BaseReadBookActivity(),
setOnMenuItemClickListener(this@ReadBookActivity)
}.show()
}
binding.readMenu.refreshMenuColorFilter()
return super.onCompatCreateOptionsMenu(menu)
}
@ -1216,6 +1217,7 @@ class ReadBookActivity : BaseReadBookActivity(),
} else {
readView.upContent(resetPageOffset = false)
}
binding.readMenu.reset()
}
observeEvent<Int>(EventBus.ALOUD_STATE) {
if (it == Status.STOP || it == Status.PAUSE) {
@ -1253,6 +1255,9 @@ class ReadBookActivity : BaseReadBookActivity(),
observeEvent<List<SearchResult>>(EventBus.SEARCH_RESULT) {
viewModel.searchResultList = it
}
observeEvent<Boolean>(PreferKey.updateReadActionBar){
binding.readMenu.reset()
}
}
private fun upScreenTimeOut() {

View File

@ -3,6 +3,7 @@ package io.legado.app.ui.book.read
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet
import android.view.Gravity
@ -14,8 +15,7 @@ import android.view.animation.Animation
import android.widget.FrameLayout
import android.widget.SeekBar
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.*
import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.databinding.ViewReadMenuBinding
@ -55,12 +55,24 @@ class ReadMenu @JvmOverloads constructor(
private val menuBottomOut: Animation by lazy {
loadAnimation(context, R.anim.anim_readbook_bottom_out)
}
private val bgColor: Int = context.bottomBackground
private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
private val bottomBackgroundList: ColorStateList = Selector.colorBuild()
.setDefaultColor(bgColor)
.setPressedColor(ColorUtils.darkenColor(bgColor))
.create()
private val bgColor: Int
get() = if(AppConfig.readBarStyleFollowPage && ReadBookConfig.durConfig.curBgType() == 0){
Color.parseColor(ReadBookConfig.durConfig.curBgStr())
}else{
context.bottomBackground
}
private val textColor: Int
get() = if(AppConfig.readBarStyleFollowPage && ReadBookConfig.durConfig.curBgType() == 0){
ReadBookConfig.durConfig.curTextColor()
}else{
context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
}
private val bottomBackgroundList: ColorStateList
get() = Selector.colorBuild()
.setDefaultColor(bgColor)
.setPressedColor(ColorUtils.darkenColor(bgColor))
.create()
private var onMenuOutEnd: (() -> Unit)? = null
private val showBrightnessView
get() = context.getPrefBoolean(
@ -145,6 +157,15 @@ class ReadMenu @JvmOverloads constructor(
fabNightTheme.setImageResource(R.drawable.ic_brightness)
}
initAnimation()
val bgColor = this@ReadMenu.bgColor
val textColor = this@ReadMenu.textColor
val bottomBackgroundList = this@ReadMenu.bottomBackgroundList
val lightTextColor = ColorUtils.lightenColor(textColor)
titleBar.setTextColor(textColor)
titleBar.setBackgroundColor(bgColor)
titleBar.setColorFilter(textColor)
tvChapterName.setTextColor(lightTextColor)
tvChapterUrl.setTextColor(lightTextColor)
val brightnessBackground = GradientDrawable()
brightnessBackground.cornerRadius = 5F.dpToPx()
brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f))
@ -173,6 +194,19 @@ class ReadMenu @JvmOverloads constructor(
seekBrightness.post {
seekBrightness.progress = AppConfig.readBrightness
}
if(AppConfig.showReadTitleBarAddition){
titleBarAddition.visible()
}else{
titleBarAddition.gone()
}
}
fun reset(){
initView()
}
fun refreshMenuColorFilter(){
binding.titleBar.setColorFilter(textColor)
}
fun upBrightnessState() {

View File

@ -133,6 +133,10 @@ class MoreConfigDialog : DialogFragment() {
ChapterProvider.upLayout()
ReadBook.loadContent(false)
}
PreferKey.showReadTitleAddition,
PreferKey.readBarStyleFollowPage -> {
postEvent(PreferKey.updateReadActionBar,true)
}
}
}

View File

@ -3,12 +3,16 @@ package io.legado.app.ui.widget
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.util.AttributeSet
import android.view.Menu
import android.view.View
import android.widget.ImageView
import androidx.annotation.ColorInt
import androidx.annotation.StyleRes
import androidx.appcompat.widget.Toolbar
import androidx.core.view.children
import com.google.android.material.appbar.AppBarLayout
import io.legado.app.R
import io.legado.app.lib.theme.elevation
@ -192,6 +196,21 @@ class TitleBar @JvmOverloads constructor(
toolbar.setSubtitleTextAppearance(context, resId)
}
fun setTextColor(@ColorInt color: Int){
setTitleTextColor(color)
setSubTitleTextColor(color)
}
fun setColorFilter(@ColorInt color: Int){
val colorFilter = PorterDuffColorFilter(color,PorterDuff.Mode.SRC_ATOP)
toolbar.children.firstOrNull { it is ImageView }?.background?.colorFilter = colorFilter
toolbar.navigationIcon?.colorFilter = colorFilter
toolbar.overflowIcon?.colorFilter = colorFilter
toolbar.menu.children.forEach{
it.icon?.colorFilter = colorFilter
}
}
fun transparent() {
elevation = 0f
setBackgroundColor(Color.TRANSPARENT)

View File

@ -22,6 +22,7 @@
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/title_bar_addition"
android:layout_width="match_parent"
android:layout_height="wrap_content">

View File

@ -1012,4 +1012,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">show read title addition area</string>
<string name="read_bar_style_follow_page">read bar style follow page</string>
</resources>

View File

@ -1015,4 +1015,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">show read title addition area</string>
<string name="read_bar_style_follow_page">read bar style follow page</string>
</resources>

View File

@ -1015,4 +1015,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">show read title addition area</string>
<string name="read_bar_style_follow_page">read bar style follow page</string>
</resources>

View File

@ -1012,4 +1012,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">展示顶部工具栏附加区域</string>
<string name="read_bar_style_follow_page">工具栏样式跟随页面</string>
</resources>

View File

@ -1014,4 +1014,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">展示顶部工具栏附加区域</string>
<string name="read_bar_style_follow_page">工具栏样式跟随页面</string>
</resources>

View File

@ -1014,4 +1014,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">展示顶部工具栏附加区域</string>
<string name="read_bar_style_follow_page">工具栏样式跟随页面</string>
</resources>

View File

@ -1015,4 +1015,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">show read title addition area</string>
<string name="read_bar_style_follow_page">read bar style follow page</string>
</resources>

View File

@ -146,4 +146,13 @@
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="true"
android:key="showReadTitleAddition"
android:title="@string/show_read_title_addition"/>
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="readBarStyleFollowPage"
android:title="@string/read_bar_style_follow_page"/>
</androidx.preference.PreferenceScreen>

View File

@ -27,3 +27,5 @@ android.experimental.enableNewResourceShrinker.preciseShrinking=true
android.nonTransitiveRClass=true
#https://chromiumdash.appspot.com/releases?platform=Android
CronetVersion=105.0.5195.79
android.injected.testOnly=false