playback: further pager cleanup

- Use Replace instead of Diff for now since that avoids the scroll
state freaking out. In practice I'll likely need to radically refactor
this system (AGAIN...) to make the queue updates 100% fine-grained,
even during shuffling.
- Remove the behaivor of staying paused on the next track. That's
covered by #568.
This commit is contained in:
Alexander Capehart 2023-10-16 21:33:53 -06:00
parent 243fb73f94
commit 94e2c3c3e4
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 11 additions and 12 deletions

View file

@ -175,7 +175,7 @@ class PlaybackPanelFragment :
} }
private fun updateQueue(queue: List<Song>) { private fun updateQueue(queue: List<Song>) {
coverAdapter?.update(queue, UpdateInstructions.Diff) coverAdapter?.update(queue, UpdateInstructions.Replace(0))
} }
private fun updateQueuePosition(position: Int) { private fun updateQueuePosition(position: Int) {
@ -239,7 +239,7 @@ class PlaybackPanelFragment :
// TODO // TODO
} }
private class OnCoverChangedCallback(private val viewModel: QueueViewModel) : private class OnCoverChangedCallback(private val queueViewModel: QueueViewModel) :
OnPageChangeCallback() { OnPageChangeCallback() {
private var targetPosition = RecyclerView.NO_POSITION private var targetPosition = RecyclerView.NO_POSITION
@ -253,8 +253,8 @@ class PlaybackPanelFragment :
super.onPageScrollStateChanged(state) super.onPageScrollStateChanged(state)
if (state == ViewPager2.SCROLL_STATE_IDLE && if (state == ViewPager2.SCROLL_STATE_IDLE &&
targetPosition != RecyclerView.NO_POSITION && targetPosition != RecyclerView.NO_POSITION &&
targetPosition != viewModel.index.value) { targetPosition != queueViewModel.index.value) {
viewModel.goto(targetPosition, playIfPaused = false) queueViewModel.goto(targetPosition)
} }
} }
} }

View file

@ -88,7 +88,7 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), EditClickList
} }
override fun onClick(item: Song, viewHolder: RecyclerView.ViewHolder) { override fun onClick(item: Song, viewHolder: RecyclerView.ViewHolder) {
queueModel.goto(viewHolder.bindingAdapterPosition, playIfPaused = true) queueModel.goto(viewHolder.bindingAdapterPosition)
} }
override fun onPickUp(viewHolder: RecyclerView.ViewHolder) { override fun onPickUp(viewHolder: RecyclerView.ViewHolder) {

View file

@ -108,12 +108,12 @@ class QueueViewModel @Inject constructor(private val playbackManager: PlaybackSt
* range. * range.
* @param playIfPaused Start playing after switching even if it currently is paused * @param playIfPaused Start playing after switching even if it currently is paused
*/ */
fun goto(adapterIndex: Int, playIfPaused: Boolean) { fun goto(adapterIndex: Int) {
if (adapterIndex !in queue.value.indices) { if (adapterIndex !in queue.value.indices) {
return return
} }
logD("Going to position $adapterIndex in queue") logD("Going to position $adapterIndex in queue")
playbackManager.goto(adapterIndex, playIfPaused || playbackManager.playerState.isPlaying) playbackManager.goto(adapterIndex)
} }
/** /**

View file

@ -120,9 +120,8 @@ interface PlaybackStateManager {
* Play a [Song] at the given position in the queue. * Play a [Song] at the given position in the queue.
* *
* @param index The position of the [Song] in the queue to start playing. * @param index The position of the [Song] in the queue to start playing.
* @param play Whether to start playing after switching to target index
*/ */
fun goto(index: Int, play: Boolean) fun goto(index: Int)
/** /**
* Add [Song]s to the top of the queue. * Add [Song]s to the top of the queue.
@ -430,12 +429,12 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
} }
@Synchronized @Synchronized
override fun goto(index: Int, play: Boolean) { override fun goto(index: Int) {
val internalPlayer = internalPlayer ?: return val internalPlayer = internalPlayer ?: return
if (queue.goto(index)) { if (queue.goto(index)) {
logD("Moving to $index") logD("Moving to $index")
notifyIndexMoved() notifyIndexMoved()
internalPlayer.loadSong(queue.currentSong, play) internalPlayer.loadSong(queue.currentSong, true)
} else { } else {
logW("$index was not in bounds, could not move to it") logW("$index was not in bounds, could not move to it")
} }

View file

@ -256,7 +256,7 @@ constructor(
} }
override fun onSkipToQueueItem(id: Long) { override fun onSkipToQueueItem(id: Long) {
playbackManager.goto(id.toInt(), true) playbackManager.goto(id.toInt())
} }
override fun onCustomAction(action: String?, extras: Bundle?) { override fun onCustomAction(action: String?, extras: Bundle?) {