From 7c838a71d9109050875e1996bb25b659b1600045 Mon Sep 17 00:00:00 2001 From: XieJC Date: Thu, 8 Sep 2022 10:14:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=B7=A5=E5=85=B7=E6=A0=8F?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 4 +- .../io/legado/app/help/config/AppConfig.kt | 11 ++++ .../app/ui/book/read/ReadBookActivity.kt | 5 ++ .../io/legado/app/ui/book/read/ReadMenu.kt | 50 ++++++++++++++++--- .../ui/book/read/config/MoreConfigDialog.kt | 4 ++ .../java/io/legado/app/ui/widget/TitleBar.kt | 19 +++++++ app/src/main/res/layout/view_read_menu.xml | 1 + app/src/main/res/values-es-rES/strings.xml | 2 + app/src/main/res/values-ja-rJP/strings.xml | 2 + app/src/main/res/values-pt-rBR/strings.xml | 2 + app/src/main/res/values-zh-rHK/strings.xml | 2 + app/src/main/res/values-zh-rTW/strings.xml | 2 + app/src/main/res/values-zh/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/pref_config_read.xml | 9 ++++ gradle.properties | 2 + 16 files changed, 110 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index b1bbf3663..a83c7ae9f 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -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" } diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt index 60ea20f46..b339af4aa 100644 --- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt @@ -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) + } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index c4a97a1ce..fe9a6ded7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -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(EventBus.ALOUD_STATE) { if (it == Status.STOP || it == Status.PAUSE) { @@ -1253,6 +1255,9 @@ class ReadBookActivity : BaseReadBookActivity(), observeEvent>(EventBus.SEARCH_RESULT) { viewModel.searchResultList = it } + observeEvent(PreferKey.updateReadActionBar){ + binding.readMenu.reset() + } } private fun upScreenTimeOut() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index bc743164c..1d6e29d56 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -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() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 18a452c3b..d819026ab 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -133,6 +133,10 @@ class MoreConfigDialog : DialogFragment() { ChapterProvider.upLayout() ReadBook.loadContent(false) } + PreferKey.showReadTitleAddition, + PreferKey.readBarStyleFollowPage -> { + postEvent(PreferKey.updateReadActionBar,true) + } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 225a91850..bcffe65f1 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -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) diff --git a/app/src/main/res/layout/view_read_menu.xml b/app/src/main/res/layout/view_read_menu.xml index 9b5a91876..ca8160cad 100644 --- a/app/src/main/res/layout/view_read_menu.xml +++ b/app/src/main/res/layout/view_read_menu.xml @@ -22,6 +22,7 @@ app:layout_constraintTop_toTopOf="parent"> diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index acad14f1c..cfd9ff9c2 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1012,4 +1012,6 @@ 阅读未放入书架的书籍在返回时提示放入书架 标志:发现已启用 标志:发现已禁用 + show read title addition area + read bar style follow page diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index c6c3c0521..aedfeae99 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1015,4 +1015,6 @@ 阅读未放入书架的书籍在返回时提示放入书架 标志:发现已启用 标志:发现已禁用 + show read title addition area + read bar style follow page diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index d126d2470..84e8ec0df 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1015,4 +1015,6 @@ 阅读未放入书架的书籍在返回时提示放入书架 标志:发现已启用 标志:发现已禁用 + show read title addition area + read bar style follow page diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 518017c67..f74ba349d 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1012,4 +1012,6 @@ 阅读未放入书架的书籍在返回时提示放入书架 标志:发现已启用 标志:发现已禁用 + 展示顶部工具栏附加区域 + 工具栏样式跟随页面 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index eb43ecdbc..480bad8c9 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1014,4 +1014,6 @@ 阅读未放入书架的书籍在返回时提示放入书架 标志:发现已启用 标志:发现已禁用 + 展示顶部工具栏附加区域 + 工具栏样式跟随页面 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index db2a80a04..8515e27fe 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1014,4 +1014,6 @@ 阅读未放入书架的书籍在返回时提示放入书架 标志:发现已启用 标志:发现已禁用 + 展示顶部工具栏附加区域 + 工具栏样式跟随页面 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f78e4c912..1664e0621 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1015,4 +1015,6 @@ 阅读未放入书架的书籍在返回时提示放入书架 标志:发现已启用 标志:发现已禁用 + show read title addition area + read bar style follow page diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 0ee6ad6fd..8d4a3cda9 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -146,4 +146,13 @@ app:iconSpaceReserved="false" app:isBottomBackground="true" /> + + + \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index cff0bf657..84acaf1c4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file