Twelve: Introduce QueueItem

I hate random Pair<>!

Change-Id: Ic307c60ec6a27b89882e360c6361196ee666ad54
diff --git a/app/src/main/java/org/lineageos/twelve/ext/Player.kt b/app/src/main/java/org/lineageos/twelve/ext/Player.kt
index 61f41d0..3fee812 100644
--- a/app/src/main/java/org/lineageos/twelve/ext/Player.kt
+++ b/app/src/main/java/org/lineageos/twelve/ext/Player.kt
@@ -16,6 +16,7 @@
 import androidx.media3.common.util.UnstableApi
 import kotlinx.coroutines.channels.awaitClose
 import org.lineageos.twelve.models.PlaybackState
+import org.lineageos.twelve.models.QueueItem
 import org.lineageos.twelve.models.RepeatMode
 
 @OptIn(UnstableApi::class)
@@ -160,7 +161,7 @@
 
         trySend(
             mediaItems.mapIndexed { index, mediaItem ->
-                mediaItem to (index == currentMediaItemIndex)
+                QueueItem(mediaItem, index == currentMediaItemIndex)
             }
         )
     }
diff --git a/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt
index f02d83a..e401822 100644
--- a/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt
+++ b/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt
@@ -15,11 +15,9 @@
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.lifecycleScope
 import androidx.lifecycle.repeatOnLifecycle
-import androidx.media3.common.MediaItem
 import androidx.media3.common.util.UnstableApi
 import androidx.navigation.fragment.findNavController
 import androidx.navigation.ui.setupWithNavController
-import androidx.recyclerview.widget.DiffUtil
 import androidx.recyclerview.widget.ItemTouchHelper
 import androidx.recyclerview.widget.RecyclerView
 import com.google.android.material.appbar.MaterialToolbar
@@ -28,7 +26,9 @@
 import org.lineageos.twelve.R
 import org.lineageos.twelve.ext.getViewProperty
 import org.lineageos.twelve.ext.updatePadding
+import org.lineageos.twelve.models.QueueItem
 import org.lineageos.twelve.ui.recyclerview.SimpleListAdapter
+import org.lineageos.twelve.ui.recyclerview.UniqueItemDiffCallback
 import org.lineageos.twelve.ui.views.ListItem
 import org.lineageos.twelve.utils.TimestampFormatter
 import org.lineageos.twelve.viewmodels.QueueViewModel
@@ -49,17 +49,17 @@
 
     // RecyclerView
     private val adapter by lazy {
-        object : SimpleListAdapter<Pair<MediaItem, Boolean>, ListItem>(
-            diffCallback,
+        object : SimpleListAdapter<QueueItem, ListItem>(
+            UniqueItemDiffCallback(),
             ::ListItem,
         ) {
-            var currentQueue = listOf<Pair<MediaItem, Boolean>>()
+            var currentQueue = listOf<QueueItem>()
 
             override fun ViewHolder.onPrepareView() {
                 view.setTrailingIconImage(R.drawable.ic_drag_handle)
             }
 
-            override fun ViewHolder.onBindView(item: Pair<MediaItem, Boolean>) {
+            override fun ViewHolder.onBindView(item: QueueItem) {
                 val (mediaItem, isCurrent) = item
 
                 view.setLeadingIconImage(
@@ -169,18 +169,4 @@
 
         super.onDestroyView()
     }
-
-    companion object {
-        private val diffCallback = object : DiffUtil.ItemCallback<Pair<MediaItem, Boolean>>() {
-            override fun areItemsTheSame(
-                oldItem: Pair<MediaItem, Boolean>,
-                newItem: Pair<MediaItem, Boolean>,
-            ) = oldItem.first.mediaId == newItem.first.mediaId
-
-            override fun areContentsTheSame(
-                oldItem: Pair<MediaItem, Boolean>,
-                newItem: Pair<MediaItem, Boolean>,
-            ) = oldItem.first == newItem.first && oldItem.second == newItem.second
-        }
-    }
 }
diff --git a/app/src/main/java/org/lineageos/twelve/models/QueueItem.kt b/app/src/main/java/org/lineageos/twelve/models/QueueItem.kt
new file mode 100644
index 0000000..42751b7
--- /dev/null
+++ b/app/src/main/java/org/lineageos/twelve/models/QueueItem.kt
@@ -0,0 +1,18 @@
+/*
+ * SPDX-FileCopyrightText: 2024 The LineageOS Project
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.lineageos.twelve.models
+
+import androidx.media3.common.MediaItem
+
+data class QueueItem(
+    val mediaItem: MediaItem,
+    val isCurrent: Boolean,
+) : UniqueItem<QueueItem> {
+    override fun areItemsTheSame(other: QueueItem) = mediaItem.mediaId == other.mediaItem.mediaId
+
+    override fun areContentsTheSame(other: QueueItem) =
+        mediaItem == other.mediaItem && isCurrent == other.isCurrent
+}