Fixed navbar overlapping in settings

This commit is contained in:
Prathamesh More 2021-10-22 12:14:53 +05:30
parent d8aaa5a21b
commit 65d52776f8
2 changed files with 31 additions and 8 deletions

View file

@ -27,10 +27,8 @@ import android.widget.EditText
import androidx.annotation.LayoutRes
import androidx.core.animation.doOnEnd
import androidx.core.animation.doOnStart
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.*
import androidx.core.view.WindowInsetsCompat.Type.navigationBars
import androidx.core.view.updateLayoutParams
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.retromusic.util.PreferenceUtil
@ -138,11 +136,13 @@ fun ShapeableImageView.setCircleShape(boolean: Boolean) {
* This will draw our view above the navigation bar instead of behind it by adding margins.
*/
fun View.drawAboveNavBar() {
// Create a snapshot of the view's margin state
val initialMargin = recordInitialMarginForView(this)
ViewCompat.setOnApplyWindowInsetsListener(
(this)
) { v: View, insets: WindowInsetsCompat ->
v.updateLayoutParams<MarginLayoutParams> {
bottomMargin =
bottomMargin = initialMargin.bottom +
insets.getInsets(navigationBars()).bottom
}
insets
@ -153,11 +153,13 @@ fun View.drawAboveNavBar() {
* This will draw our view above the navigation bar instead of behind it by adding padding.
*/
fun View.drawAboveNavBarWithPadding() {
val initialPadding = recordInitialPaddingForView(this)
ViewCompat.setOnApplyWindowInsetsListener(
(this)
) { v: View, insets: WindowInsetsCompat ->
val navBarHeight = insets.getInsets(navigationBars()).bottom
v.updatePadding(bottom = navBarHeight)
v.updatePadding(bottom = initialPadding.bottom + navBarHeight)
insets
}
requestApplyInsetsWhenAttached()
@ -179,4 +181,19 @@ fun View.requestApplyInsetsWhenAttached() {
override fun onViewDetachedFromWindow(v: View) = Unit
})
}
}
}
data class InitialMargin(val left: Int, val top: Int,
val right: Int, val bottom: Int)
private fun recordInitialMarginForView(view: View) = InitialMargin(
view.marginLeft, view.marginTop, view.marginRight, view.marginBottom)
data class InitialPadding(val left: Int, val top: Int,
val right: Int, val bottom: Int)
private fun recordInitialPaddingForView(view: View) = InitialMargin(
view.paddingLeft, view.paddingTop, view.paddingRight, view.paddingBottom)

View file

@ -19,6 +19,7 @@ import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.core.view.updatePadding
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceManager
@ -26,6 +27,7 @@ import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragm
import code.name.monkey.retromusic.activities.OnThemeChangedListener
import code.name.monkey.retromusic.preferences.*
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.RetroUtil
/**
* @author Hemanth S (h4h13).
@ -65,8 +67,12 @@ abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
super.onViewCreated(view, savedInstanceState)
setDivider(ColorDrawable(Color.TRANSPARENT))
listView.overScrollMode = View.OVER_SCROLL_NEVER
listView.setPadding(0, 0, 0, 0)
listView.setPaddingRelative(0, 0, 0, 0)
// This is a workaround as CollapsingToolbarLayout consumes insets and
// insets are not passed to child views
// https://github.com/material-components/material-components-android/issues/1310
if (!RetroUtil.isLandscape()) {
listView.updatePadding(bottom = RetroUtil.getNavigationBarHeight())
}
invalidateSettings()
}