diff --git a/app/src/main/java/io/legado/app/ui/book/read/BaseReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/BaseReadBookActivity.kt index 339c16e20..0e1c7b603 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/BaseReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/BaseReadBookActivity.kt @@ -279,10 +279,13 @@ abstract class BaseReadBookActivity : * 适配刘海 */ private fun upLayoutInDisplayCutoutMode() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ReadBookConfig.readBodyToLh) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { window.attributes = window.attributes.apply { - layoutInDisplayCutoutMode = + layoutInDisplayCutoutMode = if (ReadBookConfig.readBodyToLh) { WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + } else { + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER + } } } } 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 a008328c3..3ba1e8057 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 @@ -112,7 +112,7 @@ class MoreConfigDialog : DialogFragment() { PreferKey.readBodyToLh -> activity?.recreate() PreferKey.hideStatusBar -> { ReadBookConfig.hideStatusBar = getPrefBoolean(PreferKey.hideStatusBar) - postEvent(EventBus.UP_CONFIG, arrayListOf(0)) + postEvent(EventBus.UP_CONFIG, arrayListOf(0, 2)) } PreferKey.hideNavigationBar -> { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 59ef446f7..05e07bebd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -5,6 +5,8 @@ import android.content.Context import android.view.LayoutInflater import android.widget.FrameLayout import androidx.core.content.ContextCompat +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat import androidx.core.view.isGone import androidx.core.view.isInvisible import io.legado.app.R @@ -24,8 +26,8 @@ import io.legado.app.utils.activity import io.legado.app.utils.dpToPx import io.legado.app.utils.gone import io.legado.app.utils.setTextIfNotEqual -import io.legado.app.utils.statusBarHeight import splitties.views.backgroundColor +import splitties.views.topPadding import java.util.Date /** @@ -52,7 +54,7 @@ class PageView(context: Context) : FrameLayout(context) { val headerHeight: Int get() { - val h1 = if (ReadBookConfig.hideStatusBar) 0 else context.statusBarHeight + val h1 = if (binding.vwStatusBar.isGone) 0 else binding.vwStatusBar.height val h2 = if (binding.llHeader.isGone) 0 else binding.llHeader.height return h1 + h2 } @@ -60,6 +62,11 @@ class PageView(context: Context) : FrameLayout(context) { init { if (!isInEditMode) { upStyle() + ViewCompat.setOnApplyWindowInsetsListener(this) { _, windowInsets -> + val insets = windowInsets.getInsets(WindowInsetsCompat.Type.statusBars()) + binding.vwStatusBar.topPadding = insets.top + windowInsets + } } } @@ -114,7 +121,7 @@ class PageView(context: Context) : FrameLayout(context) { * 显示状态栏时隐藏header */ fun upStatusBar() = with(binding.vwStatusBar) { - setPadding(paddingLeft, context.statusBarHeight, paddingRight, paddingBottom) +// setPadding(paddingLeft, context.statusBarHeight, paddingRight, paddingBottom) isGone = ReadBookConfig.hideStatusBar || readBookActivity?.isInMultiWindow == 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 bf5126cb2..72c0cb1a2 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 @@ -14,14 +14,16 @@ import androidx.annotation.ColorInt import androidx.annotation.StyleRes import androidx.appcompat.widget.Toolbar import androidx.core.graphics.alpha +import androidx.core.view.ViewCompat +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.lib.theme.elevation import io.legado.app.lib.theme.primaryColor import io.legado.app.utils.activity -import io.legado.app.utils.navigationBarHeight -import io.legado.app.utils.statusBarHeight +import splitties.views.bottomPadding +import splitties.views.topPadding @Suppress("unused", "MemberVisibilityCanBePrivate") class TitleBar @JvmOverloads constructor( @@ -153,12 +155,25 @@ class TitleBar @JvmOverloads constructor( } if (!isInEditMode) { - if (fitStatusBar) { - setPadding(paddingLeft, context.statusBarHeight, paddingRight, paddingBottom) - } +// if (fitStatusBar) { +// setPadding(paddingLeft, context.statusBarHeight, paddingRight, paddingBottom) +// } +// +// if (fitNavigationBar) { +// setPadding(paddingLeft, paddingTop, paddingRight, context.navigationBarHeight) +// } - if (fitNavigationBar) { - setPadding(paddingLeft, paddingTop, paddingRight, context.navigationBarHeight) + if (fitStatusBar || fitNavigationBar) { + ViewCompat.setOnApplyWindowInsetsListener(this) { _, windowInsets -> + val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) + if (fitStatusBar) { + topPadding = insets.top + } + if (fitNavigationBar) { + bottomPadding = insets.bottom + } + windowInsets + } } setBackgroundColor(context.primaryColor) @@ -236,8 +251,10 @@ class TitleBar @JvmOverloads constructor( } fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, fullScreen: Boolean) { - val topPadding = if (!isInMultiWindowMode && fullScreen) context.statusBarHeight else 0 - setPadding(paddingLeft, topPadding, paddingRight, paddingBottom) +// if (fitStatusBar) { +// val topPadding = if (!isInMultiWindowMode && fullScreen) context.statusBarHeight else 0 +// setPadding(paddingLeft, topPadding, paddingRight, paddingBottom) +// } } private fun attachToActivity() {