0

There is LiveData which is a list of users:

val users: MutableLiveData<List<User>>

Then it is updated:

val usersValues = users.getValues()
val user = usersValues[0]
user.name = "new-name"
users.post(usersValues)

And DiffUtil doesn't see different because User is the same object, so it's just updated inside Adapter.

fun areContentsTheSame(int a, int b): Boolean {
    val oldUser //User@666
    val newUser //User@666
    return oldUser.id == newUser.id || oldUser.name == newUser.name
}

One solution is to create a new instance or a copy, then DiffUtil will notice difference. Is there anything better?

eleven
  • 6,779
  • 2
  • 32
  • 52

1 Answers1

0

Maybe this will help you

override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean
        = oldList[oldItemPosition].id == newList[newItemPosition].id

You can modify a bit according to your requirements if you want to check by ids or something else

Muhammad Saad
  • 713
  • 1
  • 9
  • 31