2015-01-15 21:35:35 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2015-02-27 02:31:22 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-07-26 16:59:15 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Conversions;
|
|
|
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
2017-08-01 15:56:00 +00:00
|
|
|
import java.util.List;
|
2015-01-15 21:35:35 +00:00
|
|
|
|
2017-09-30 15:45:45 +00:00
|
|
|
class MessageDetailsRecipientAdapter extends BaseAdapter implements AbsListView.RecyclerListener {
|
2015-01-15 21:35:35 +00:00
|
|
|
|
2017-09-30 15:45:45 +00:00
|
|
|
private final Context context;
|
|
|
|
private final MasterSecret masterSecret;
|
|
|
|
private final MessageRecord record;
|
|
|
|
private final List<RecipientDeliveryStatus> members;
|
|
|
|
private final boolean isPushGroup;
|
2015-01-15 21:35:35 +00:00
|
|
|
|
2017-09-30 15:45:45 +00:00
|
|
|
MessageDetailsRecipientAdapter(Context context, MasterSecret masterSecret, MessageRecord record,
|
|
|
|
List<RecipientDeliveryStatus> members, boolean isPushGroup)
|
2015-02-27 02:31:22 +00:00
|
|
|
{
|
2015-01-15 21:35:35 +00:00
|
|
|
this.context = context;
|
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.record = record;
|
2015-02-27 02:31:22 +00:00
|
|
|
this.isPushGroup = isPushGroup;
|
2017-09-30 15:45:45 +00:00
|
|
|
this.members = members;
|
2015-01-15 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2017-09-30 15:45:45 +00:00
|
|
|
return members.size();
|
2015-01-15 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int position) {
|
2017-09-30 15:45:45 +00:00
|
|
|
return members.get(position);
|
2015-01-15 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
2017-07-26 16:59:15 +00:00
|
|
|
try {
|
2017-09-30 15:45:45 +00:00
|
|
|
return Conversions.byteArrayToLong(MessageDigest.getInstance("SHA1").digest(members.get(position).recipient.getAddress().serialize().getBytes()));
|
2017-07-26 16:59:15 +00:00
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
2015-01-15 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
if (convertView == null) {
|
2015-02-27 19:07:20 +00:00
|
|
|
convertView = LayoutInflater.from(context).inflate(R.layout.message_recipient_list_item, parent, false);
|
2015-01-15 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 15:45:45 +00:00
|
|
|
RecipientDeliveryStatus member = members.get(position);
|
|
|
|
|
|
|
|
((MessageRecipientListItem)convertView).set(masterSecret, record, member, isPushGroup);
|
2015-01-15 21:35:35 +00:00
|
|
|
return convertView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMovedToScrapHeap(View view) {
|
|
|
|
((MessageRecipientListItem)view).unbind();
|
|
|
|
}
|
|
|
|
|
2017-09-30 15:45:45 +00:00
|
|
|
|
|
|
|
static class RecipientDeliveryStatus {
|
|
|
|
|
|
|
|
enum Status {
|
|
|
|
UNKNOWN, PENDING, SENT, DELIVERED, READ
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Recipient recipient;
|
|
|
|
private final Status deliveryStatus;
|
|
|
|
private final long timestamp;
|
|
|
|
|
|
|
|
RecipientDeliveryStatus(Recipient recipient, Status deliveryStatus, long timestamp) {
|
|
|
|
this.recipient = recipient;
|
|
|
|
this.deliveryStatus = deliveryStatus;
|
|
|
|
this.timestamp = timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status getDeliveryStatus() {
|
|
|
|
return deliveryStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getTimestamp() {
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Recipient getRecipient() {
|
|
|
|
return recipient;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-15 21:35:35 +00:00
|
|
|
}
|