2015-01-15 13:35:35 -08:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
|
2020-09-17 11:39:34 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2015-01-15 13:35:35 -08:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2020-09-17 11:39:34 +10:00
|
|
|
import org.thoughtcrime.securesms.loki.views.UserView;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2015-02-26 18:31:22 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-07-26 09:59:15 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Conversions;
|
|
|
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
2017-08-01 08:56:00 -07:00
|
|
|
import java.util.List;
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
class MessageDetailsRecipientAdapter extends BaseAdapter implements AbsListView.RecyclerListener {
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
private final Context context;
|
2017-10-16 13:11:42 -07:00
|
|
|
private final GlideRequests glideRequests;
|
2017-09-30 08:45:45 -07:00
|
|
|
private final MessageRecord record;
|
|
|
|
private final List<RecipientDeliveryStatus> members;
|
|
|
|
private final boolean isPushGroup;
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
MessageDetailsRecipientAdapter(@NonNull Context context, @NonNull GlideRequests glideRequests,
|
|
|
|
@NonNull MessageRecord record, @NonNull List<RecipientDeliveryStatus> members,
|
|
|
|
boolean isPushGroup)
|
2015-02-26 18:31:22 -08:00
|
|
|
{
|
2017-10-16 13:11:42 -07:00
|
|
|
this.context = context;
|
|
|
|
this.glideRequests = glideRequests;
|
|
|
|
this.record = record;
|
|
|
|
this.isPushGroup = isPushGroup;
|
|
|
|
this.members = members;
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2017-09-30 08:45:45 -07:00
|
|
|
return members.size();
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int position) {
|
2017-09-30 08:45:45 -07:00
|
|
|
return members.get(position);
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
2017-07-26 09:59:15 -07:00
|
|
|
try {
|
2017-09-30 08:45:45 -07:00
|
|
|
return Conversions.byteArrayToLong(MessageDigest.getInstance("SHA1").digest(members.get(position).recipient.getAddress().serialize().getBytes()));
|
2017-07-26 09:59:15 -07:00
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
2020-09-17 11:39:34 +10:00
|
|
|
UserView result = new UserView(context);
|
|
|
|
Recipient recipient = members.get(position).getRecipient();
|
|
|
|
result.setOpenGroupThreadID(record.getThreadId());
|
|
|
|
result.bind(recipient, glideRequests, UserView.ActionIndicator.None, false);
|
|
|
|
return result;
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMovedToScrapHeap(View view) {
|
|
|
|
((MessageRecipientListItem)view).unbind();
|
|
|
|
}
|
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
|
|
|
|
static class RecipientDeliveryStatus {
|
|
|
|
|
|
|
|
enum Status {
|
|
|
|
UNKNOWN, PENDING, SENT, DELIVERED, READ
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Recipient recipient;
|
|
|
|
private final Status deliveryStatus;
|
2018-10-11 16:45:22 -07:00
|
|
|
private final boolean isUnidentified;
|
2017-09-30 08:45:45 -07:00
|
|
|
private final long timestamp;
|
|
|
|
|
2018-10-11 16:45:22 -07:00
|
|
|
RecipientDeliveryStatus(Recipient recipient, Status deliveryStatus, boolean isUnidentified, long timestamp) {
|
2017-09-30 08:45:45 -07:00
|
|
|
this.recipient = recipient;
|
|
|
|
this.deliveryStatus = deliveryStatus;
|
2018-10-11 16:45:22 -07:00
|
|
|
this.isUnidentified = isUnidentified;
|
2017-09-30 08:45:45 -07:00
|
|
|
this.timestamp = timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status getDeliveryStatus() {
|
|
|
|
return deliveryStatus;
|
|
|
|
}
|
|
|
|
|
2018-10-11 16:45:22 -07:00
|
|
|
boolean isUnidentified() {
|
|
|
|
return isUnidentified;
|
|
|
|
}
|
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
public long getTimestamp() {
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Recipient getRecipient() {
|
|
|
|
return recipient;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|