2015-01-15 21:35:35 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-10-16 20:11:42 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2015-01-15 21:35:35 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2017-10-16 20:11:42 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
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;
|
2017-10-16 20:11:42 +00:00
|
|
|
private final GlideRequests glideRequests;
|
2017-09-30 15:45:45 +00:00
|
|
|
private final MessageRecord record;
|
|
|
|
private final List<RecipientDeliveryStatus> members;
|
|
|
|
private final boolean isPushGroup;
|
2015-01-15 21:35:35 +00:00
|
|
|
|
2018-01-25 03:17:44 +00:00
|
|
|
MessageDetailsRecipientAdapter(@NonNull Context context, @NonNull GlideRequests glideRequests,
|
|
|
|
@NonNull MessageRecord record, @NonNull List<RecipientDeliveryStatus> members,
|
|
|
|
boolean isPushGroup)
|
2015-02-27 02:31:22 +00:00
|
|
|
{
|
2017-10-16 20:11:42 +00:00
|
|
|
this.context = context;
|
|
|
|
this.glideRequests = glideRequests;
|
|
|
|
this.record = record;
|
|
|
|
this.isPushGroup = isPushGroup;
|
|
|
|
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);
|
|
|
|
|
2018-01-25 03:17:44 +00:00
|
|
|
((MessageRecipientListItem)convertView).set(glideRequests, 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;
|
2018-10-11 23:45:22 +00:00
|
|
|
private final boolean isUnidentified;
|
2017-09-30 15:45:45 +00:00
|
|
|
private final long timestamp;
|
|
|
|
|
2018-10-11 23:45:22 +00:00
|
|
|
RecipientDeliveryStatus(Recipient recipient, Status deliveryStatus, boolean isUnidentified, long timestamp) {
|
2017-09-30 15:45:45 +00:00
|
|
|
this.recipient = recipient;
|
|
|
|
this.deliveryStatus = deliveryStatus;
|
2018-10-11 23:45:22 +00:00
|
|
|
this.isUnidentified = isUnidentified;
|
2017-09-30 15:45:45 +00:00
|
|
|
this.timestamp = timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status getDeliveryStatus() {
|
|
|
|
return deliveryStatus;
|
|
|
|
}
|
|
|
|
|
2018-10-11 23:45:22 +00:00
|
|
|
boolean isUnidentified() {
|
|
|
|
return isUnidentified;
|
|
|
|
}
|
|
|
|
|
2017-09-30 15:45:45 +00:00
|
|
|
public long getTimestamp() {
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Recipient getRecipient() {
|
|
|
|
return recipient;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-15 21:35:35 +00:00
|
|
|
}
|