diff --git a/src/org/thoughtcrime/securesms/ConversationListAdapter.java b/src/org/thoughtcrime/securesms/ConversationListAdapter.java index 8755d69ba6..291ef72949 100644 --- a/src/org/thoughtcrime/securesms/ConversationListAdapter.java +++ b/src/org/thoughtcrime/securesms/ConversationListAdapter.java @@ -24,6 +24,7 @@ import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.CursorAdapter; +import org.whispersystems.textsecure.crypto.MasterCipher; import org.whispersystems.textsecure.crypto.MasterSecret; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.ThreadDatabase; @@ -40,18 +41,23 @@ import java.util.Set; */ public class ConversationListAdapter extends CursorAdapter implements AbsListView.RecyclerListener { - private final MasterSecret masterSecret; - private final Context context; + private final ThreadDatabase threadDatabase; + private final MasterCipher masterCipher; + private final Context context; private final LayoutInflater inflater; - private final Set batchSet = Collections.synchronizedSet(new HashSet()); - private boolean batchMode = false; + private final Set batchSet = Collections.synchronizedSet(new HashSet()); + private boolean batchMode = false; public ConversationListAdapter(Context context, Cursor cursor, MasterSecret masterSecret) { super(context, cursor); - this.masterSecret = masterSecret; - this.context = context; - this.inflater = LayoutInflater.from(context); + + if (masterSecret != null) this.masterCipher = new MasterCipher(masterSecret); + else this.masterCipher = null; + + this.context = context; + this.threadDatabase = DatabaseFactory.getThreadDatabase(context); + this.inflater = LayoutInflater.from(context); } @Override @@ -61,9 +67,9 @@ public class ConversationListAdapter extends CursorAdapter implements AbsListVie @Override public void bindView(View view, Context context, Cursor cursor) { - if (masterSecret != null) { - ThreadDatabase.Reader reader = DatabaseFactory.getThreadDatabase(context).readerFor(cursor, masterSecret); - ThreadRecord record = reader.getCurrent(); + if (masterCipher != null) { + ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, masterCipher); + ThreadRecord record = reader.getCurrent(); ((ConversationListItem)view).set(record, batchSet, batchMode); } diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index 72fe0ed03d..c519414de9 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -399,8 +399,8 @@ public class ThreadDatabase extends Database { public void onProgress(int complete, int total); } - public Reader readerFor(Cursor cursor, MasterSecret masterSecret) { - return new Reader(cursor, masterSecret); + public Reader readerFor(Cursor cursor, MasterCipher masterCipher) { + return new Reader(cursor, masterCipher); } public static class DistributionTypes { @@ -411,14 +411,12 @@ public class ThreadDatabase extends Database { public class Reader { - private final Cursor cursor; + private final Cursor cursor; private final MasterCipher masterCipher; - public Reader(Cursor cursor, MasterSecret masterSecret) { - this.cursor = cursor; - - if (masterSecret != null) this.masterCipher = new MasterCipher(masterSecret); - else this.masterCipher = null; + public Reader(Cursor cursor, MasterCipher masterCipher) { + this.cursor = cursor; + this.masterCipher = masterCipher; } public ThreadRecord getNext() {