queue: fix visual error when adding to queue
Fix a visual error where adding to queue would visually place items next to the starting index rather than at the end. This was a result of forgetting to update the Add instructions returned by Queue.addToNext to return the end of the queue rather than the current index, which completely broke the queue visual. Resolves #435.
This commit is contained in:
parent
63f7627fbc
commit
d97eaf67b9
4 changed files with 19 additions and 9 deletions
|
@ -17,6 +17,7 @@
|
|||
- Items should no longer be indicated as playing if the currently playing song is not contained
|
||||
within it
|
||||
- Fixed blurry playing indicator in album/artist/genre/playlist items
|
||||
- Fixed incorrect songs being displayed when adding albums to the end of the queue
|
||||
|
||||
## 3.1.0
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
private val selectionBadge: ImageView?
|
||||
|
||||
@DimenRes private val iconSizeRes: Int?
|
||||
@DimenRes private val cornerRadiusRes: Int
|
||||
@DimenRes private val cornerRadiusRes: Int?
|
||||
|
||||
private var fadeAnimator: ValueAnimator? = null
|
||||
private val indicatorMatrix = Matrix()
|
||||
|
@ -103,7 +103,12 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
|
||||
val sizing = styledAttrs.getIntOrThrow(R.styleable.CoverView_sizing)
|
||||
iconSizeRes = SIZING_ICON_SIZE[sizing]
|
||||
cornerRadiusRes = SIZING_CORNER_RADII[sizing]
|
||||
cornerRadiusRes =
|
||||
if (uiSettings.roundMode) {
|
||||
SIZING_CORNER_RADII[sizing]
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val playbackIndicatorEnabled =
|
||||
styledAttrs.getBoolean(R.styleable.CoverView_enablePlaybackIndicator, true)
|
||||
|
@ -162,7 +167,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
background =
|
||||
MaterialShapeDrawable().apply {
|
||||
fillColor = context.getColorCompat(R.color.sel_cover_bg)
|
||||
setCornerSize(context.getDimen(cornerRadiusRes))
|
||||
setCornerSize(cornerRadiusRes?.let(context::getDimen) ?: 0f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +225,11 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
invalidateSelectionIndicatorAlpha(selectionBadge ?: return)
|
||||
}
|
||||
|
||||
override fun setEnabled(enabled: Boolean) {
|
||||
super.setEnabled(enabled)
|
||||
invalidateRootAlpha()
|
||||
}
|
||||
|
||||
override fun setSelected(selected: Boolean) {
|
||||
super.setSelected(selected)
|
||||
invalidateRootAlpha()
|
||||
|
@ -249,7 +259,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
}
|
||||
|
||||
private fun invalidateRootAlpha() {
|
||||
alpha = if (isSelected || isEnabled) 1f else 0.5f
|
||||
alpha = if (isEnabled || isSelected) 1f else 0.5f
|
||||
}
|
||||
|
||||
private fun invalidatePlaybackIndicatorAlpha(playbackIndicator: PlaybackIndicator) {
|
||||
|
@ -370,7 +380,8 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
ImageRequest.Builder(context)
|
||||
.data(songs)
|
||||
.error(StyledDrawable(context, context.getDrawableCompat(errorRes), iconSizeRes))
|
||||
.transformations(RoundedCornersTransformation(context.getDimen(cornerRadiusRes)))
|
||||
.transformations(
|
||||
RoundedCornersTransformation(cornerRadiusRes?.let(context::getDimen) ?: 0f))
|
||||
.target(image)
|
||||
.build()
|
||||
// Dispose of any previous image request and load a new image.
|
||||
|
|
|
@ -234,6 +234,7 @@ class EditableQueue : Queue {
|
|||
*/
|
||||
fun addToQueue(songs: List<Song>): Queue.Change {
|
||||
logD("Adding ${songs.size} songs to the back of the queue")
|
||||
val point = orderedMapping.size
|
||||
val heapIndices = songs.map(::addSongToHeap)
|
||||
// Can simple append the new songs to the end of both mappings.
|
||||
orderedMapping.addAll(heapIndices)
|
||||
|
@ -242,8 +243,7 @@ class EditableQueue : Queue {
|
|||
shuffledMapping.addAll(heapIndices)
|
||||
}
|
||||
check()
|
||||
return Queue.Change(
|
||||
Queue.Change.Type.MAPPING, UpdateInstructions.Add(index + 1, songs.size))
|
||||
return Queue.Change(Queue.Change.Type.MAPPING, UpdateInstructions.Add(point, songs.size))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -105,9 +105,7 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), EditClickList
|
|||
private fun updateQueue(queue: List<Song>, index: Int, isPlaying: Boolean) {
|
||||
val binding = requireBinding()
|
||||
|
||||
// Replace or diff the queue depending on the type of change it is.
|
||||
queueAdapter.update(queue, queueModel.queueInstructions.consume())
|
||||
// Update position in list (and thus past/future items)
|
||||
queueAdapter.setPosition(index, isPlaying)
|
||||
|
||||
// If requested, scroll to a new item (occurs when the index moves)
|
||||
|
|
Loading…
Reference in a new issue