Created
May 9, 2018 09:39
-
-
Save anitaa1990/4726169dc26ee5d3d6298b1bb1e523b8 to your computer and use it in GitHub Desktop.
Sample gist from sample app - https://github.com/anitaa1990/RoomDb-Sample
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 NoteDiffUtil extends DiffUtil.Callback { | |
List<Note> oldNoteList; | |
List<Note> newNoteList; | |
public NoteDiffUtil(List<Note> oldNoteList, List<Note> newNoteList) { | |
this.oldNoteList = oldNoteList; | |
this.newNoteList = newNoteList; | |
} | |
@Override | |
public int getOldListSize() { | |
return oldNoteList.size(); | |
} | |
@Override | |
public int getNewListSize() { | |
return newNoteList.size(); | |
} | |
@Override | |
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { | |
return oldNoteList.get(oldItemPosition).getId() == newNoteList.get(newItemPosition).getId(); | |
} | |
@Override | |
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { | |
return oldNoteList.get(oldItemPosition).equals(newNoteList.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