Twelve: SimpleListAdapter: Add support for manual updates

Change-Id: I0212f1c48bfd82b9c45381797f57f7f8a0fc525d
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 d197015..1e5b795 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,6 +8,7 @@
 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
@@ -21,6 +22,10 @@
     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() {}
@@ -33,6 +38,15 @@
         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