优化Eink主题效果: 1.移除Eink主题时dialog及UI控件阴影; 2.Eink主题时dialog增加边框. (#4386)

* 优化Eink主题效果: 1.移除Eink主题时dialog及UI控件阴影; 2.Eink主题时dialog增加边框.

* fix: 2处与全局不一致的UI效果
This commit is contained in:
wyouflf 2024-11-30 18:18:21 +08:00 committed by GitHub
parent aeaed40933
commit b7db2a0494
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 273 additions and 22 deletions

View File

@ -4,15 +4,22 @@ import android.content.DialogInterface
import android.content.DialogInterface.OnDismissListener
import android.os.Build
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import androidx.annotation.LayoutRes
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import io.legado.app.R
import io.legado.app.constant.AppLog
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.dpToPx
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlin.coroutines.CoroutineContext
@ -34,6 +41,35 @@ abstract class BaseDialogFragment(
if (adaptationSoftKeyboard) {
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
}
if (AppConfig.isEInkMode) {
dialog?.window?.let {
it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
val attr = it.attributes
attr.dimAmount = 0.0f
attr.windowAnimations = 0
it.attributes = attr
it.setBackgroundDrawableResource(R.color.transparent)
}
// 修改gravity的时机一般在子类的onStart方法中, 因此需要在onStart之后执行.
this.lifecycle.addObserver(object : LifecycleEventObserver {
override fun onStateChanged(
source: LifecycleOwner,
event: Lifecycle.Event
) {
if (event == Lifecycle.Event.ON_START) {
when (dialog?.window?.attributes?.gravity) {
Gravity.TOP -> view?.setBackgroundResource(R.drawable.bg_eink_border_bottom)
Gravity.BOTTOM -> view?.setBackgroundResource(R.drawable.bg_eink_border_top)
else -> {
val padding = 2.dpToPx();
view?.setPadding(padding, padding, padding, padding)
view?.setBackgroundResource(R.drawable.bg_eink_border_dialog)
}
}
}
}
})
}
}
override fun onCreate(savedInstanceState: Bundle?) {
@ -49,7 +85,7 @@ abstract class BaseDialogFragment(
if (adaptationSoftKeyboard) {
view.findViewById<View>(R.id.vw_bg)?.setOnClickListener(null)
view.setOnClickListener { dismiss() }
} else {
} else if (!AppConfig.isEInkMode) {
view.setBackgroundColor(ThemeStore.backgroundColor())
}
onFragmentCreated(view, savedInstanceState)

View File

@ -0,0 +1,50 @@
package io.legado.app.base
import android.view.Gravity
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import io.legado.app.R
import io.legado.app.help.config.AppConfig
import io.legado.app.utils.dpToPx
abstract class BasePrefDialogFragment(
) : DialogFragment() {
override fun onStart() {
super.onStart()
if (AppConfig.isEInkMode) {
dialog?.window?.let {
it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
val attr = it.attributes
attr.dimAmount = 0.0f
attr.windowAnimations = 0
it.attributes = attr
it.setBackgroundDrawableResource(R.color.transparent)
}
// 修改gravity的时机一般在子类的onStart方法中, 因此需要在onStart之后执行.
this.lifecycle.addObserver(object : LifecycleEventObserver {
override fun onStateChanged(
source: LifecycleOwner,
event: Lifecycle.Event
) {
if (event == Lifecycle.Event.ON_START) {
when (dialog?.window?.attributes?.gravity) {
Gravity.TOP -> view?.setBackgroundResource(R.drawable.bg_eink_border_bottom)
Gravity.BOTTOM -> view?.setBackgroundResource(R.drawable.bg_eink_border_top)
else -> {
val padding = 2.dpToPx();
view?.setPadding(padding, padding, padding, padding)
view?.setBackgroundResource(R.drawable.bg_eink_border_dialog)
}
}
}
}
})
}
}
}

View File

@ -6,6 +6,7 @@ import android.provider.Settings
import androidx.annotation.Keep
import cn.hutool.crypto.digest.DigestUtil
import io.legado.app.BuildConfig
import io.legado.app.help.config.AppConfig
import io.legado.app.help.update.AppVariant
import splitties.init.appCtx
import java.text.SimpleDateFormat
@ -51,7 +52,7 @@ object AppConst {
)
@SuppressLint("PrivateResource")
val sysElevation = appCtx.resources
val sysElevation = if (AppConfig.isEInkMode) 0 else appCtx.resources
.getDimension(com.google.android.material.R.dimen.design_appbar_elevation)
.toInt()

View File

@ -290,7 +290,10 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
}
var elevation: Int
get() = appCtx.getPrefInt(PreferKey.barElevation, AppConst.sysElevation)
get() = if (isEInkMode) 0 else appCtx.getPrefInt(
PreferKey.barElevation,
AppConst.sysElevation
)
set(value) {
appCtx.putPrefInt(PreferKey.barElevation, value)
}

View File

@ -497,7 +497,7 @@ object ReadBookConfig {
private var textColorNight: String = "#ADADAD",//夜间文字颜色
private var textColorEInk: String = "#000000",
private var pageAnim: Int = 0,//翻页动画
private var pageAnimEInk: Int = 3,
private var pageAnimEInk: Int = 4,
var textFont: String = "",//字体
var textBold: Int = 0,//是否粗体字 0:正常, 1:粗体, 2:细体
var textSize: Int = 20,//文字大小

View File

@ -7,6 +7,8 @@ import android.view.KeyEvent
import android.view.View
import androidx.appcompat.app.AlertDialog
import io.legado.app.utils.applyTint
import io.legado.app.R
import io.legado.app.help.config.AppConfig
internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<AlertDialog> {
private val builder = AlertDialog.Builder(ctx)
@ -139,7 +141,21 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
}
}
override fun build(): AlertDialog = builder.create()
override fun build(): AlertDialog {
var dialog = builder.create()
if (AppConfig.isEInkMode) {
dialog.window?.setDimAmount(0f)
dialog.window?.decorView?.setBackgroundResource(R.drawable.bg_eink_border_dialog)
}
return dialog
}
override fun show(): AlertDialog = builder.show().applyTint()
override fun show(): AlertDialog {
var dialog = builder.show().applyTint()
if (AppConfig.isEInkMode) {
dialog.window?.setDimAmount(0f)
dialog.window?.decorView?.setBackgroundResource(R.drawable.bg_eink_border_dialog)
}
return dialog
}
}

View File

@ -2,11 +2,16 @@ package io.legado.app.lib.prefs
import android.app.Dialog
import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import androidx.preference.EditTextPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.R
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.filletBackground
import io.legado.app.utils.dpToPx
class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() {
@ -35,4 +40,27 @@ class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() {
return dialog
}
override fun onStart() {
super.onStart()
if (AppConfig.isEInkMode) {
dialog?.window?.let {
it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
val attr = it.attributes
attr.dimAmount = 0.0f
attr.windowAnimations = 0
it.attributes = attr
it.setBackgroundDrawableResource(R.color.transparent)
when (attr.gravity) {
Gravity.TOP -> it.decorView.setBackgroundResource(R.drawable.bg_eink_border_bottom)
Gravity.BOTTOM -> it.decorView.setBackgroundResource(R.drawable.bg_eink_border_top)
else -> {
val padding = 2.dpToPx();
it.decorView.setPadding(padding, padding, padding, padding)
it.decorView.setBackgroundResource(R.drawable.bg_eink_border_dialog)
}
}
}
}
}
}

View File

@ -2,13 +2,18 @@ package io.legado.app.lib.prefs
import android.app.Dialog
import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import androidx.core.view.forEach
import androidx.preference.ListPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.R
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.filletBackground
import io.legado.app.utils.applyTint
import io.legado.app.utils.dpToPx
class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() {
@ -40,4 +45,27 @@ class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() {
return dialog
}
override fun onStart() {
super.onStart()
if (AppConfig.isEInkMode) {
dialog?.window?.let {
it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
val attr = it.attributes
attr.dimAmount = 0.0f
attr.windowAnimations = 0
it.attributes = attr
it.setBackgroundDrawableResource(R.color.transparent)
when (attr.gravity) {
Gravity.TOP -> it.decorView.setBackgroundResource(R.drawable.bg_eink_border_bottom)
Gravity.BOTTOM -> it.decorView.setBackgroundResource(R.drawable.bg_eink_border_top)
else -> {
val padding = 2.dpToPx();
it.decorView.setPadding(padding, padding, padding, padding)
it.decorView.setBackgroundResource(R.drawable.bg_eink_border_dialog)
}
}
}
}
}
}

View File

@ -2,13 +2,18 @@ package io.legado.app.lib.prefs
import android.app.Dialog
import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import androidx.core.view.forEach
import androidx.preference.MultiSelectListPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.R
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.filletBackground
import io.legado.app.utils.applyTint
import io.legado.app.utils.dpToPx
class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentCompat() {
@ -42,5 +47,27 @@ class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentC
return dialog
}
override fun onStart() {
super.onStart()
if (AppConfig.isEInkMode) {
dialog?.window?.let {
it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
val attr = it.attributes
attr.dimAmount = 0.0f
attr.windowAnimations = 0
it.attributes = attr
it.setBackgroundDrawableResource(R.color.transparent)
when (attr.gravity) {
Gravity.TOP -> it.decorView.setBackgroundResource(R.drawable.bg_eink_border_bottom)
Gravity.BOTTOM -> it.decorView.setBackgroundResource(R.drawable.bg_eink_border_top)
else -> {
val padding = 2.dpToPx();
it.decorView.setPadding(padding, padding, padding, padding)
it.decorView.setBackgroundResource(R.drawable.bg_eink_border_dialog)
}
}
}
}
}
}

