From a9bbdff25d990593b2fbd217183633cd3c14bc50 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Mon, 5 Sep 2022 19:43:33 -0600 Subject: [PATCH] recycler: fix popup desync in grid layouts [#230] Fix a popup desynchronization issue in grid-based layouts. This issue stemmed from the popup index calculation apparently not needing a division by the span count in order to produce the correct index. This kind of makes sense, but is still really weird. Resolves #230. --- CHANGELOG.md | 3 ++ .../auxio/home/list/ArtistListFragment.kt | 7 ++-- .../playback/state/PlaybackStateManager.kt | 4 ++- .../ui/fastscroll/FastScrollRecyclerView.kt | 36 +++++++++---------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d09f55f26..9a256610b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## dev +#### What's Fixed +- Fixed issue wher the scroll popup would not display correctly in landscape mode [#230] + ## 2.6.3 #### What's New diff --git a/app/src/main/java/org/oxycblt/auxio/home/list/ArtistListFragment.kt b/app/src/main/java/org/oxycblt/auxio/home/list/ArtistListFragment.kt index 4c5a77945..31a1d9dff 100644 --- a/app/src/main/java/org/oxycblt/auxio/home/list/ArtistListFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/home/list/ArtistListFragment.kt @@ -79,10 +79,11 @@ class ArtistListFragment : HomeListFragment() { } override fun onOpenMenu(item: Item, anchor: View) { - when (item) { - is Artist -> musicMenu(anchor, R.menu.menu_genre_artist_actions, item) - else -> error("Unexpected datatype when opening menu: ${item::class.java}") + if (item is Artist) { + musicMenu(anchor, R.menu.menu_genre_artist_actions, item) } + + error("Unexpected datatype when opening menu: ${item::class.java}") } private fun handleParent(parent: MusicParent?, isPlaying: Boolean) { diff --git a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt index 1bee176ac..4a9a9338d 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt @@ -163,7 +163,9 @@ class PlaybackStateManager private constructor() { PlaybackMode.IN_ALBUM -> song.album PlaybackMode.IN_ARTIST -> song.album.artist PlaybackMode.IN_GENRE -> - song.genres.maxBy { it.songs.size } // TODO: Stopgap measure until I can rework this and add selection + song.genres.maxBy { + it.songs.size + } // TODO: Stopgap measure until I can rework this and add selection } applyNewQueue(library, settings, settings.keepShuffle && isShuffled, song) diff --git a/app/src/main/java/org/oxycblt/auxio/ui/fastscroll/FastScrollRecyclerView.kt b/app/src/main/java/org/oxycblt/auxio/ui/fastscroll/FastScrollRecyclerView.kt index 1721fde0e..c392603a3 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/fastscroll/FastScrollRecyclerView.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/fastscroll/FastScrollRecyclerView.kt @@ -208,13 +208,20 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr thumbView.layout(thumbLeft, thumbTop, thumbLeft + thumbWidth, thumbTop + thumbHeight) - val firstPos = firstAdapterPos + val child = getChildAt(0) + val firstAdapterPos = + if (child != null) { + layoutManager?.getPosition(child) ?: NO_POSITION + } else { + NO_POSITION + } + val popupText: String val provider = popupProvider - if (firstPos != NO_POSITION && provider != null) { + if (firstAdapterPos != NO_POSITION && provider != null) { popupView.isInvisible = false // Get the popup text. If there is none, we default to "?". - popupText = provider.getPopup(firstPos) ?: "?" + popupText = provider.getPopup(firstAdapterPos) ?: "?" } else { // No valid position or provider, do not show the popup. popupView.isInvisible = true @@ -298,6 +305,14 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr // Combine the previous item dimensions with the current item top to find our scroll // position getDecoratedBoundsWithMargins(getChildAt(0), tRect) + val child = getChildAt(0) + val firstAdapterPos = + when (val mgr = layoutManager) { + is GridLayoutManager -> mgr.getPosition(child) / mgr.spanCount + is LinearLayoutManager -> mgr.getPosition(child) + else -> 0 + } + val scrollOffset = paddingTop + (firstAdapterPos * itemHeight) - tRect.top // Then calculate the thumb position, which is just: @@ -474,21 +489,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr private val scrollOffsetRange: Int get() = scrollRange - height - private val firstAdapterPos: Int - get() { - if (childCount == 0) { - return NO_POSITION - } - - val child = getChildAt(0) - - return when (val mgr = layoutManager) { - is GridLayoutManager -> mgr.getPosition(child) / mgr.spanCount - is LinearLayoutManager -> mgr.getPosition(child) - else -> 0 - } - } - private val itemHeight: Int get() { if (childCount == 0) {