Created
December 28, 2020 21:24
Star
You must be signed in to star a gist
EmailDiffCallback for fast rendering
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 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; | |
} | |
@Override | |
public int getOldListSize() { | |
return oldList.size(); | |
} | |
@Override | |
public int getNewListSize() { | |
return newList.size(); | |
} | |
@Override | |
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(); | |
} | |
@Override | |
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