Minor ConversationList scrolling optimization.

This commit is contained in:
Moxie Marlinspike 2014-03-16 14:36:21 -07:00
parent 34c885f08d
commit b860aeff85
2 changed files with 22 additions and 18 deletions

View File

@ -24,6 +24,7 @@ import android.view.ViewGroup;
import android.widget.AbsListView; import android.widget.AbsListView;
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
import org.whispersystems.textsecure.crypto.MasterCipher;
import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase;
@ -40,7 +41,8 @@ import java.util.Set;
*/ */
public class ConversationListAdapter extends CursorAdapter implements AbsListView.RecyclerListener { public class ConversationListAdapter extends CursorAdapter implements AbsListView.RecyclerListener {
private final MasterSecret masterSecret; private final ThreadDatabase threadDatabase;
private final MasterCipher masterCipher;
private final Context context; private final Context context;
private final LayoutInflater inflater; private final LayoutInflater inflater;
@ -49,8 +51,12 @@ public class ConversationListAdapter extends CursorAdapter implements AbsListVie
public ConversationListAdapter(Context context, Cursor cursor, MasterSecret masterSecret) { public ConversationListAdapter(Context context, Cursor cursor, MasterSecret masterSecret) {
super(context, cursor); super(context, cursor);
this.masterSecret = masterSecret;
if (masterSecret != null) this.masterCipher = new MasterCipher(masterSecret);
else this.masterCipher = null;
this.context = context; this.context = context;
this.threadDatabase = DatabaseFactory.getThreadDatabase(context);
this.inflater = LayoutInflater.from(context); this.inflater = LayoutInflater.from(context);
} }
@ -61,8 +67,8 @@ public class ConversationListAdapter extends CursorAdapter implements AbsListVie
@Override @Override
public void bindView(View view, Context context, Cursor cursor) { public void bindView(View view, Context context, Cursor cursor) {
if (masterSecret != null) { if (masterCipher != null) {
ThreadDatabase.Reader reader = DatabaseFactory.getThreadDatabase(context).readerFor(cursor, masterSecret); ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, masterCipher);
ThreadRecord record = reader.getCurrent(); ThreadRecord record = reader.getCurrent();
((ConversationListItem)view).set(record, batchSet, batchMode); ((ConversationListItem)view).set(record, batchSet, batchMode);

View File

@ -399,8 +399,8 @@ public class ThreadDatabase extends Database {
public void onProgress(int complete, int total); public void onProgress(int complete, int total);
} }
public Reader readerFor(Cursor cursor, MasterSecret masterSecret) { public Reader readerFor(Cursor cursor, MasterCipher masterCipher) {
return new Reader(cursor, masterSecret); return new Reader(cursor, masterCipher);
} }
public static class DistributionTypes { public static class DistributionTypes {
@ -414,11 +414,9 @@ public class ThreadDatabase extends Database {
private final Cursor cursor; private final Cursor cursor;
private final MasterCipher masterCipher; private final MasterCipher masterCipher;
public Reader(Cursor cursor, MasterSecret masterSecret) { public Reader(Cursor cursor, MasterCipher masterCipher) {
this.cursor = cursor; this.cursor = cursor;
this.masterCipher = masterCipher;
if (masterSecret != null) this.masterCipher = new MasterCipher(masterSecret);
else this.masterCipher = null;
} }
public ThreadRecord getNext() { public ThreadRecord getNext() {