Twelve: Remove differ hack

If we're smart enough we can handle everything
without reflection

Change-Id: Iac75fb507cf0354fced618e72be2071f0a712998
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 e26c0db..f02d83a 100644
--- a/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt
+++ b/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt
@@ -53,6 +53,8 @@
             diffCallback,
             ::ListItem,
         ) {
+            var currentQueue = listOf<Pair<MediaItem, Boolean>>()
+
             override fun ViewHolder.onPrepareView() {
                 view.setTrailingIconImage(R.drawable.ic_drag_handle)
             }
@@ -91,16 +93,11 @@
             val to = target.bindingAdapterPosition
 
             // First update our adapter list
-            val list = adapter.currentList.toMutableList()
-            Collections.swap(list, from, to)
-            adapter.setListWithoutDiffing(list)
+            Collections.swap(adapter.currentQueue, from, to)
             adapter.notifyItemMoved(from, to)
 
             // Then update the queue
-            viewModel.moveItem(
-                viewHolder.bindingAdapterPosition,
-                target.bindingAdapterPosition
-            )
+            viewModel.moveItem(from, to)
 
             return true
         }
@@ -156,8 +153,11 @@
 
         viewLifecycleOwner.lifecycleScope.launch {
             viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
-                viewModel.queue.collectLatest {
-                    adapter.submitList(it)
+                viewModel.queue.collectLatest { queue ->
+                    queue.toMutableList().let {
+                        adapter.currentQueue = it
+                        adapter.submitList(it)
+                    }
                 }
             }
         }
diff --git a/app/src/main/java/org/lineageos/twelve/ui/recyclerview/SimpleListAdapter.kt b/app/src/main/java/org/lineageos/twelve/ui/recyclerview/SimpleListAdapter.kt
index 1e5b795..d197015 100644
--- a/app/src/main/java/org/lineageos/twelve/ui/recyclerview/SimpleListAdapter.kt
+++ b/app/src/main/java/org/lineageos/twelve/ui/recyclerview/SimpleListAdapter.kt
@@ -8,7 +8,6 @@
 import android.content.Context
 import android.view.View
 import android.view.ViewGroup
-import androidx.recyclerview.widget.AsyncListDiffer
 import androidx.recyclerview.widget.DiffUtil
 import androidx.recyclerview.widget.ListAdapter
 import androidx.recyclerview.widget.RecyclerView
@@ -22,10 +21,6 @@
     diffCallback: DiffUtil.ItemCallback<T>,
     private val factory: (Context) -> V,
 ) : ListAdapter<T, SimpleListAdapter<T, V>.ViewHolder>(diffCallback) {
-    private val differ = ListAdapter::class.java.getDeclaredField("mDiffer").apply {
-        isAccessible = true
-    }.get(this) as AsyncListDiffer<*>
-
     abstract fun ViewHolder.onBindView(item: T)
 
     open fun ViewHolder.onPrepareView() {}
@@ -38,15 +33,6 @@
         holder.bind(getItem(position))
     }
 
-    fun setListWithoutDiffing(list: List<T>) {
-        setOf("mList", "mReadOnlyList").forEach { fieldName ->
-            differ::class.java.getDeclaredField(fieldName).apply {
-                isAccessible = true
-                set(differ, list)
-            }
-        }
-    }
-
     inner class ViewHolder(val view: V) : RecyclerView.ViewHolder(view) {
         var item: T? = null