Use stable ids in adapter

This commit is contained in:
Stefan Niedermann 2020-06-10 13:10:49 +02:00
parent 6b0e47da85
commit 56ab5105e7
3 changed files with 13 additions and 5 deletions

View file

@ -47,6 +47,14 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
this.gridView = gridView;
this.mainColor = context.getResources().getColor(R.color.defaultBrand);
this.textColor = Color.WHITE;
setHasStableIds(true);
}
@Override
public long getItemId(int position) {
return getItemViewType(position) == TYPE_SECTION
? ((SectionItem) getItem(position)).getTitle().hashCode()
: ((DBNote) getItem(position)).getId();
}
/**

View file

@ -138,7 +138,6 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder implements
}
private void bindContent(@NonNull TextView textView, @NonNull CharSequence charSequence) {
textView.setText(charSequence);
if (renderMarkdown) {
new Thread(() -> {
try {
@ -148,6 +147,8 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder implements
// Workaround for RxMarkdown: https://github.com/stefan-niedermann/nextcloud-notes/issues/668
}
}).start();
} else {
textView.setText(charSequence);
}
}

View file

@ -11,13 +11,12 @@ public class SectionViewHolder extends RecyclerView.ViewHolder {
public SectionViewHolder(ItemNotesListSectionItemBinding binding) {
super(binding.getRoot());
this.binding = binding;
if (itemView.getLayoutParams() != null && itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams()).setFullSpan(true);
}
}
public void bind(SectionItem item) {
binding.sectionTitle.setText(item.getTitle());
if (itemView.getLayoutParams() != null && itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams()).setFullSpan(true);
}
}
}