mirror of
https://github.com/gedoor/legado.git
synced 2025-01-08 11:47:32 +08:00
优化
This commit is contained in:
parent
e389185022
commit
06d247b849
@ -12,7 +12,6 @@ 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
|
||||
@ -20,6 +19,7 @@ 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 io.legado.app.utils.setBackgroundKeepPadding
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
@ -40,31 +40,25 @@ abstract class BaseDialogFragment(
|
||||
super.onStart()
|
||||
if (adaptationSoftKeyboard) {
|
||||
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
|
||||
}
|
||||
if (AppConfig.isEInkMode) {
|
||||
} else 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)
|
||||
it.decorView.setBackgroundKeepPadding(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)
|
||||
}
|
||||
lifecycle.addObserver(LifecycleEventObserver { _, 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ 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
|
||||
@ -27,20 +26,15 @@ abstract class BasePrefDialogFragment(
|
||||
}
|
||||
|
||||
// 修改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)
|
||||
}
|
||||
lifecycle.addObserver(LifecycleEventObserver { _, 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ import android.graphics.drawable.Drawable
|
||||
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
|
||||
import io.legado.app.utils.applyTint
|
||||
|
||||
internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<AlertDialog> {
|
||||
private val builder = AlertDialog.Builder(ctx)
|
||||
@ -144,8 +144,13 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
|
||||
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)
|
||||
dialog.window?.run {
|
||||
val attr = attributes
|
||||
attr.dimAmount = 0f
|
||||
attr.windowAnimations = 0
|
||||
attributes = attr
|
||||
setBackgroundDrawableResource(R.drawable.bg_eink_border_dialog)
|
||||
}
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
@ -153,8 +158,13 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
|
||||
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)
|
||||
dialog.window?.run {
|
||||
val attr = attributes
|
||||
attr.dimAmount = 0f
|
||||
attr.windowAnimations = 0
|
||||
attributes = attr
|
||||
setBackgroundDrawableResource(R.drawable.bg_eink_border_dialog)
|
||||
}
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import io.legado.app.data.entities.SearchBook
|
||||
import io.legado.app.databinding.DialogBookChangeSourceBinding
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.elevation
|
||||
import io.legado.app.lib.theme.getPrimaryTextColor
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.ui.book.read.ReadBookActivity
|
||||
@ -123,7 +124,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()
|
||||
binding.toolBar.elevation = requireContext().elevation
|
||||
}
|
||||
|
||||
private fun initMenu() {
|
||||
|
@ -27,7 +27,6 @@ import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.dialogs.selector
|
||||
import io.legado.app.lib.theme.ThemeStore
|
||||
import io.legado.app.lib.theme.backgroundColor
|
||||
import io.legado.app.lib.theme.bottomBackground
|
||||
import io.legado.app.model.CacheBook
|
||||
import io.legado.app.model.ReadBook
|
||||
@ -320,7 +319,6 @@ abstract class BaseReadBookActivity :
|
||||
ReadBook.book?.let { book ->
|
||||
alert(titleResource = R.string.simulated_reading) {
|
||||
val alertBinding = DialogSimulatedReadingBinding.inflate(layoutInflater).apply {
|
||||
root.setBackgroundColor(root.context.backgroundColor)
|
||||
srEnabled.isChecked = book.getReadSimulating()
|
||||
editStart.setText(book.getStartChapter().toString())
|
||||
editNum.setText(book.getDailyChapters().toString())
|
||||
|
@ -31,7 +31,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setLayout(0.9f, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -19,6 +19,7 @@ import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.children
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import io.legado.app.R
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.lib.theme.elevation
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.utils.activity
|
||||
@ -176,7 +177,11 @@ class TitleBar @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
setBackgroundColor(context.primaryColor)
|
||||
if (AppConfig.isEInkMode) {
|
||||
setBackgroundResource(R.drawable.bg_eink_border_bottom)
|
||||
} else {
|
||||
setBackgroundColor(context.primaryColor)
|
||||
}
|
||||
|
||||
stateListAnimator = null
|
||||
elevation = context.elevation
|
||||
|
@ -23,6 +23,7 @@ import android.widget.RadioGroup
|
||||
import android.widget.SeekBar
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.menu.MenuPopupHelper
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
@ -277,3 +278,12 @@ fun View.applyNavigationBarPadding(withInitialPadding: Boolean = false) {
|
||||
windowInsets
|
||||
}
|
||||
}
|
||||
|
||||
fun View.setBackgroundKeepPadding(@DrawableRes backgroundResId: Int) {
|
||||
val paddingLeft = paddingLeft
|
||||
val paddingTop = paddingTop
|
||||
val paddingRight = paddingRight
|
||||
val paddingBottom = paddingBottom
|
||||
setBackgroundResource(backgroundResId)
|
||||
setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user