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:
parent
b24e22182e
commit
a9bbdff25d
4 changed files with 28 additions and 22 deletions
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
## dev
|
## dev
|
||||||
|
|
||||||
|
#### What's Fixed
|
||||||
|
- Fixed issue wher the scroll popup would not display correctly in landscape mode [#230]
|
||||||
|
|
||||||
## 2.6.3
|
## 2.6.3
|
||||||
|
|
||||||
#### What's New
|
#### What's New
|
||||||
|
|
|
@ -79,10 +79,11 @@ class ArtistListFragment : HomeListFragment<Artist>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOpenMenu(item: Item, anchor: View) {
|
override fun onOpenMenu(item: Item, anchor: View) {
|
||||||
when (item) {
|
if (item is Artist) {
|
||||||
is Artist -> musicMenu(anchor, R.menu.menu_genre_artist_actions, item)
|
musicMenu(anchor, R.menu.menu_genre_artist_actions, item)
|
||||||
else -> error("Unexpected datatype when opening menu: ${item::class.java}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error("Unexpected datatype when opening menu: ${item::class.java}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleParent(parent: MusicParent?, isPlaying: Boolean) {
|
private fun handleParent(parent: MusicParent?, isPlaying: Boolean) {
|
||||||
|
|
|
@ -163,7 +163,9 @@ class PlaybackStateManager private constructor() {
|
||||||
PlaybackMode.IN_ALBUM -> song.album
|
PlaybackMode.IN_ALBUM -> song.album
|
||||||
PlaybackMode.IN_ARTIST -> song.album.artist
|
PlaybackMode.IN_ARTIST -> song.album.artist
|
||||||
PlaybackMode.IN_GENRE ->
|
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)
|
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)
|
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 popupText: String
|
||||||
val provider = popupProvider
|
val provider = popupProvider
|
||||||
if (firstPos != NO_POSITION && provider != null) {
|
if (firstAdapterPos != NO_POSITION && provider != null) {
|
||||||
popupView.isInvisible = false
|
popupView.isInvisible = false
|
||||||
// Get the popup text. If there is none, we default to "?".
|
// Get the popup text. If there is none, we default to "?".
|
||||||
popupText = provider.getPopup(firstPos) ?: "?"
|
popupText = provider.getPopup(firstAdapterPos) ?: "?"
|
||||||
} else {
|
} else {
|
||||||
// No valid position or provider, do not show the popup.
|
// No valid position or provider, do not show the popup.
|
||||||
popupView.isInvisible = true
|
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
|
// Combine the previous item dimensions with the current item top to find our scroll
|
||||||
// position
|
// position
|
||||||
getDecoratedBoundsWithMargins(getChildAt(0), tRect)
|
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
|
val scrollOffset = paddingTop + (firstAdapterPos * itemHeight) - tRect.top
|
||||||
|
|
||||||
// Then calculate the thumb position, which is just:
|
// Then calculate the thumb position, which is just:
|
||||||
|
@ -474,21 +489,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||||
private val scrollOffsetRange: Int
|
private val scrollOffsetRange: Int
|
||||||
get() = scrollRange - height
|
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
|
private val itemHeight: Int
|
||||||
get() {
|
get() {
|
||||||
if (childCount == 0) {
|
if (childCount == 0) {
|
||||||
|
|
Loading…
Reference in a new issue