Skip to content
Snippets Groups Projects
Commit dd85d8bc authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Speed up diffResult calculation for sorting

parent 02282081
No related branches found
No related tags found
No related merge requests found
......@@ -449,16 +449,17 @@ public class VideoListAdapter extends BaseQueuedAdapter<MediaWrapper, VideoListA
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
MediaWrapper oldItem = oldList.get(oldItemPosition);
MediaWrapper newItem = newList.get(newItemPosition);
return oldList != null && newList != null && oldItem.getType() == newItem.getType() && oldItem.equals(newItem);
return oldItem == newItem || (oldList != null && newList != null
&& oldItem.getType() == newItem.getType() && oldItem.equals(newItem));
}
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
MediaWrapper oldItem = oldList.get(oldItemPosition);
MediaWrapper newItem = newList.get(newItemPosition);
return oldItem.getTime() == newItem.getTime()
return oldItem == newItem || (oldItem.getTime() == newItem.getTime()
&& TextUtils.equals(oldItem.getArtworkMrl(), newItem.getArtworkMrl())
&& oldItem.getSeen() == newItem.getSeen();
&& oldItem.getSeen() == newItem.getSeen());
}
@Nullable
......
......@@ -9,31 +9,28 @@ import java.util.List;
public class MediaItemDiffCallback extends DiffUtil.Callback {
private static final String TAG = "MediaItemDiffCallback";
private MediaLibraryItem[] oldList, newList;
private List<? extends MediaLibraryItem> oldList, newList;
public MediaItemDiffCallback(List<? extends MediaLibraryItem> oldList, List<? extends MediaLibraryItem> newList) {
this.oldList = oldList.toArray(new MediaLibraryItem[oldList.size()]);
this.newList = newList.toArray(new MediaLibraryItem[newList.size()]);
}
public MediaItemDiffCallback(MediaLibraryItem[] oldList, MediaLibraryItem[] newList) {
this.oldList = oldList;
this.newList = newList;
}
@Override
public int getOldListSize() {
return oldList == null ? 0 :oldList.length;
return oldList == null ? 0 :oldList.size();
}
@Override
public int getNewListSize() {
return newList == null ? 0 : newList.length;
return newList == null ? 0 : newList.size();
}
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
return (oldList[oldItemPosition] == null ) == ( newList[newItemPosition] == null) && oldList[oldItemPosition].equals(newList[newItemPosition]);
MediaLibraryItem oldItem = oldList.get(oldItemPosition);
MediaLibraryItem newItem = newList.get(newItemPosition);
return oldItem == newItem || ((oldItem == null ) == (newItem == null) && oldItem.equals(newItem));
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment