I am working on a tool that list devices based on certain value and the signal of the device is one of them and its defined by RSSI value rssi Here this(RSSI) value changes frequently which keeps updating the rows in the recycler view. I have just started with recycler view and by looking internet I am using a list adapter with diffutil callback. But it behave the same here is example behaviour
https://youtube.com/shorts/UNqj_6wwFnI?feature=share
I want only signal element of the whole view to be updated, not the whole row gets shuffled which makes very hard user to select a device when number of devices are large.
My diffutil impl
private val diffUtil = object : DiffUtil.ItemCallback<A>() {
override fun areItemsTheSame(
oldItem: A,
newItem: A
): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(
oldItem: A,
newItem: A
): Boolean {
return oldItem == newItem
}
Equal impl
override fun equals(other: Any?): Boolean {
if (javaClass != other?.javaClass){
return false
}
other as A
return (id == other.id
&& name == other.name
&& address == other.address
&& selected == other.selected
&& version == other.version
&& rssi == other.rssi
&& stateOfCharge == other.stateOfCharge
&& configVersionNumber == other.configVersionNumber
&& expanded == other.expanded)
}
The data A fields
var id: Long = 0,
var name: String = "",
var address: String = "",
var selected: Boolean = false,
var version: String = Version().formattedVersion,
var voltage: Float = 0f,
var rssi: Int = 0,
var stateOfCharge: Int = 0,
var configVersionNumber: Int = 0,
var timestamp: Long = 0,
var expanded: Boolean = false