Bug fixed: Use getLayoutPosition instead of getAdapterPosition. #994, #988

This commit is contained in:
Isc 2020-12-17 02:14:18 +08:00 committed by Niedermann IT-Dienstleistungen
parent 69e453dc54
commit f864ade4f5
2 changed files with 5 additions and 5 deletions

View file

@ -50,8 +50,8 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
@CallSuper
public void bind(@NonNull DBNote note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) {
itemView.setOnClickListener((view) -> noteClickListener.onNoteClick(getAdapterPosition(), view));
itemView.setOnLongClickListener((view) -> noteClickListener.onNoteLongClick(getAdapterPosition(), view));
itemView.setOnClickListener((view) -> noteClickListener.onNoteClick(getLayoutPosition(), view));
itemView.setOnLongClickListener((view) -> noteClickListener.onNoteLongClick(getLayoutPosition(), view));
}
protected void bindStatus(AppCompatImageView noteStatus, DBStatus status, int mainColor) {
@ -106,7 +106,7 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
protected void bindFavorite(@NonNull ImageView noteFavorite, boolean isFavorite) {
noteFavorite.setImageResource(isFavorite ? R.drawable.ic_star_yellow_24dp : R.drawable.ic_star_grey_ccc_24dp);
noteFavorite.setOnClickListener(view -> noteClickListener.onNoteFavoriteClick(getAdapterPosition(), view));
noteFavorite.setOnClickListener(view -> noteClickListener.onNoteFavoriteClick(getLayoutPosition(), view));
}
protected void bindSearchableContent(@NonNull Context context, @NonNull TextView textView, @Nullable CharSequence searchQuery, @NonNull String content, int mainColor) {

View file

@ -71,7 +71,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
switch (direction) {
case ItemTouchHelper.LEFT:
final DBNote dbNoteWithoutContent = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
final DBNote dbNoteWithoutContent = (DBNote) adapter.getItem(viewHolder.getLayoutPosition());
final DBNote dbNote = db.getNote(dbNoteWithoutContent.getAccountId(), dbNoteWithoutContent.getId());
db.deleteNoteAndSync(ssoAccount, dbNote.getId());
adapter.remove(dbNote);
@ -92,7 +92,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
}
break;
case ItemTouchHelper.RIGHT:
final DBNote adapterNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
final DBNote adapterNote = (DBNote) adapter.getItem(viewHolder.getLayoutPosition());
db.toggleFavorite(ssoAccount, adapterNote, syncCallBack);
refreshLists.run();
break;