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 truejoelpedraza
06/03/2019, 2:34 PMareContentsTheSame
is _only called for elements in which areItemsTheSame
has returned true
joelpedraza
06/03/2019, 2:35 PMjoelpedraza
06/03/2019, 2:37 PMWhen `areItemsTheSame`returns `true `for two items andreturns false for them,areContentsTheSame
calls this method to get a payload about the change.DiffUtil
joelpedraza
06/03/2019, 2:37 PMursus
06/03/2019, 3:32 PMursus
06/03/2019, 6:42 PMursus
06/03/2019, 6:42 PMursus
06/03/2019, 6:43 PMursus
06/03/2019, 6:43 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;
}
ursus
06/03/2019, 8:40 PMursus
06/03/2019, 8:41 PMursus
06/03/2019, 8:42 PMjoelpedraza
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 visitorsjoelpedraza
06/04/2019, 1:08 PMWARNING: 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.joelpedraza
06/04/2019, 1:15 PMEnumSet
, 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 Classjoelpedraza
06/04/2019, 1:15 PMursus
06/04/2019, 9:40 PMjoelpedraza
06/06/2019, 2:06 PMursus
06/07/2019, 6:16 AM