This commit is contained in:
Horis 2024-08-29 09:41:27 +08:00
parent 83445ea071
commit b36c09674a
4 changed files with 42 additions and 15 deletions

View File

@ -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
}
}
}
}

View File

@ -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 -> {

View File

@ -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
}

View File

@ -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() {