mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2025-07-20 12:55:45 +00:00
top margin fixed for non zero cutout screens (#185)
intended to fix top margin for screens with non zero cutout insets Co-authored-by: Allison Cunha <allisonbzk@gmail.com> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/185 Co-authored-by: xbzk <xbzk@noreply.localhost> Co-committed-by: xbzk <xbzk@noreply.localhost>
This commit is contained in:
parent
1037bff8ac
commit
6b46aca0b7
1 changed files with 12 additions and 22 deletions
|
@ -444,32 +444,24 @@ class GamesFragment : Fragment() {
|
||||||
private fun setInsets() =
|
private fun setInsets() =
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(
|
ViewCompat.setOnApplyWindowInsetsListener(
|
||||||
binding.root
|
binding.root
|
||||||
) { view: View, windowInsets: WindowInsetsCompat ->
|
) { _: View, windowInsets: WindowInsetsCompat ->
|
||||||
val barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
val barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout())
|
val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout())
|
||||||
val spacingNavigation = resources.getDimensionPixelSize(R.dimen.spacing_navigation)
|
val spacingNavigation = resources.getDimensionPixelSize(R.dimen.spacing_navigation)
|
||||||
resources.getDimensionPixelSize(R.dimen.spacing_navigation_rail)
|
resources.getDimensionPixelSize(R.dimen.spacing_navigation_rail)
|
||||||
val isLandscape =
|
|
||||||
resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
|
||||||
|
|
||||||
binding.swipeRefresh.setProgressViewEndTarget(
|
binding.swipeRefresh.setProgressViewEndTarget(
|
||||||
false,
|
false,
|
||||||
barInsets.top + resources.getDimensionPixelSize(R.dimen.spacing_refresh_end)
|
barInsets.top + resources.getDimensionPixelSize(R.dimen.spacing_refresh_end)
|
||||||
)
|
)
|
||||||
|
|
||||||
val leftInsets = barInsets.left + cutoutInsets.left
|
val leftInset = barInsets.left + cutoutInsets.left
|
||||||
val rightInsets = barInsets.right + cutoutInsets.right
|
val rightInset = barInsets.right + cutoutInsets.right
|
||||||
val topInsets = barInsets.top + cutoutInsets.top
|
val topInset = maxOf(barInsets.top, cutoutInsets.top)
|
||||||
val bottomInsets = barInsets.bottom + cutoutInsets.bottom
|
|
||||||
|
|
||||||
val mlpSwipe = binding.swipeRefresh.layoutParams as ViewGroup.MarginLayoutParams
|
val mlpSwipe = binding.swipeRefresh.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
if (view.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR) {
|
mlpSwipe.leftMargin = leftInset
|
||||||
mlpSwipe.leftMargin = leftInsets
|
mlpSwipe.rightMargin = rightInset
|
||||||
mlpSwipe.rightMargin = rightInsets
|
|
||||||
} else {
|
|
||||||
mlpSwipe.leftMargin = leftInsets
|
|
||||||
mlpSwipe.rightMargin = rightInsets
|
|
||||||
}
|
|
||||||
binding.swipeRefresh.layoutParams = mlpSwipe
|
binding.swipeRefresh.layoutParams = mlpSwipe
|
||||||
|
|
||||||
val mlpHeader = binding.header.layoutParams as ViewGroup.MarginLayoutParams
|
val mlpHeader = binding.header.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
|
@ -477,29 +469,27 @@ class GamesFragment : Fragment() {
|
||||||
// Store original margins only once
|
// Store original margins only once
|
||||||
if (originalHeaderTopMargin == null) {
|
if (originalHeaderTopMargin == null) {
|
||||||
originalHeaderTopMargin = mlpHeader.topMargin
|
originalHeaderTopMargin = mlpHeader.topMargin
|
||||||
originalHeaderBottomMargin = mlpHeader.bottomMargin
|
|
||||||
originalHeaderRightMargin = mlpHeader.rightMargin
|
originalHeaderRightMargin = mlpHeader.rightMargin
|
||||||
originalHeaderLeftMargin = mlpHeader.leftMargin
|
originalHeaderLeftMargin = mlpHeader.leftMargin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always set margin as original + insets
|
// Always set margin as original + insets
|
||||||
mlpHeader.leftMargin = (originalHeaderLeftMargin ?: 0) + leftInsets
|
mlpHeader.leftMargin = (originalHeaderLeftMargin ?: 0) + leftInset
|
||||||
mlpHeader.rightMargin = (originalHeaderRightMargin ?: 0) + rightInsets
|
mlpHeader.rightMargin = (originalHeaderRightMargin ?: 0) + rightInset
|
||||||
mlpHeader.topMargin = (originalHeaderTopMargin ?: 0) + if (!isLandscape) topInsets else 0
|
mlpHeader.topMargin = (originalHeaderTopMargin ?: 0) + topInset + resources.getDimensionPixelSize(R.dimen.spacing_med)
|
||||||
mlpHeader.bottomMargin = (originalHeaderBottomMargin ?: 0) + if (!isLandscape) bottomInsets else 0
|
|
||||||
binding.header.layoutParams = mlpHeader
|
binding.header.layoutParams = mlpHeader
|
||||||
|
|
||||||
binding.noticeText.updatePadding(bottom = spacingNavigation)
|
binding.noticeText.updatePadding(bottom = spacingNavigation)
|
||||||
binding.header.updatePadding(top = cutoutInsets.top + resources.getDimensionPixelSize(R.dimen.spacing_large) + if (isLandscape) barInsets.top else 0)
|
|
||||||
binding.gridGames.updatePadding(
|
binding.gridGames.updatePadding(
|
||||||
top = resources.getDimensionPixelSize(R.dimen.spacing_med)
|
top = resources.getDimensionPixelSize(R.dimen.spacing_med)
|
||||||
)
|
)
|
||||||
|
|
||||||
val mlpFab = binding.addDirectory.layoutParams as ViewGroup.MarginLayoutParams
|
val mlpFab = binding.addDirectory.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
val fabPadding = resources.getDimensionPixelSize(R.dimen.spacing_large)
|
val fabPadding = resources.getDimensionPixelSize(R.dimen.spacing_large)
|
||||||
mlpFab.leftMargin = leftInsets + fabPadding
|
mlpFab.leftMargin = leftInset + fabPadding
|
||||||
mlpFab.bottomMargin = barInsets.bottom + fabPadding
|
mlpFab.bottomMargin = barInsets.bottom + fabPadding
|
||||||
mlpFab.rightMargin = rightInsets + fabPadding
|
mlpFab.rightMargin = rightInset + fabPadding
|
||||||
binding.addDirectory.layoutParams = mlpFab
|
binding.addDirectory.layoutParams = mlpFab
|
||||||
|
|
||||||
windowInsets
|
windowInsets
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue