|
|
@ -22,12 +22,14 @@ import android.support.annotation.LayoutRes;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnLongClickListener;
|
|
|
|
import android.view.View.OnLongClickListener;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.thoughtcrime.redphone.util.Conversions;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter;
|
|
|
|
import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter;
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
@ -39,6 +41,8 @@ import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
import org.thoughtcrime.securesms.util.LRUCache;
|
|
|
|
import org.thoughtcrime.securesms.util.LRUCache;
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.ref.SoftReference;
|
|
|
|
import java.lang.ref.SoftReference;
|
|
|
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Locale;
|
|
|
@ -46,6 +50,7 @@ import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.util.VisibleForTesting;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A cursor adapter for a conversation thread. Ultimately
|
|
|
|
* A cursor adapter for a conversation thread. Ultimately
|
|
|
@ -69,12 +74,13 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
|
|
|
|
|
|
|
|
|
|
|
private final Set<MessageRecord> batchSelected = Collections.synchronizedSet(new HashSet<MessageRecord>());
|
|
|
|
private final Set<MessageRecord> batchSelected = Collections.synchronizedSet(new HashSet<MessageRecord>());
|
|
|
|
|
|
|
|
|
|
|
|
private final ItemClickListener clickListener;
|
|
|
|
private final @Nullable ItemClickListener clickListener;
|
|
|
|
private final MasterSecret masterSecret;
|
|
|
|
private final @NonNull MasterSecret masterSecret;
|
|
|
|
private final Locale locale;
|
|
|
|
private final @NonNull Locale locale;
|
|
|
|
private final Recipients recipients;
|
|
|
|
private final @NonNull Recipients recipients;
|
|
|
|
private final MmsSmsDatabase db;
|
|
|
|
private final @NonNull MmsSmsDatabase db;
|
|
|
|
private final LayoutInflater inflater;
|
|
|
|
private final @NonNull LayoutInflater inflater;
|
|
|
|
|
|
|
|
private final @NonNull MessageDigest digest;
|
|
|
|
|
|
|
|
|
|
|
|
protected static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
protected static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
public <V extends View & BindableConversationItem> ViewHolder(final @NonNull V itemView) {
|
|
|
|
public <V extends View & BindableConversationItem> ViewHolder(final @NonNull V itemView) {
|
|
|
@ -92,6 +98,23 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
|
|
|
void onItemLongClick(ConversationItem item);
|
|
|
|
void onItemLongClick(ConversationItem item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("ConstantConditions")
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
|
|
|
ConversationAdapter(Context context, Cursor cursor) {
|
|
|
|
|
|
|
|
super(context, cursor);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
this.masterSecret = null;
|
|
|
|
|
|
|
|
this.locale = null;
|
|
|
|
|
|
|
|
this.clickListener = null;
|
|
|
|
|
|
|
|
this.recipients = null;
|
|
|
|
|
|
|
|
this.inflater = null;
|
|
|
|
|
|
|
|
this.db = null;
|
|
|
|
|
|
|
|
this.digest = MessageDigest.getInstance("SHA1");
|
|
|
|
|
|
|
|
} catch (NoSuchAlgorithmException nsae) {
|
|
|
|
|
|
|
|
throw new AssertionError("SHA1 isn't supported!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ConversationAdapter(@NonNull Context context,
|
|
|
|
public ConversationAdapter(@NonNull Context context,
|
|
|
|
@NonNull MasterSecret masterSecret,
|
|
|
|
@NonNull MasterSecret masterSecret,
|
|
|
|
@NonNull Locale locale,
|
|
|
|
@NonNull Locale locale,
|
|
|
@ -100,12 +123,19 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
|
|
|
@NonNull Recipients recipients)
|
|
|
|
@NonNull Recipients recipients)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
super(context, cursor);
|
|
|
|
super(context, cursor);
|
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
try {
|
|
|
|
this.locale = locale;
|
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.clickListener = clickListener;
|
|
|
|
this.locale = locale;
|
|
|
|
this.recipients = recipients;
|
|
|
|
this.clickListener = clickListener;
|
|
|
|
this.inflater = LayoutInflater.from(context);
|
|
|
|
this.recipients = recipients;
|
|
|
|
this.db = DatabaseFactory.getMmsSmsDatabase(context);
|
|
|
|
this.inflater = LayoutInflater.from(context);
|
|
|
|
|
|
|
|
this.db = DatabaseFactory.getMmsSmsDatabase(context);
|
|
|
|
|
|
|
|
this.digest = MessageDigest.getInstance("SHA1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setHasStableIds(true);
|
|
|
|
|
|
|
|
} catch (NoSuchAlgorithmException nsae) {
|
|
|
|
|
|
|
|
throw new AssertionError("SHA1 isn't supported!");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -114,7 +144,8 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
|
|
|
super.changeCursor(cursor);
|
|
|
|
super.changeCursor(cursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void onBindItemViewHolder(ViewHolder viewHolder, @NonNull Cursor cursor) {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onBindItemViewHolder(ViewHolder viewHolder, @NonNull Cursor cursor) {
|
|
|
|
long id = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.ID));
|
|
|
|
long id = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.ID));
|
|
|
|
String type = cursor.getString(cursor.getColumnIndexOrThrow(MmsSmsDatabase.TRANSPORT));
|
|
|
|
String type = cursor.getString(cursor.getColumnIndexOrThrow(MmsSmsDatabase.TRANSPORT));
|
|
|
|
MessageRecord messageRecord = getMessageRecord(id, cursor, type);
|
|
|
|
MessageRecord messageRecord = getMessageRecord(id, cursor, type);
|
|
|
@ -122,7 +153,8 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
|
|
|
viewHolder.getView().bind(masterSecret, messageRecord, locale, batchSelected, recipients);
|
|
|
|
viewHolder.getView().bind(masterSecret, messageRecord, locale, batchSelected, recipients);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public ViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public ViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
final V itemView = ViewUtil.inflate(inflater, parent, getLayoutForViewType(viewType));
|
|
|
|
final V itemView = ViewUtil.inflate(inflater, parent, getLayoutForViewType(viewType));
|
|
|
|
if (viewType == MESSAGE_TYPE_INCOMING || viewType == MESSAGE_TYPE_OUTGOING) {
|
|
|
|
if (viewType == MESSAGE_TYPE_INCOMING || viewType == MESSAGE_TYPE_OUTGOING) {
|
|
|
|
itemView.setOnClickListener(new OnClickListener() {
|
|
|
|
itemView.setOnClickListener(new OnClickListener() {
|
|
|
@ -143,7 +175,8 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
|
|
|
return new ViewHolder(itemView);
|
|
|
|
return new ViewHolder(itemView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void onItemViewRecycled(ViewHolder holder) {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onItemViewRecycled(ViewHolder holder) {
|
|
|
|
holder.getView().unbind();
|
|
|
|
holder.getView().unbind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -171,6 +204,13 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public long getItemId(@NonNull Cursor cursor) {
|
|
|
|
|
|
|
|
final String unique = cursor.getString(cursor.getColumnIndexOrThrow(MmsSmsColumns.UNIQUE_ROW_ID));
|
|
|
|
|
|
|
|
final byte[] bytes = digest.digest(unique.getBytes());
|
|
|
|
|
|
|
|
return Conversions.byteArrayToLong(bytes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private MessageRecord getMessageRecord(long messageId, Cursor cursor, String type) {
|
|
|
|
private MessageRecord getMessageRecord(long messageId, Cursor cursor, String type) {
|
|
|
|
final SoftReference<MessageRecord> reference = messageRecordCache.get(type + messageId);
|
|
|
|
final SoftReference<MessageRecord> reference = messageRecordCache.get(type + messageId);
|
|
|
|
if (reference != null) {
|
|
|
|
if (reference != null) {
|
|
|
|