How to handle nested RecyclerView updates

50 views Asked by At

I have implemented a view with a parent RecyclerView and a nested one. The nested RecyclerView contains Cards with items of a shopping card, that need to be updated when the user clicks on them (by showing a badge with the purchased quantity).

Both recyclers work with their ListAdapter with the DiffUtil.ItemCallback.

The point is the implementation of the outer ListAdapter areContentsTheSame of the DiffUtil.ItemCallback object: if it return false when the quantity changes, the quantity badge of the inner recycler is never updated. If it returns true, the entire inner RecyclerView is redrawn.

object ListDiffCallback : DiffUtil.ItemCallback<CategoryWithItems>() {
    override fun areContentsTheSame(oldItem: CategoryWithItems, newItem: CategoryWithItems): Boolean {
        var result oldItem.category.name == newItem.category.name
        oldItem.itemQuantityList?.forEachIndexed { index, value ->
            result = result && value.item.quantity == newItem.itemQuantityList?.get(index)?.item?.quantity
        }
        return result
    }
}

So my question is: how can I redraw only the clicked card of the inner RecyclerView?

0

There are 0 answers