Created
August 20, 2016 16:10
-
-
Save iammert/16c4006221f9815ed2cf2a3c0cc90627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyDiffCallback extends DiffUtil.Callback{ | |
List<Person> oldPersons; | |
List<Person> newPersons; | |
public MyDiffCallback(List<Person> newPersons, List<Person> oldPersons) { | |
this.newPersons = newPersons; | |
this.oldPersons = oldPersons; | |
} | |
@Override | |
public int getOldListSize() { | |
return oldPersons.size(); | |
} | |
@Override | |
public int getNewListSize() { | |
return newPersons.size(); | |
} | |
@Override | |
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { | |
return oldPersons.get(oldItemPosition).id == newPersons.get(newItemPosition).id; | |
} | |
@Override | |
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { | |
return oldPersons.get(oldItemPosition).equals(newPersons.get(newItemPosition)); | |
} | |
@Nullable | |
@Override | |
public Object getChangePayload(int oldItemPosition, int newItemPosition) { | |
//you can return particular field for changed item. | |
return super.getChangePayload(oldItemPosition, newItemPosition); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment