ursus
06/01/2019, 5:49 PMjoelpedraza
06/03/2019, 2:33 PMDiffUtil.Callback
areItemsTheSame
checks identity equality
areContentsTheSame
checks visual equality
The adapter is only notified of changes if the return values of both are trueareContentsTheSame
is _only called for elements in which areItemsTheSame
has returned true
When `areItemsTheSame`returns `true `for two items andreturns false for them,areContentsTheSame
calls this method to get a payload about the change.DiffUtil
ursus
06/03/2019, 3:32 PMjoelpedraza
06/03/2019, 6:44 PMursus
06/03/2019, 8:40 PM@Nullable
@Override
public Object getChangePayload(int oldItemPosition, int newItemPosition) {
Contact newContact = newList.get(newItemPosition);
Contact oldContact = oldList.get(oldItemPosition);
Bundle diff = new Bundle();
if(!newContact.getName().equals(oldContact.getName())){
diff.putString("name", newContact.getName());
}
if(!newContact.getPhonenumber().equals (oldContact.getPhonenumber())){
diff.putString("phone", newContact.getPhonenumber());
}
if (diff.size()==0){
return null;
}
return diff;
}
joelpedraza
06/04/2019, 1:05 PMvisit
method, then it’s a compile error unless you add an implementation for the new method to all your visitorsWARNING: OPINION
Using a bundle is weird. What’s the purpose of even having the Contact
type that stores all the data, only to stuff it into the bundle.EnumSet
, then you can pattern match with a when
expression and non-exhastive matching will be a compiler error
That would come at the development cost of declaring a new enum for each view holder. This dosent seem much higher than declaring string constants though.
Also the runtime (bytecode) cost of adding new Classursus
06/04/2019, 9:40 PMjoelpedraza
06/06/2019, 2:06 PMursus
06/07/2019, 6:16 AM