阅读工具栏更多自定义

pull/2253/head
XieJC 2 years ago
parent 7e0e6f5b0a
commit 7c838a71d9
  1. 4
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 11
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 44
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  6. 19
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  7. 1
      app/src/main/res/layout/view_read_menu.xml
  8. 2
      app/src/main/res/values-es-rES/strings.xml
  9. 2
      app/src/main/res/values-ja-rJP/strings.xml
  10. 2
      app/src/main/res/values-pt-rBR/strings.xml
  11. 2
      app/src/main/res/values-zh-rHK/strings.xml
  12. 2
      app/src/main/res/values-zh-rTW/strings.xml
  13. 2
      app/src/main/res/values-zh/strings.xml
  14. 2
      app/src/main/res/values/strings.xml
  15. 9
      app/src/main/res/xml/pref_config_read.xml
  16. 2
      gradle.properties

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

@ -342,5 +342,16 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
set(value) { set(value) {
appCtx.putPrefInt(PreferKey.bitmapCacheSize, 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)
}
} }

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

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

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

@ -3,12 +3,16 @@ package io.legado.app.ui.widget
import android.content.Context import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.util.AttributeSet import android.util.AttributeSet
import android.view.Menu import android.view.Menu
import android.view.View import android.view.View
import android.widget.ImageView
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.StyleRes import androidx.annotation.StyleRes
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.view.children
import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.AppBarLayout
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.elevation import io.legado.app.lib.theme.elevation
@ -192,6 +196,21 @@ class TitleBar @JvmOverloads constructor(
toolbar.setSubtitleTextAppearance(context, resId) 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() { fun transparent() {
elevation = 0f elevation = 0f
setBackgroundColor(Color.TRANSPARENT) setBackgroundColor(Color.TRANSPARENT)

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

@ -1012,4 +1012,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string> <string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</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> </resources>

@ -1015,4 +1015,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string> <string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</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> </resources>

@ -1015,4 +1015,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string> <string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</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> </resources>

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

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

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

@ -1015,4 +1015,6 @@
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="tag_explore_enabled">标志:发现已启用</string> <string name="tag_explore_enabled">标志:发现已启用</string>
<string name="tag_explore_disabled">标志:发现已禁用</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> </resources>

@ -146,4 +146,13 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:isBottomBackground="true" /> 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> </androidx.preference.PreferenceScreen>

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