Skip to content

Commit

Permalink
We need to override getItemId if we set hasStableIds to true (#3286)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Apr 29, 2020
1 parent 18270f0 commit e1c08cc
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public SitePermissionAdapter(Context aContext, PermissionSiteItemCallback callba
public void setSites(@NonNull List<SitePermission> sites) {
if (mDisplayList == null) {
mDisplayList = sites;
notifyItemRangeChanged(0, sites.size());
notifyDataSetChanged();

} else {
notifyDiff(sites);
Expand All @@ -78,7 +78,7 @@ public int getNewListSize() {

@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
return mDisplayList.get(oldItemPosition).url.equals(newDisplayList.get(newItemPosition).url);
return mDisplayList.get(oldItemPosition).id == newDisplayList.get(newItemPosition).id;
}

@Override
Expand Down Expand Up @@ -125,6 +125,11 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
siteHolder.binding.setItem(site);
}

@Override
public long getItemId(int position) {
return mDisplayList.get(position).id;
}

@Override
public int getItemCount() {
return mDisplayList == null ? 0 : mDisplayList.size();
Expand Down

0 comments on commit e1c08cc

Please sign in to comment.