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
protected void onBindItemViewHolder(ViewHolder viewHolder, @NonNull MessageRecord messageRecord, int adjustedPosition) {
protected void onBindItemViewHolder(ViewHolder viewHolder, @NonNull MessageRecord messageRecord) {
long start = System.currentTimeMillis();
int rawPosition = getRawCursorPosition(adjustedPosition);
MessageRecord previousRecord = rawPosition < getItemCount() - 1 && !isFooterPosition(rawPosition + 1) ? getRecordForPositionOrThrow(rawPosition + 1) : null;
MessageRecord nextRecord = rawPosition > 0 && !isHeaderPosition(rawPosition - 1) ? getRecordForPositionOrThrow(rawPosition - 1) : null;
int adapterPosition = viewHolder.getAdapterPosition();
MessageRecord previousRecord = adapterPosition < getItemCount() - 1 && !isFooterPosition(adapterPosition + 1) ? getRecordForPositionOrThrow(adapterPosition + 1) : null;
MessageRecord nextRecord = adapterPosition > 0 && !isHeaderPosition(adapterPosition - 1) ? getRecordForPositionOrThrow(adapterPosition - 1) : null;
viewHolder.getView().bind(messageRecord,
Optional.fromNullable(previousRecord),

View File

@ -211,13 +211,6 @@ public abstract class CursorRecyclerViewAdapter<VH extends RecyclerView.ViewHold
return position - getFastAccessSize();
}
protected int getRawCursorPosition(int position) {
if (hasHeaderView()) {
position += 1;
}
return position;
}
protected int getFastAccessItemViewType(int position) {
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 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 int getItemViewType(@NonNull T record);
protected abstract boolean isRecordForId(@NonNull T record, long id);
@ -69,13 +69,13 @@ public abstract class FastCursorRecyclerViewAdapter<VH extends RecyclerView.View
@Override
public void onBindItemViewHolder(VH viewHolder, @NonNull Cursor cursor) {
T record = getRecordFromCursor(cursor);
onBindItemViewHolder(viewHolder, record, cursor.getPosition());
onBindItemViewHolder(viewHolder, record);
}
@Override
public void onBindFastAccessItemViewHolder(VH viewHolder, int position) {
int calculatedPosition = getCalculatedPosition(position);
onBindItemViewHolder(viewHolder, fastRecords.get(calculatedPosition), calculatedPosition);
onBindItemViewHolder(viewHolder, fastRecords.get(calculatedPosition));
}
@Override