View File

@ -1,12 +1,14 @@
package io.legado.app.lib.theme.view
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.util.AttributeSet
import android.view.LayoutInflater
import com.google.android.material.bottomnavigation.BottomNavigationItemView
import com.google.android.material.bottomnavigation.BottomNavigationMenuView
import android.view.ViewGroup
import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.databinding.ViewNavigationBadgeBinding
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.bottomBackground
@ -27,13 +29,18 @@ class ThemeBottomNavigationVIew(context: Context, attrs: AttributeSet) :
.setSelectedColor(ThemeStore.accentColor(context)).create()
itemIconTintList = colorStateList
itemTextColor = colorStateList
if (AppConfig.isEInkMode) {
isItemHorizontalTranslationEnabled = false
itemBackground = ColorDrawable(Color.TRANSPARENT)
}
}
fun addBadgeView(index: Int): BadgeView {
//获取底部菜单view
val menuView = getChildAt(0) as BottomNavigationMenuView
val menuView = getChildAt(0) as ViewGroup
//获取第index个itemView
val itemView = menuView.getChildAt(index) as BottomNavigationItemView
val itemView = menuView.getChildAt(index) as ViewGroup
val badgeBinding = ViewNavigationBadgeBinding.inflate(LayoutInflater.from(context))
itemView.addView(badgeBinding.root)
return badgeBinding.viewBadge

View File

@ -17,6 +17,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.AppConst
import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
@ -122,6 +123,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
binding.toolBar.subtitle = viewModel.author
binding.toolBar.navigationIcon =
getCompatDrawable(androidx.appcompat.R.drawable.abc_ic_ab_back_material)
binding.toolBar.elevation = AppConfig.elevation.toFloat()
}
private fun initMenu() {

View File

@ -156,7 +156,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
binding.ivHideToc.setOnClickListener {
binding.clToc.gone()
}
binding.flHideToc.elevation = requireContext().elevation
binding.flHideToc.elevation = if (AppConfig.isEInkMode) 0f else requireContext().elevation
}
private fun initRecyclerView() {

View File

@ -295,7 +295,6 @@ abstract class BaseReadBookActivity :
ReadBook.book?.let { book ->
alert(titleResource = R.string.offline_cache) {
val alertBinding = DialogDownloadChoiceBinding.inflate(layoutInflater).apply {
root.setBackgroundColor(root.context.backgroundColor)
editStart.setText((book.durChapterIndex + 1).toString())
editEnd.setText(book.totalChapterNum.toString())
}

View File

@ -100,7 +100,7 @@ class ReadMenu @JvmOverloads constructor(
private val showBrightnessView
get() = context.getPrefBoolean(
PreferKey.showBrightnessView,
true
!AppConfig.isEInkMode
)
private val sourceMenu by lazy {
PopupMenu(context, binding.tvSourceAction).apply {
@ -202,7 +202,12 @@ class ReadMenu @JvmOverloads constructor(
brightnessBackground.cornerRadius = 5F.dpToPx()
brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f))
llBrightness.background = brightnessBackground
llBottomBg.setBackgroundColor(bgColor)
if(AppConfig.isEInkMode) {
titleBar.setBackgroundResource(R.drawable.bg_eink_border_bottom)
llBottomBg.setBackgroundResource(R.drawable.bg_eink_border_top)
} else {
llBottomBg.setBackgroundColor(bgColor)
}
fabSearch.backgroundTintList = bottomBackgroundList
fabSearch.setColorFilter(textColor)
fabAutoPage.backgroundTintList = bottomBackgroundList

View File

@ -11,9 +11,9 @@ import android.view.ViewConfiguration
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import androidx.preference.Preference
import io.legado.app.R
import io.legado.app.base.BasePrefDialogFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.config.AppConfig
@ -30,7 +30,7 @@ import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.postEvent
import io.legado.app.utils.setEdgeEffectColor
class MoreConfigDialog : DialogFragment() {
class MoreConfigDialog : BasePrefDialogFragment() {
private val readPreferTag = "readPreferenceFragment"
override fun onStart() {

View File

@ -6,10 +6,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import androidx.preference.ListPreference
import androidx.preference.Preference
import io.legado.app.R
import io.legado.app.base.BasePrefDialogFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
@ -30,7 +30,7 @@ import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.setLayout
import io.legado.app.utils.showDialogFragment
class ReadAloudConfigDialog : DialogFragment() {
class ReadAloudConfigDialog : BasePrefDialogFragment() {
private val readAloudPreferTag = "readAloudPreferTag"
override fun onStart() {

View File

@ -98,6 +98,11 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
}
}
}
if(AppConfig.isEInkMode) {
binding.vwBgFg1.visibility = View.INVISIBLE
binding.llBgTs.visibility = View.GONE
binding.rvStyle.visibility = View.GONE
}
}
private fun initData() {

View File

@ -31,7 +31,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
override fun onStart() {
super.onStart()
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
setLayout(0.9f, ViewGroup.LayoutParams.WRAP_CONTENT)
}
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {

View File

@ -96,6 +96,9 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
bottomNavigationView.elevation = elevation
bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity)
bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity)
if (AppConfig.isEInkMode) {
bottomNavigationView.setBackgroundResource(R.drawable.bg_eink_border_top)
}
}
upHomePage()
viewModel.deleteNotShelfBook()
@ -109,7 +112,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
return@addCallback
}
}
if (System.currentTimeMillis() - exitTime > 2000) {
if (!AppConfig.isEInkMode && System.currentTimeMillis() - exitTime > 2000) {
toastOnUi(R.string.double_click_exit)
exitTime = System.currentTimeMillis()
} else {

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<!-- 边框颜色 -->
<solid android:color="@color/divider" />
</shape>
</item>
<!-- 边框位置和粗细 -->
<item android:bottom="1dp">
<shape>
<!-- 背景颜色 -->
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<stroke
android:width="1dp"
android:color="@color/divider" />
<corners android:radius="2dp" />
</shape>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<!-- 边框颜色 -->
<solid android:color="@color/divider" />
</shape>
</item>
<!-- 边框位置和粗细 -->
<item android:top="1dp">
<shape>
<!-- 背景颜色 -->
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>

View File

@ -4,7 +4,6 @@
android:id="@+id/ll_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:gravity="center"
android:orientation="horizontal"
android:padding="16dp">

View File

@ -267,6 +267,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:id="@+id/ll_bg_ts"
android:orientation="horizontal">
<TextView

View File

@ -1,6 +1,7 @@
#Tue Aug 27 18:19:17 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://mirrors.aliyun.com/macports/distfiles/gradle/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists