No longer using getInsetsIgnoringVisibility for Android 10 and below

so those with samsung hacks for hiding elements should be happy

Fixes #1048
This commit is contained in:
Jays2Kings 2021-10-17 03:57:46 -04:00
parent a98149f7a6
commit 134c2552f9
3 changed files with 37 additions and 26 deletions

View file

@ -216,36 +216,38 @@ open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceLi
nav.isVisible = false nav.isVisible = false
content.doOnApplyWindowInsetsCompat { v, insets, _ -> content.doOnApplyWindowInsetsCompat { v, insets, _ ->
setNavBarColor(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<View>(R.id.action_mode_bar) val contextView = window?.decorView?.findViewById<View>(R.id.action_mode_bar)
contextView?.updateLayoutParams<ViewGroup.MarginLayoutParams> { contextView?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.getInsetsIgnoringVisibility(systemBars()).left leftMargin = systemInsets.left
rightMargin = insets.getInsetsIgnoringVisibility(systemBars()).right rightMargin = systemInsets.right
} }
// Consume any horizontal insets and pad all content in. There's not much we can do // Consume any horizontal insets and pad all content in. There's not much we can do
// with horizontal insets // with horizontal insets
v.updatePadding( v.updatePadding(
left = insets.getInsetsIgnoringVisibility(systemBars()).left, left = systemInsets.left,
right = insets.getInsetsIgnoringVisibility(systemBars()).right right = systemInsets.right
) )
binding.appBar.updatePadding( binding.appBar.updatePadding(
top = insets.getInsetsIgnoringVisibility(systemBars()).top top = systemInsets.top
) )
binding.bottomNav?.updatePadding( binding.bottomNav?.updatePadding(
bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { bottom = systemInsets.bottom
insets.getInsetsIgnoringVisibility(systemBars()).bottom
} else {
insets.getInsets(systemBars()).bottom
}
) )
binding.sideNav?.updatePadding( binding.sideNav?.updatePadding(
left = 0, left = 0,
right = 0, right = 0,
bottom = insets.getInsetsIgnoringVisibility(systemBars()).bottom, bottom = systemInsets.bottom,
top = insets.getInsetsIgnoringVisibility(systemBars()).top top = systemInsets.top
) )
binding.bottomView?.isVisible = insets.getInsetsIgnoringVisibility(systemBars()).bottom > 0 binding.bottomView?.isVisible = systemInsets.bottom > 0
binding.bottomView?.updateLayoutParams<ViewGroup.LayoutParams> { binding.bottomView?.updateLayoutParams<ViewGroup.LayoutParams> {
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 // Set this as nav view will try to set its own insets and they're hilariously bad

View file

@ -759,6 +759,12 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
var firstPass = true var firstPass = true
binding.readerLayout.doOnApplyWindowInsetsCompat { _, insets, _ -> binding.readerLayout.doOnApplyWindowInsetsCompat { _, insets, _ ->
setNavColor(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()) val vis = insets.isVisible(statusBars())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!firstPass && lastVis != vis && preferences.fullscreen().get()) { if (!firstPass && lastVis != vis && preferences.fullscreen().get()) {
@ -772,20 +778,20 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
window.navigationBarColor = getResourceColor(R.attr.colorSurface) window.navigationBarColor = getResourceColor(R.attr.colorSurface)
} }
binding.appBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.appBar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.getInsetsIgnoringVisibility(systemBars()).left leftMargin = systemInsets.left
rightMargin = insets.getInsetsIgnoringVisibility(systemBars()).right rightMargin = systemInsets.right
} }
binding.toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.getInsetsIgnoringVisibility(systemBars()).top topMargin = systemInsets.top
} }
binding.chaptersSheet.chaptersBottomSheet.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.chaptersSheet.chaptersBottomSheet.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.getInsetsIgnoringVisibility(systemBars()).left leftMargin = systemInsets.left
rightMargin = insets.getInsetsIgnoringVisibility(systemBars()).right rightMargin = systemInsets.right
height = 280.dpToPx + insets.getInsetsIgnoringVisibility(systemBars()).bottom height = 280.dpToPx + systemInsets.bottom
} }
binding.navLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.navLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = 12.dpToPx + insets.getInsetsIgnoringVisibility(systemBars()).left leftMargin = 12.dpToPx + systemInsets.left
rightMargin = 12.dpToPx + insets.getInsetsIgnoringVisibility(systemBars()).right rightMargin = 12.dpToPx + systemInsets.right
} }
binding.chaptersSheet.root.sheetBehavior?.peekHeight = binding.chaptersSheet.root.sheetBehavior?.peekHeight =
peek + if (preferences.fullscreen().get()) { peek + if (preferences.fullscreen().get()) {
@ -798,7 +804,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
rootInsets.getInsetsIgnoringVisibility(systemBars()).bottom rootInsets.getInsetsIgnoringVisibility(systemBars()).bottom
) )
} }
binding.chaptersSheet.chapterRecycler.updatePaddingRelative(bottom = insets.getInsetsIgnoringVisibility(systemBars()).bottom) binding.chaptersSheet.chapterRecycler.updatePaddingRelative(bottom = systemInsets.bottom)
binding.viewerContainer.requestLayout() binding.viewerContainer.requestLayout()
} }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {

View file

@ -15,14 +15,17 @@ fun WindowInsetsCompat.getBottomGestureInsets(): Int {
/** returns if device using gesture nav and supports true edge to edge */ /** returns if device using gesture nav and supports true edge to edge */
fun WindowInsetsCompat.isBottomTappable() = fun WindowInsetsCompat.isBottomTappable() =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
getInsets(systemBars()).bottom != getInsets(mandatorySystemGestures()).bottom getInsetsIgnoringVisibility(systemBars()).bottom != getInsetsIgnoringVisibility(mandatorySystemGestures()).bottom
val View.rootWindowInsetsCompat val View.rootWindowInsetsCompat
get() = rootWindowInsets?.let { WindowInsetsCompat.toWindowInsetsCompat(it) } get() = rootWindowInsets?.let { WindowInsetsCompat.toWindowInsetsCompat(it) }
fun WindowInsetsCompat.hasSideNavBar() = 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) @RequiresApi(Build.VERSION_CODES.R)
fun WindowInsetsCompat.isImeVisible() = isVisible(WindowInsetsCompat.Type.ime()) fun WindowInsetsCompat.isImeVisible() = isVisible(WindowInsetsCompat.Type.ime())