From 1c0e29e9b10fac3c348ea96d7f8aa410f1ece27b Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sun, 1 Nov 2026 16:17:43 -0700 Subject: [PATCH] queue: optimize only-position index moves --- .../auxio/playback/queue/QueueAdapter.kt | 23 +++++++++++++++---- .../auxio/playback/queue/QueueFragment.kt | 6 +++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueAdapter.kt b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueAdapter.kt index f2f7c1fd6..f5416d276 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueAdapter.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueAdapter.kt @@ -80,7 +80,7 @@ class QueueAdapter(private val listener: EditClickListListener) : * @param index The position of the currently playing item in the queue. * @param isPlaying Whether playback is ongoing or paused. */ - fun setPosition(index: Int, isPlaying: Boolean) { + fun setPosition(index: Int, isPlaying: Boolean, incremental: Boolean) { L.d("Updating index") val lastIndex = currentIndex currentIndex = index @@ -91,13 +91,28 @@ class QueueAdapter(private val listener: EditClickListListener) : // TODO: Don't update when the index has not moved. if (currentIndex < lastIndex) { L.d("Moved backwards, must update items above last index") - notifyItemRangeChanged(0, lastIndex + 1, PAYLOAD_UPDATE_POSITION) - } else { + val since = if (incremental) currentIndex else 0 + notifyItemRangeChanged( + since, + lastIndex - since + 1, + PAYLOAD_UPDATE_POSITION + ) + } else if (currentIndex > lastIndex) { L.d("Moved forwards, update items after index") - notifyItemRangeChanged(0, currentIndex + 1, PAYLOAD_UPDATE_POSITION) + val since = if (incremental) lastIndex else 0 + notifyItemRangeChanged( + since, + currentIndex - since + 1, + PAYLOAD_UPDATE_POSITION + ) } + val lastIsPlaying = this.isPlaying this.isPlaying = isPlaying + if (this.isPlaying != lastIsPlaying) { + L.d("Changed play state") + notifyItemChanged(currentIndex) + } } private companion object { diff --git a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt index 614f7142e..84d345175 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt @@ -30,6 +30,7 @@ import dagger.hilt.android.AndroidEntryPoint import kotlin.math.min import org.oxycblt.auxio.databinding.FragmentQueueBinding import org.oxycblt.auxio.list.EditClickListListener +import org.oxycblt.auxio.list.adapter.UpdateInstructions import org.oxycblt.auxio.playback.PlaybackViewModel import org.oxycblt.auxio.ui.ViewBindingFragment import org.oxycblt.auxio.util.collectImmediately @@ -111,8 +112,9 @@ class QueueFragment : ViewBindingFragment(), EditClickList private fun updateQueue(queue: List, index: Int, isPlaying: Boolean) { val binding = requireBinding() - queueAdapter.update(queue, queueModel.queueInstructions.consume()) - queueAdapter.setPosition(index, isPlaying) + val instructions = queueModel.queueInstructions.consume() + queueAdapter.update(queue, instructions) + queueAdapter.setPosition(index, isPlaying, instructions == null) // If requested, scroll to a new item (occurs when the index moves) val scrollTo = queueModel.scrollTo.consume()