2015-01-15 21:35:35 +00: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 01:39:34 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2021-01-21 04:42:43 +00:00
|
|
|
|
2015-01-15 21:35:35 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2020-09-17 01:39:34 +00:00
|
|
|
import org.thoughtcrime.securesms.loki.views.UserView;
|
2017-10-16 20:11:42 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2021-05-18 06:03:47 +00:00
|
|
|
import org.session.libsession.utilities.recipients.Recipient;
|
2021-01-15 05:51:53 +00:00
|
|
|
import org.session.libsession.utilities.Conversions;
|
2017-07-26 16:59:15 +00:00
|
|
|
|
|
|
|
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;
|
2021-01-21 04:42:43 +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) {
|
2020-09-17 01:39:34 +00: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 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMovedToScrapHeap(View view) {
|
2020-12-07 02:30:52 +00:00
|
|
|
((UserView)view).unbind();
|
2015-01-15 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|