diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index f468e3e7fc..b956acadc2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -216,36 +216,38 @@ open class MainActivity : BaseActivity(), DownloadServiceLi nav.isVisible = false content.doOnApplyWindowInsetsCompat { v, insets, _ -> setNavBarColor(insets) + val systemInsets = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + insets.getInsetsIgnoringVisibility(systemBars()) + } else { + insets.getInsets(systemBars()) + } val contextView = window?.decorView?.findViewById(R.id.action_mode_bar) contextView?.updateLayoutParams { - leftMargin = insets.getInsetsIgnoringVisibility(systemBars()).left - rightMargin = insets.getInsetsIgnoringVisibility(systemBars()).right + leftMargin = systemInsets.left + rightMargin = systemInsets.right } // Consume any horizontal insets and pad all content in. There's not much we can do // with horizontal insets v.updatePadding( - left = insets.getInsetsIgnoringVisibility(systemBars()).left, - right = insets.getInsetsIgnoringVisibility(systemBars()).right + left = systemInsets.left, + right = systemInsets.right ) binding.appBar.updatePadding( - top = insets.getInsetsIgnoringVisibility(systemBars()).top + top = systemInsets.top ) binding.bottomNav?.updatePadding( - bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - insets.getInsetsIgnoringVisibility(systemBars()).bottom - } else { - insets.getInsets(systemBars()).bottom - } + bottom = systemInsets.bottom ) binding.sideNav?.updatePadding( left = 0, right = 0, - bottom = insets.getInsetsIgnoringVisibility(systemBars()).bottom, - top = insets.getInsetsIgnoringVisibility(systemBars()).top + bottom = systemInsets.bottom, + top = systemInsets.top ) - binding.bottomView?.isVisible = insets.getInsetsIgnoringVisibility(systemBars()).bottom > 0 + binding.bottomView?.isVisible = systemInsets.bottom > 0 binding.bottomView?.updateLayoutParams { - height = insets.getInsetsIgnoringVisibility(systemBars()).bottom + height = systemInsets.bottom } } // Set this as nav view will try to set its own insets and they're hilariously bad diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index f40d8b9aaf..4b7d053721 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -759,6 +759,12 @@ class ReaderActivity : BaseRxActivity() { var firstPass = true binding.readerLayout.doOnApplyWindowInsetsCompat { _, insets, _ -> setNavColor(insets) + val systemInsets = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + insets.getInsetsIgnoringVisibility(systemBars()) + } else { + insets.getInsets(systemBars()) + } val vis = insets.isVisible(statusBars()) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (!firstPass && lastVis != vis && preferences.fullscreen().get()) { @@ -772,20 +778,20 @@ class ReaderActivity : BaseRxActivity() { window.navigationBarColor = getResourceColor(R.attr.colorSurface) } binding.appBar.updateLayoutParams { - leftMargin = insets.getInsetsIgnoringVisibility(systemBars()).left - rightMargin = insets.getInsetsIgnoringVisibility(systemBars()).right + leftMargin = systemInsets.left + rightMargin = systemInsets.right } binding.toolbar.updateLayoutParams { - topMargin = insets.getInsetsIgnoringVisibility(systemBars()).top + topMargin = systemInsets.top } binding.chaptersSheet.chaptersBottomSheet.updateLayoutParams { - leftMargin = insets.getInsetsIgnoringVisibility(systemBars()).left - rightMargin = insets.getInsetsIgnoringVisibility(systemBars()).right - height = 280.dpToPx + insets.getInsetsIgnoringVisibility(systemBars()).bottom + leftMargin = systemInsets.left + rightMargin = systemInsets.right + height = 280.dpToPx + systemInsets.bottom } binding.navLayout.updateLayoutParams { - leftMargin = 12.dpToPx + insets.getInsetsIgnoringVisibility(systemBars()).left - rightMargin = 12.dpToPx + insets.getInsetsIgnoringVisibility(systemBars()).right + leftMargin = 12.dpToPx + systemInsets.left + rightMargin = 12.dpToPx + systemInsets.right } binding.chaptersSheet.root.sheetBehavior?.peekHeight = peek + if (preferences.fullscreen().get()) { @@ -798,7 +804,7 @@ class ReaderActivity : BaseRxActivity() { rootInsets.getInsetsIgnoringVisibility(systemBars()).bottom ) } - binding.chaptersSheet.chapterRecycler.updatePaddingRelative(bottom = insets.getInsetsIgnoringVisibility(systemBars()).bottom) + binding.chaptersSheet.chapterRecycler.updatePaddingRelative(bottom = systemInsets.bottom) binding.viewerContainer.requestLayout() } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/WindowInsetsExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/WindowInsetsExtensions.kt index f5a6bec9ef..52d8e09d17 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/WindowInsetsExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/WindowInsetsExtensions.kt @@ -15,14 +15,17 @@ fun WindowInsetsCompat.getBottomGestureInsets(): Int { /** returns if device using gesture nav and supports true edge to edge */ fun WindowInsetsCompat.isBottomTappable() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && - getInsets(systemBars()).bottom != getInsets(mandatorySystemGestures()).bottom + getInsetsIgnoringVisibility(systemBars()).bottom != getInsetsIgnoringVisibility(mandatorySystemGestures()).bottom val View.rootWindowInsetsCompat get() = rootWindowInsets?.let { WindowInsetsCompat.toWindowInsetsCompat(it) } fun WindowInsetsCompat.hasSideNavBar() = - (getInsets(systemBars()).left > 0 || getInsets(systemBars()).right > 0) && !isBottomTappable() && - getInsets(systemBars()).bottom == 0 + ( + getInsetsIgnoringVisibility(systemBars()).left > 0 || + getInsetsIgnoringVisibility(systemBars()).right > 0 + ) && !isBottomTappable() && + getInsetsIgnoringVisibility(systemBars()).bottom == 0 @RequiresApi(Build.VERSION_CODES.R) fun WindowInsetsCompat.isImeVisible() = isVisible(WindowInsetsCompat.Type.ime())