Skip to content

Commit

Permalink
fix snack bar inset bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Jun 1, 2024
1 parent be661ce commit 545347d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down

0 comments on commit 545347d

Please sign in to comment.