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.
This commit is contained in:
@@ -79,10 +79,11 @@ class ArtistListFragment : HomeListFragment<Artist>() {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user