Fixed navbar overlapping in settings
This commit is contained in:
parent
d8aaa5a21b
commit
65d52776f8
2 changed files with 31 additions and 8 deletions
|
@ -27,10 +27,8 @@ import android.widget.EditText
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.core.animation.doOnEnd
|
import androidx.core.animation.doOnEnd
|
||||||
import androidx.core.animation.doOnStart
|
import androidx.core.animation.doOnStart
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.*
|
||||||
import androidx.core.view.WindowInsetsCompat
|
|
||||||
import androidx.core.view.WindowInsetsCompat.Type.navigationBars
|
import androidx.core.view.WindowInsetsCompat.Type.navigationBars
|
||||||
import androidx.core.view.updateLayoutParams
|
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.TintHelper
|
import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
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.
|
* This will draw our view above the navigation bar instead of behind it by adding margins.
|
||||||
*/
|
*/
|
||||||
fun View.drawAboveNavBar() {
|
fun View.drawAboveNavBar() {
|
||||||
|
// Create a snapshot of the view's margin state
|
||||||
|
val initialMargin = recordInitialMarginForView(this)
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(
|
ViewCompat.setOnApplyWindowInsetsListener(
|
||||||
(this)
|
(this)
|
||||||
) { v: View, insets: WindowInsetsCompat ->
|
) { v: View, insets: WindowInsetsCompat ->
|
||||||
v.updateLayoutParams<MarginLayoutParams> {
|
v.updateLayoutParams<MarginLayoutParams> {
|
||||||
bottomMargin =
|
bottomMargin = initialMargin.bottom +
|
||||||
insets.getInsets(navigationBars()).bottom
|
insets.getInsets(navigationBars()).bottom
|
||||||
}
|
}
|
||||||
insets
|
insets
|
||||||
|
@ -153,11 +153,13 @@ fun View.drawAboveNavBar() {
|
||||||
* This will draw our view above the navigation bar instead of behind it by adding padding.
|
* This will draw our view above the navigation bar instead of behind it by adding padding.
|
||||||
*/
|
*/
|
||||||
fun View.drawAboveNavBarWithPadding() {
|
fun View.drawAboveNavBarWithPadding() {
|
||||||
|
val initialPadding = recordInitialPaddingForView(this)
|
||||||
|
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(
|
ViewCompat.setOnApplyWindowInsetsListener(
|
||||||
(this)
|
(this)
|
||||||
) { v: View, insets: WindowInsetsCompat ->
|
) { v: View, insets: WindowInsetsCompat ->
|
||||||
val navBarHeight = insets.getInsets(navigationBars()).bottom
|
val navBarHeight = insets.getInsets(navigationBars()).bottom
|
||||||
v.updatePadding(bottom = navBarHeight)
|
v.updatePadding(bottom = initialPadding.bottom + navBarHeight)
|
||||||
insets
|
insets
|
||||||
}
|
}
|
||||||
requestApplyInsetsWhenAttached()
|
requestApplyInsetsWhenAttached()
|
||||||
|
@ -180,3 +182,18 @@ fun View.requestApplyInsetsWhenAttached() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
|
@ -19,6 +19,7 @@ import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceManager
|
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.activities.OnThemeChangedListener
|
||||||
import code.name.monkey.retromusic.preferences.*
|
import code.name.monkey.retromusic.preferences.*
|
||||||
import code.name.monkey.retromusic.util.NavigationUtil
|
import code.name.monkey.retromusic.util.NavigationUtil
|
||||||
|
import code.name.monkey.retromusic.util.RetroUtil
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hemanth S (h4h13).
|
* @author Hemanth S (h4h13).
|
||||||
|
@ -65,8 +67,12 @@ abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
setDivider(ColorDrawable(Color.TRANSPARENT))
|
setDivider(ColorDrawable(Color.TRANSPARENT))
|
||||||
listView.overScrollMode = View.OVER_SCROLL_NEVER
|
listView.overScrollMode = View.OVER_SCROLL_NEVER
|
||||||
listView.setPadding(0, 0, 0, 0)
|
// This is a workaround as CollapsingToolbarLayout consumes insets and
|
||||||
listView.setPaddingRelative(0, 0, 0, 0)
|
// 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()
|
invalidateSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue