I have a recyclerview adapter of plain old data type, char in my case.
The adapter is backed by a list.
The setChar method updates the list.
Assume in my case that setChar is only called with the same list as the adapter has but only with items moved.
fun setChar(list: List<Char>) {
val diffResult = DiffUtil.calculateDiff(CharDiffCallBack(mChars, list), true)
mChars = list
diffResult.dispatchUpdatesTo(this)
}
class CharDiffCallBack(private val mOldList: List<Char>, private val mNewList: List<Char>) :
DiffUtil.Callback() {
override fun getOldListSize() = mOldList.size
override fun getNewListSize() = mNewList.size
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) = mOldList[oldItemPosition] == mNewList[newItemPosition]
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int) = false
}
What is the correct implementation of DiffUtil.Callback so that the moves are animated correctly as moves by the recyclerview?
Currently, it animates as if the item is removed and reinserted.