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
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<View>(R.id.action_mode_bar)
contextView?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
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<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

View file

@ -759,6 +759,12 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
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<ReaderPresenter>() {
window.navigationBarColor = getResourceColor(R.attr.colorSurface)
}
binding.appBar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.getInsetsIgnoringVisibility(systemBars()).left
rightMargin = insets.getInsetsIgnoringVisibility(systemBars()).right
leftMargin = systemInsets.left
rightMargin = systemInsets.right
}
binding.toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.getInsetsIgnoringVisibility(systemBars()).top
topMargin = systemInsets.top
}
binding.chaptersSheet.chaptersBottomSheet.updateLayoutParams<ViewGroup.MarginLayoutParams> {
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<ViewGroup.MarginLayoutParams> {
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<ReaderPresenter>() {
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) {

View file

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