From 545347dfb2fbbb68cb278de23e8fd93506c4b9ee Mon Sep 17 00:00:00 2001 From: nift4 Date: Sat, 1 Jun 2024 20:42:49 +0200 Subject: [PATCH] fix snack bar inset bug --- .../gramophone/logic/GramophoneExtensions.kt | 4 ++++ .../gramophone/ui/fragments/ViewPagerFragment.kt | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/src/main/kotlin/org/akanework/gramophone/logic/GramophoneExtensions.kt b/app/src/main/kotlin/org/akanework/gramophone/logic/GramophoneExtensions.kt index 231cd4f03..9ea443b0a 100644 --- a/app/src/main/kotlin/org/akanework/gramophone/logic/GramophoneExtensions.kt +++ b/app/src/main/kotlin/org/akanework/gramophone/logic/GramophoneExtensions.kt @@ -414,6 +414,10 @@ inline fun needsMissingOnDestroyCallWorkarounds(): Boolean = inline fun hasImprovedMediaStore(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R +@Suppress("NOTHING_TO_INLINE") +inline fun needsManualSnackBarInset(): Boolean = + Build.VERSION.SDK_INT <= Build.VERSION_CODES.P + @Suppress("NOTHING_TO_INLINE") inline fun hasAlbumArtistIdInMediaStore(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q diff --git a/app/src/main/kotlin/org/akanework/gramophone/ui/fragments/ViewPagerFragment.kt b/app/src/main/kotlin/org/akanework/gramophone/ui/fragments/ViewPagerFragment.kt index c6db2b1ae..0bd47a1d7 100644 --- a/app/src/main/kotlin/org/akanework/gramophone/ui/fragments/ViewPagerFragment.kt +++ b/app/src/main/kotlin/org/akanework/gramophone/ui/fragments/ViewPagerFragment.kt @@ -26,6 +26,8 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.appcompat.content.res.AppCompatResources +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.activityViewModels import androidx.media3.common.util.UnstableApi import androidx.viewpager2.widget.ViewPager2 @@ -36,7 +38,10 @@ import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator import org.akanework.gramophone.R +import org.akanework.gramophone.logic.clone import org.akanework.gramophone.logic.enableEdgeToEdgePaddingListener +import org.akanework.gramophone.logic.needsManualSnackBarInset +import org.akanework.gramophone.logic.updateMargin import org.akanework.gramophone.ui.LibraryViewModel import org.akanework.gramophone.ui.MainActivity import org.akanework.gramophone.ui.adapters.ViewPager2Adapter @@ -132,6 +137,16 @@ class ViewPagerFragment : BaseFragment(true) { // Set an anchor for snack bar. if (playerLayout.visible && playerLayout.actuallyVisible) snackBar.anchorView = playerLayout + else if (needsManualSnackBarInset()) { + // snack bar only implements proper insets handling for Q+ + snackBar.view.updateMargin { + val i = ViewCompat.getRootWindowInsets(activity.window.decorView) + if (i != null) { + bottom += i.clone() + .getInsets(WindowInsetsCompat.Type.systemBars()).bottom + } + } + } snackBar.show() } }