diff --git a/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt b/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt index ea84a9ccaca6..da4ea99fac92 100644 --- a/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/base/BasePrefDialogFragment.kt b/app/src/main/java/io/legado/app/base/BasePrefDialogFragment.kt index 8f2f9be04579..db5f560c4848 100644 --- a/app/src/main/java/io/legado/app/base/BasePrefDialogFragment.kt +++ b/app/src/main/java/io/legado/app/base/BasePrefDialogFragment.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt b/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt index 1ab98be5182f..097726c2d493 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt @@ -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 { private val builder = AlertDialog.Builder(ctx) @@ -144,8 +144,13 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder 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()) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt index df5857c739bc..1a201e7dcaa6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt @@ -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?) { 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 72c0cb1a234d..6c44907cc08f 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 @@ -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 diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index 5e5aa66ea5b7..2fec77ab3a29 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -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) +}