Fix next/prev message detection with fastRecords.

The previous way we were getting the next/previous record didn't take into
consideration that some records aren't in the cursor -- some are in the
fastRecords map. We now use the proper position to get the next/previous
message.
This commit is contained in:
Greyson Parrelli 2018-07-25 00:24:49 -04:00
parent ec43c3ae5a
commit e96a02ab35
3 changed files with 7 additions and 15 deletions

View File

@ -190,12 +190,11 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
} }
@Override @Override
protected void onBindItemViewHolder(ViewHolder viewHolder, @NonNull MessageRecord messageRecord, int adjustedPosition) { protected void onBindItemViewHolder(ViewHolder viewHolder, @NonNull MessageRecord messageRecord) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
int rawPosition = getRawCursorPosition(adjustedPosition); int adapterPosition = viewHolder.getAdapterPosition();
MessageRecord previousRecord = rawPosition < getItemCount() - 1 && !isFooterPosition(rawPosition + 1) ? getRecordForPositionOrThrow(rawPosition + 1) : null; MessageRecord previousRecord = adapterPosition < getItemCount() - 1 && !isFooterPosition(adapterPosition + 1) ? getRecordForPositionOrThrow(adapterPosition + 1) : null;
MessageRecord nextRecord = rawPosition > 0 && !isHeaderPosition(rawPosition - 1) ? getRecordForPositionOrThrow(rawPosition - 1) : null; MessageRecord nextRecord = adapterPosition > 0 && !isHeaderPosition(adapterPosition - 1) ? getRecordForPositionOrThrow(adapterPosition - 1) : null;
viewHolder.getView().bind(messageRecord, viewHolder.getView().bind(messageRecord,
Optional.fromNullable(previousRecord), Optional.fromNullable(previousRecord),

View File

@ -211,13 +211,6 @@ public abstract class CursorRecyclerViewAdapter<VH extends RecyclerView.ViewHold
return position - getFastAccessSize(); return position - getFastAccessSize();
} }
protected int getRawCursorPosition(int position) {
if (hasHeaderView()) {
position += 1;
}
return position;
}
protected int getFastAccessItemViewType(int position) { protected int getFastAccessItemViewType(int position) {
return 0; return 0;
} }

View File

@ -55,7 +55,7 @@ public abstract class FastCursorRecyclerViewAdapter<VH extends RecyclerView.View
} }
protected abstract T getRecordFromCursor(@NonNull Cursor cursor); protected abstract T getRecordFromCursor(@NonNull Cursor cursor);
protected abstract void onBindItemViewHolder(VH viewHolder, @NonNull T record, int position); protected abstract void onBindItemViewHolder(VH viewHolder, @NonNull T record);
protected abstract long getItemId(@NonNull T record); protected abstract long getItemId(@NonNull T record);
protected abstract int getItemViewType(@NonNull T record); protected abstract int getItemViewType(@NonNull T record);
protected abstract boolean isRecordForId(@NonNull T record, long id); protected abstract boolean isRecordForId(@NonNull T record, long id);
@ -69,13 +69,13 @@ public abstract class FastCursorRecyclerViewAdapter<VH extends RecyclerView.View
@Override @Override
public void onBindItemViewHolder(VH viewHolder, @NonNull Cursor cursor) { public void onBindItemViewHolder(VH viewHolder, @NonNull Cursor cursor) {
T record = getRecordFromCursor(cursor); T record = getRecordFromCursor(cursor);
onBindItemViewHolder(viewHolder, record, cursor.getPosition()); onBindItemViewHolder(viewHolder, record);
} }
@Override @Override
public void onBindFastAccessItemViewHolder(VH viewHolder, int position) { public void onBindFastAccessItemViewHolder(VH viewHolder, int position) {
int calculatedPosition = getCalculatedPosition(position); int calculatedPosition = getCalculatedPosition(position);
onBindItemViewHolder(viewHolder, fastRecords.get(calculatedPosition), calculatedPosition); onBindItemViewHolder(viewHolder, fastRecords.get(calculatedPosition));
} }
@Override @Override