Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
EmailDiffCallback for fast rendering
public class EmailDiffCallback extends DiffUtil.Callback {
private List<Email> oldList;
private List<Email> newList;
public EmailDiffCallback(List<Email> oldList, List<Email> newList) {
this.oldList = oldList;
this.newList = newList;
public int getOldListSize() {
return oldList.size();
public int getNewListSize() {
return newList.size();
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
// add a unique ID property on Email and expose a getId() method
return oldList.get(oldItemPosition).getId() == newList.get(newItemPosition).getId();
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
Email oldEmail = oldList.get(oldItemPosition);
Email newEmail = newList.get(newItemPosition);
if (oldEmail.getFromName() == newEmail.getFromName() && oldEmail.getSubject() == newEmail.getSubject() && oldEmail.getShortBody() == newEmail.getShortBody()) {
return true;
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.