2019-01-31 19:28:40 -08:00
|
|
|
package org.thoughtcrime.securesms.conversation;
|
2015-09-16 17:31:24 -07:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2016-08-15 20:23:56 -07:00
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2015-09-16 17:31:24 -07:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2019-01-31 19:28:40 -08:00
|
|
|
import org.thoughtcrime.securesms.BindableConversationItem;
|
|
|
|
import org.thoughtcrime.securesms.VerifyIdentityActivity;
|
2016-08-29 17:49:49 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
2015-09-16 17:31:24 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2018-08-01 11:09:24 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2015-09-16 17:31:24 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
2015-09-21 10:54:23 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DateUtils;
|
2018-06-26 10:27:44 -07:00
|
|
|
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
2015-09-16 17:31:24 -07:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2016-08-29 17:49:49 -07:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2015-09-16 17:31:24 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2016-08-29 17:49:49 -07:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2015-09-16 17:31:24 -07:00
|
|
|
|
2015-09-15 15:28:27 -07:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Set;
|
2016-08-29 17:49:49 -07:00
|
|
|
import java.util.concurrent.ExecutionException;
|
2015-09-15 15:28:27 -07:00
|
|
|
|
2020-01-16 11:37:52 +11:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2015-09-16 17:31:24 -07:00
|
|
|
public class ConversationUpdateItem extends LinearLayout
|
2017-08-01 08:56:00 -07:00
|
|
|
implements RecipientModifiedListener, BindableConversationItem
|
2015-09-16 17:31:24 -07:00
|
|
|
{
|
|
|
|
private static final String TAG = ConversationUpdateItem.class.getSimpleName();
|
|
|
|
|
2016-08-29 17:49:49 -07:00
|
|
|
private Set<MessageRecord> batchSelected;
|
|
|
|
|
2015-09-16 17:31:24 -07:00
|
|
|
private ImageView icon;
|
2018-06-26 10:27:44 -07:00
|
|
|
private TextView title;
|
2015-09-16 17:31:24 -07:00
|
|
|
private TextView body;
|
2015-09-21 10:54:23 -07:00
|
|
|
private TextView date;
|
2015-09-16 17:31:24 -07:00
|
|
|
private Recipient sender;
|
|
|
|
private MessageRecord messageRecord;
|
2015-09-21 10:54:23 -07:00
|
|
|
private Locale locale;
|
2015-09-16 17:31:24 -07:00
|
|
|
|
|
|
|
public ConversationUpdateItem(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConversationUpdateItem(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
this.icon = findViewById(R.id.conversation_update_icon);
|
|
|
|
this.title = findViewById(R.id.conversation_update_title);
|
|
|
|
this.body = findViewById(R.id.conversation_update_body);
|
|
|
|
this.date = findViewById(R.id.conversation_update_date);
|
2015-09-16 17:31:24 -07:00
|
|
|
|
2016-08-29 17:49:49 -07:00
|
|
|
this.setOnClickListener(new InternalClickListener(null));
|
2015-09-16 17:31:24 -07:00
|
|
|
}
|
|
|
|
|
2015-09-15 15:28:27 -07:00
|
|
|
@Override
|
2018-06-26 10:27:44 -07:00
|
|
|
public void bind(@NonNull MessageRecord messageRecord,
|
|
|
|
@NonNull Optional<MessageRecord> previousMessageRecord,
|
|
|
|
@NonNull Optional<MessageRecord> nextMessageRecord,
|
|
|
|
@NonNull GlideRequests glideRequests,
|
|
|
|
@NonNull Locale locale,
|
|
|
|
@NonNull Set<MessageRecord> batchSelected,
|
|
|
|
@NonNull Recipient conversationRecipient,
|
2019-02-01 09:06:59 -08:00
|
|
|
@Nullable String searchQuery,
|
2018-06-26 10:27:44 -07:00
|
|
|
boolean pulseUpdate)
|
2015-09-15 15:28:27 -07:00
|
|
|
{
|
2016-08-29 17:49:49 -07:00
|
|
|
this.batchSelected = batchSelected;
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2016-08-29 17:49:49 -07:00
|
|
|
bind(messageRecord, locale);
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
|
|
|
|
2018-04-02 16:17:32 -07:00
|
|
|
@Override
|
|
|
|
public void setEventListener(@Nullable EventListener listener) {
|
|
|
|
// No events to report yet
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
@Override
|
|
|
|
public MessageRecord getMessageRecord() {
|
|
|
|
return messageRecord;
|
2015-09-15 15:28:27 -07:00
|
|
|
}
|
|
|
|
|
2015-09-21 10:54:23 -07:00
|
|
|
private void bind(@NonNull MessageRecord messageRecord, @NonNull Locale locale) {
|
2015-09-16 17:31:24 -07:00
|
|
|
this.messageRecord = messageRecord;
|
|
|
|
this.sender = messageRecord.getIndividualRecipient();
|
2015-09-21 10:54:23 -07:00
|
|
|
this.locale = locale;
|
2015-09-16 17:31:24 -07:00
|
|
|
|
|
|
|
this.sender.addListener(this);
|
|
|
|
|
2020-05-22 09:53:04 +10:00
|
|
|
if (messageRecord.isGroupAction()) setGroupRecord(messageRecord);
|
|
|
|
else if (messageRecord.isCallLog()) setCallRecord(messageRecord);
|
|
|
|
else if (messageRecord.isJoined()) setJoinedRecord(messageRecord);
|
|
|
|
else if (messageRecord.isExpirationTimerUpdate()) setTimerRecord(messageRecord);
|
|
|
|
else if (messageRecord.isEndSession()) setEndSessionRecord(messageRecord);
|
|
|
|
else if (messageRecord.isIdentityUpdate()) setIdentityRecord(messageRecord);
|
2017-06-06 18:03:09 -07:00
|
|
|
else if (messageRecord.isIdentityVerified() ||
|
2020-05-22 09:53:04 +10:00
|
|
|
messageRecord.isIdentityDefault()) setIdentityVerifyUpdate(messageRecord);
|
2019-12-06 13:00:08 +11:00
|
|
|
else if (messageRecord.isLokiSessionRestoreSent()) setTextMessageRecord(messageRecord);
|
2020-08-24 11:41:39 +10:00
|
|
|
else if (messageRecord.isLokiSessionRestoreDone()) setTextMessageRecord(messageRecord);
|
2020-05-22 09:53:04 +10:00
|
|
|
else throw new AssertionError("Neither group nor log nor joined.");
|
2016-08-29 17:49:49 -07:00
|
|
|
|
|
|
|
if (batchSelected.contains(messageRecord)) setSelected(true);
|
|
|
|
else setSelected(false);
|
2015-09-21 10:54:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setCallRecord(MessageRecord messageRecord) {
|
|
|
|
if (messageRecord.isIncomingCall()) icon.setImageResource(R.drawable.ic_call_received_grey600_24dp);
|
|
|
|
else if (messageRecord.isOutgoingCall()) icon.setImageResource(R.drawable.ic_call_made_grey600_24dp);
|
|
|
|
else icon.setImageResource(R.drawable.ic_call_missed_grey600_24dp);
|
|
|
|
|
2019-03-13 18:28:16 -03:00
|
|
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
2015-09-21 10:54:23 -07:00
|
|
|
date.setText(DateUtils.getExtendedRelativeTimeSpanString(getContext(), locale, messageRecord.getDateReceived()));
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
title.setVisibility(GONE);
|
|
|
|
body.setVisibility(VISIBLE);
|
2015-09-21 10:54:23 -07:00
|
|
|
date.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private void setTimerRecord(final MessageRecord messageRecord) {
|
|
|
|
if (messageRecord.getExpiresIn() > 0) {
|
2018-06-26 10:27:44 -07:00
|
|
|
icon.setImageResource(R.drawable.ic_timer);
|
2020-01-16 11:37:52 +11:00
|
|
|
icon.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY));
|
2016-08-15 20:23:56 -07:00
|
|
|
} else {
|
2018-06-26 10:27:44 -07:00
|
|
|
icon.setImageResource(R.drawable.ic_timer_disabled);
|
2020-01-16 11:37:52 +11:00
|
|
|
icon.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY));
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
title.setText(ExpirationUtil.getExpirationDisplayValue(getContext(), (int)(messageRecord.getExpiresIn() / 1000)));
|
2019-03-13 18:28:16 -03:00
|
|
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
title.setVisibility(VISIBLE);
|
|
|
|
body.setVisibility(VISIBLE);
|
|
|
|
date.setVisibility(GONE);
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
|
|
|
|
2016-08-29 17:49:49 -07:00
|
|
|
private void setIdentityRecord(final MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_security_white_24dp);
|
|
|
|
icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
|
2019-03-13 18:28:16 -03:00
|
|
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
title.setVisibility(GONE);
|
|
|
|
body.setVisibility(VISIBLE);
|
|
|
|
date.setVisibility(GONE);
|
2016-08-29 17:49:49 -07:00
|
|
|
}
|
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private void setIdentityVerifyUpdate(final MessageRecord messageRecord) {
|
|
|
|
if (messageRecord.isIdentityVerified()) icon.setImageResource(R.drawable.ic_check_white_24dp);
|
|
|
|
else icon.setImageResource(R.drawable.ic_info_outline_white_24dp);
|
|
|
|
|
|
|
|
icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
|
2019-03-13 18:28:16 -03:00
|
|
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
title.setVisibility(GONE);
|
|
|
|
body.setVisibility(VISIBLE);
|
|
|
|
date.setVisibility(GONE);
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
|
|
|
|
2015-09-21 10:54:23 -07:00
|
|
|
private void setGroupRecord(MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_group_grey600_24dp);
|
2016-08-15 20:23:56 -07:00
|
|
|
icon.clearColorFilter();
|
2015-09-21 10:54:23 -07:00
|
|
|
|
2018-02-01 18:29:09 -08:00
|
|
|
GroupUtil.getDescription(getContext(), messageRecord.getBody()).addListener(this);
|
2019-03-13 18:28:16 -03:00
|
|
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
2015-09-21 10:54:23 -07:00
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
title.setVisibility(GONE);
|
|
|
|
body.setVisibility(VISIBLE);
|
|
|
|
date.setVisibility(GONE);
|
2015-09-16 17:31:24 -07:00
|
|
|
}
|
|
|
|
|
2015-10-27 12:18:02 -07:00
|
|
|
private void setJoinedRecord(MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_favorite_grey600_24dp);
|
2016-08-15 20:23:56 -07:00
|
|
|
icon.clearColorFilter();
|
2019-03-13 18:28:16 -03:00
|
|
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
title.setVisibility(GONE);
|
|
|
|
body.setVisibility(VISIBLE);
|
|
|
|
date.setVisibility(GONE);
|
2015-10-27 12:18:02 -07:00
|
|
|
}
|
|
|
|
|
2016-09-12 17:26:46 +02:00
|
|
|
private void setEndSessionRecord(MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_refresh_white_24dp);
|
|
|
|
icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
|
2019-03-13 18:28:16 -03:00
|
|
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
title.setVisibility(GONE);
|
|
|
|
body.setVisibility(VISIBLE);
|
|
|
|
date.setVisibility(GONE);
|
2016-09-12 17:26:46 +02:00
|
|
|
}
|
2019-12-05 13:56:12 +11:00
|
|
|
|
|
|
|
private void setTextMessageRecord(MessageRecord messageRecord) {
|
|
|
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
|
|
|
|
|
|
|
icon.setVisibility(GONE);
|
|
|
|
title.setVisibility(GONE);
|
|
|
|
body.setVisibility(VISIBLE);
|
|
|
|
date.setVisibility(GONE);
|
|
|
|
}
|
2017-08-01 08:56:00 -07:00
|
|
|
|
2015-09-16 17:31:24 -07:00
|
|
|
@Override
|
|
|
|
public void onModified(Recipient recipient) {
|
2018-01-24 19:17:44 -08:00
|
|
|
Util.runOnMain(() -> bind(messageRecord, locale));
|
2015-09-16 17:31:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-29 17:49:49 -07:00
|
|
|
public void setOnClickListener(View.OnClickListener l) {
|
|
|
|
super.setOnClickListener(new InternalClickListener(l));
|
2015-09-16 17:31:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void unbind() {
|
|
|
|
if (sender != null) {
|
|
|
|
sender.removeListener(this);
|
|
|
|
}
|
|
|
|
}
|
2016-08-29 17:49:49 -07:00
|
|
|
|
|
|
|
private class InternalClickListener implements View.OnClickListener {
|
|
|
|
|
|
|
|
@Nullable private final View.OnClickListener parent;
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
InternalClickListener(@Nullable View.OnClickListener parent) {
|
2016-08-29 17:49:49 -07:00
|
|
|
this.parent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-06-06 18:03:09 -07:00
|
|
|
if ((!messageRecord.isIdentityUpdate() &&
|
|
|
|
!messageRecord.isIdentityDefault() &&
|
|
|
|
!messageRecord.isIdentityVerified()) ||
|
|
|
|
!batchSelected.isEmpty())
|
|
|
|
{
|
2016-08-29 17:49:49 -07:00
|
|
|
if (parent != null) parent.onClick(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Recipient sender = ConversationUpdateItem.this.sender;
|
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
IdentityUtil.getRemoteIdentityKey(getContext(), sender).addListener(new ListenableFuture.Listener<Optional<IdentityRecord>>() {
|
2016-08-29 17:49:49 -07:00
|
|
|
@Override
|
2017-06-06 18:03:09 -07:00
|
|
|
public void onSuccess(Optional<IdentityRecord> result) {
|
2016-08-29 17:49:49 -07:00
|
|
|
if (result.isPresent()) {
|
|
|
|
Intent intent = new Intent(getContext(), VerifyIdentityActivity.class);
|
2017-07-26 09:59:15 -07:00
|
|
|
intent.putExtra(VerifyIdentityActivity.ADDRESS_EXTRA, sender.getAddress());
|
2017-06-06 18:03:09 -07:00
|
|
|
intent.putExtra(VerifyIdentityActivity.IDENTITY_EXTRA, new IdentityKeyParcelable(result.get().getIdentityKey()));
|
|
|
|
intent.putExtra(VerifyIdentityActivity.VERIFIED_EXTRA, result.get().getVerifiedStatus() == IdentityDatabase.VerifiedStatus.VERIFIED);
|
2016-08-29 17:49:49 -07:00
|
|
|
|
|
|
|
getContext().startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 17:31:24 -07:00
|
|
|
}
|