mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 08:09:12 +01:00
migrate conversation list to RecyclerView
fixes #2488 fixes #2333 // FREEBIE
This commit is contained in:
committed by
Moxie Marlinspike
parent
cbcd53a8a0
commit
99d3374d35
@@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.database;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.DataSetObserver;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
@@ -90,17 +91,34 @@ public abstract class CursorRecyclerViewAdapter<VH extends RecyclerView.ViewHold
|
||||
: 0;
|
||||
}
|
||||
|
||||
public abstract void onBindViewHolder(VH viewHolder, Cursor cursor);
|
||||
public abstract void onBindViewHolder(VH viewHolder, @NonNull Cursor cursor);
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(VH viewHolder, int position) {
|
||||
moveToPositionOrThrow(position);
|
||||
onBindViewHolder(viewHolder, cursor);
|
||||
}
|
||||
|
||||
@Override public int getItemViewType(int position) {
|
||||
moveToPositionOrThrow(position);
|
||||
return getItemViewType(cursor);
|
||||
}
|
||||
|
||||
public int getItemViewType(@NonNull Cursor cursor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void assertActiveCursor() {
|
||||
if (!isActiveCursor()) {
|
||||
throw new IllegalStateException("this should only be called when the cursor is valid");
|
||||
}
|
||||
}
|
||||
|
||||
private void moveToPositionOrThrow(final int position) {
|
||||
assertActiveCursor();
|
||||
if (!cursor.moveToPosition(position)) {
|
||||
throw new IllegalStateException("couldn't move cursor to position " + position);
|
||||
}
|
||||
onBindViewHolder(viewHolder, cursor);
|
||||
}
|
||||
|
||||
private boolean isActiveCursor() {
|
||||
|
||||
Reference in New Issue
Block a user