I am trying to update a RecyclerView based on a size (Int) passed to the adapter. I would like the adapter to add or remove items without moving any items as it appears to be now. I am sharing the code for DiffUtil below:
fun notifyChanges(newListSize: Int) {
val diff = DiffUtil.calculateDiff(object : DiffUtil.Callback() {
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
return true
}
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
return true
}
override fun getOldListSize() = columnNumber * rowNumber
override fun getNewListSize() = newListSize
})
// Update number of tiles and dispatch changes
tilesNumber = newListSize
diff.dispatchUpdatesTo(this)
}
I then call it as:
mAdapter.notifyChanges(columnNumber * rowNumber)
Any help will be appreciated.