I have a recyclerview adapter that I update from my activity but the issue is whenever the live data object gets updated and I update the adapter the object I have in the adapter also gets the same data even I didn't assign updated value to it, this is pretty strange I didn't understand what is going on
Here is the adapter code where it set my data
fun setDevices(tempDevices: List<DataModelDevice>) {
val diffResult: DiffUtil.DiffResult = DiffUtil.calculateDiff(
DeviceDiffCallback(
this.devices,
tempDevices
)
)
diffResult.dispatchUpdatesTo(this)
this.devices = tempDevices
}
the issue is when I came to this block of code both the tempDevices and devices have the same data set and I don't understand why is the devices object gets updated even before I update it with tempDevices
Here is the code where i observe the changes in devices
viewModel.devices.observe(this, {
if (it.size != 0) {
deviceAdapter.setDevices(it)
binding.recyclerViewDevices.scrollToPosition(0)
}
})
This is my live data object in my viewModel class
var devices: MutableLiveData<MutableList<DataModelDevice>> = MutableLiveData()