mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 02:25:28 +00:00
Do not always create new adapter
This commit is contained in:
parent
1a1646795f
commit
d130aa02a1
@ -15,7 +15,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.topjohnwu.magisk.BR
|
import com.topjohnwu.magisk.BR
|
||||||
|
|
||||||
class RvItemAdapter<T: RvItem>(
|
class RvItemAdapter<T: RvItem>(
|
||||||
private val items: List<T>,
|
internal val items: List<T>,
|
||||||
private val extraBindings: SparseArray<*>?
|
private val extraBindings: SparseArray<*>?
|
||||||
) : RecyclerView.Adapter<RvItemAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<RvItemAdapter.ViewHolder>() {
|
||||||
|
|
||||||
@ -113,6 +113,8 @@ inline fun bindExtra(body: (SparseArray<Any?>) -> Unit) = SparseArray<Any?>().al
|
|||||||
@BindingAdapter("items", "extraBindings", requireAll = false)
|
@BindingAdapter("items", "extraBindings", requireAll = false)
|
||||||
fun <T: RvItem> RecyclerView.setAdapter(items: List<T>?, extraBindings: SparseArray<*>?) {
|
fun <T: RvItem> RecyclerView.setAdapter(items: List<T>?, extraBindings: SparseArray<*>?) {
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
|
if ((adapter as? RvItemAdapter<T>)?.items !== items) {
|
||||||
adapter = RvItemAdapter(items, extraBindings)
|
adapter = RvItemAdapter(items, extraBindings)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user