2015-09-17 00:31:24 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2016-08-16 03:23:56 +00:00
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2015-09-15 22:28:27 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2016-08-30 00:49:49 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2015-09-17 00:31:24 +00:00
|
|
|
import android.util.AttributeSet;
|
2016-08-30 00:49:49 +00:00
|
|
|
import android.util.Log;
|
2015-09-17 00:31:24 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2016-08-30 00:49:49 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
2015-09-15 22:28:27 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2017-06-07 01:03:09 +00:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
2015-09-17 00:31:24 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2015-09-21 17:54:23 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DateUtils;
|
2015-09-17 00:31:24 +00:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2016-08-30 00:49:49 +00:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2015-09-17 00:31:24 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2016-08-30 00:49:49 +00:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2015-09-17 00:31:24 +00:00
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Set;
|
2016-08-30 00:49:49 +00:00
|
|
|
import java.util.concurrent.ExecutionException;
|
2015-09-15 22:28:27 +00:00
|
|
|
|
2015-09-17 00:31:24 +00:00
|
|
|
public class ConversationUpdateItem extends LinearLayout
|
2016-08-30 00:49:49 +00:00
|
|
|
implements Recipients.RecipientsModifiedListener, Recipient.RecipientModifiedListener, BindableConversationItem
|
2015-09-17 00:31:24 +00:00
|
|
|
{
|
|
|
|
private static final String TAG = ConversationUpdateItem.class.getSimpleName();
|
|
|
|
|
2016-08-30 00:49:49 +00:00
|
|
|
private MasterSecret masterSecret;
|
|
|
|
private Set<MessageRecord> batchSelected;
|
|
|
|
|
2015-09-17 00:31:24 +00:00
|
|
|
private ImageView icon;
|
|
|
|
private TextView body;
|
2015-09-21 17:54:23 +00:00
|
|
|
private TextView date;
|
2015-09-17 00:31:24 +00:00
|
|
|
private Recipient sender;
|
|
|
|
private MessageRecord messageRecord;
|
2015-09-21 17:54:23 +00:00
|
|
|
private Locale locale;
|
2015-09-17 00:31:24 +00:00
|
|
|
|
|
|
|
public ConversationUpdateItem(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConversationUpdateItem(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
|
|
|
this.icon = (ImageView)findViewById(R.id.conversation_update_icon);
|
|
|
|
this.body = (TextView)findViewById(R.id.conversation_update_body);
|
2015-09-21 17:54:23 +00:00
|
|
|
this.date = (TextView)findViewById(R.id.conversation_update_date);
|
2015-09-17 00:31:24 +00:00
|
|
|
|
2016-08-30 00:49:49 +00:00
|
|
|
this.setOnClickListener(new InternalClickListener(null));
|
2015-09-17 00:31:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
@Override
|
|
|
|
public void bind(@NonNull MasterSecret masterSecret,
|
|
|
|
@NonNull MessageRecord messageRecord,
|
|
|
|
@NonNull Locale locale,
|
|
|
|
@NonNull Set<MessageRecord> batchSelected,
|
2015-10-21 22:32:29 +00:00
|
|
|
@NonNull Recipients conversationRecipients)
|
2015-09-15 22:28:27 +00:00
|
|
|
{
|
2016-08-30 00:49:49 +00:00
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.batchSelected = batchSelected;
|
2016-08-16 03:23:56 +00:00
|
|
|
|
2016-08-30 00:49:49 +00:00
|
|
|
bind(messageRecord, locale);
|
2016-08-16 03:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public MessageRecord getMessageRecord() {
|
|
|
|
return messageRecord;
|
2015-09-15 22:28:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 17:54:23 +00:00
|
|
|
private void bind(@NonNull MessageRecord messageRecord, @NonNull Locale locale) {
|
2015-09-17 00:31:24 +00:00
|
|
|
this.messageRecord = messageRecord;
|
|
|
|
this.sender = messageRecord.getIndividualRecipient();
|
2015-09-21 17:54:23 +00:00
|
|
|
this.locale = locale;
|
2015-09-17 00:31:24 +00:00
|
|
|
|
|
|
|
this.sender.addListener(this);
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
if (messageRecord.isGroupAction()) setGroupRecord(messageRecord);
|
|
|
|
else if (messageRecord.isCallLog()) setCallRecord(messageRecord);
|
|
|
|
else if (messageRecord.isJoined()) setJoinedRecord(messageRecord);
|
|
|
|
else if (messageRecord.isExpirationTimerUpdate()) setTimerRecord(messageRecord);
|
2016-09-12 15:26:46 +00:00
|
|
|
else if (messageRecord.isEndSession()) setEndSessionRecord(messageRecord);
|
2016-08-30 00:49:49 +00:00
|
|
|
else if (messageRecord.isIdentityUpdate()) setIdentityRecord(messageRecord);
|
2017-06-07 01:03:09 +00:00
|
|
|
else if (messageRecord.isIdentityVerified() ||
|
|
|
|
messageRecord.isIdentityDefault()) setIdentityVerifyUpdate(messageRecord);
|
2016-08-16 03:23:56 +00:00
|
|
|
else throw new AssertionError("Neither group nor log nor joined.");
|
2016-08-30 00:49:49 +00:00
|
|
|
|
|
|
|
if (batchSelected.contains(messageRecord)) setSelected(true);
|
|
|
|
else setSelected(false);
|
2015-09-21 17:54:23 +00: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);
|
|
|
|
|
|
|
|
body.setText(messageRecord.getDisplayBody());
|
|
|
|
date.setText(DateUtils.getExtendedRelativeTimeSpanString(getContext(), locale, messageRecord.getDateReceived()));
|
|
|
|
date.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
private void setTimerRecord(final MessageRecord messageRecord) {
|
|
|
|
if (messageRecord.getExpiresIn() > 0) {
|
|
|
|
icon.setImageResource(R.drawable.ic_timer_white_24dp);
|
|
|
|
icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
|
|
|
|
} else {
|
|
|
|
icon.setImageResource(R.drawable.ic_timer_off_white_24dp);
|
|
|
|
icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
body.setText(messageRecord.getDisplayBody());
|
|
|
|
date.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2016-08-30 00:49:49 +00: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));
|
|
|
|
body.setText(messageRecord.getDisplayBody());
|
|
|
|
date.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2017-06-07 01:03:09 +00: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));
|
|
|
|
body.setText(messageRecord.getDisplayBody());
|
|
|
|
date.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2015-09-21 17:54:23 +00:00
|
|
|
private void setGroupRecord(MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_group_grey600_24dp);
|
2016-08-16 03:23:56 +00:00
|
|
|
icon.clearColorFilter();
|
2015-09-21 17:54:23 +00:00
|
|
|
|
2015-11-19 00:20:01 +00:00
|
|
|
GroupUtil.getDescription(getContext(), messageRecord.getBody().getBody()).addListener(this);
|
|
|
|
body.setText(messageRecord.getDisplayBody());
|
2015-09-21 17:54:23 +00:00
|
|
|
|
|
|
|
date.setVisibility(View.GONE);
|
2015-09-17 00:31:24 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 19:18:02 +00:00
|
|
|
private void setJoinedRecord(MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_favorite_grey600_24dp);
|
2016-08-16 03:23:56 +00:00
|
|
|
icon.clearColorFilter();
|
2015-10-27 19:18:02 +00:00
|
|
|
body.setText(messageRecord.getDisplayBody());
|
|
|
|
date.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2016-09-12 15:26:46 +00:00
|
|
|
private void setEndSessionRecord(MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_refresh_white_24dp);
|
|
|
|
icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
|
|
|
|
body.setText(messageRecord.getDisplayBody());
|
|
|
|
date.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:31:24 +00:00
|
|
|
@Override
|
|
|
|
public void onModified(Recipients recipients) {
|
|
|
|
onModified(recipients.getPrimaryRecipient());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onModified(Recipient recipient) {
|
|
|
|
Util.runOnMain(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-09-21 17:54:23 +00:00
|
|
|
bind(messageRecord, locale);
|
2015-09-17 00:31:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-30 00:49:49 +00:00
|
|
|
public void setOnClickListener(View.OnClickListener l) {
|
|
|
|
super.setOnClickListener(new InternalClickListener(l));
|
2015-09-17 00:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void unbind() {
|
|
|
|
if (sender != null) {
|
|
|
|
sender.removeListener(this);
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 00:49:49 +00:00
|
|
|
|
|
|
|
private class InternalClickListener implements View.OnClickListener {
|
|
|
|
|
|
|
|
@Nullable private final View.OnClickListener parent;
|
|
|
|
|
|
|
|
public InternalClickListener(@Nullable View.OnClickListener parent) {
|
|
|
|
this.parent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-06-07 01:03:09 +00:00
|
|
|
if ((!messageRecord.isIdentityUpdate() &&
|
|
|
|
!messageRecord.isIdentityDefault() &&
|
|
|
|
!messageRecord.isIdentityVerified()) ||
|
|
|
|
!batchSelected.isEmpty())
|
|
|
|
{
|
2016-08-30 00:49:49 +00:00
|
|
|
if (parent != null) parent.onClick(v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Recipient sender = ConversationUpdateItem.this.sender;
|
|
|
|
|
2017-06-07 01:03:09 +00:00
|
|
|
IdentityUtil.getRemoteIdentityKey(getContext(), sender).addListener(new ListenableFuture.Listener<Optional<IdentityRecord>>() {
|
2016-08-30 00:49:49 +00:00
|
|
|
@Override
|
2017-06-07 01:03:09 +00:00
|
|
|
public void onSuccess(Optional<IdentityRecord> result) {
|
2016-08-30 00:49:49 +00:00
|
|
|
if (result.isPresent()) {
|
|
|
|
Intent intent = new Intent(getContext(), VerifyIdentityActivity.class);
|
2017-07-26 16:59:15 +00:00
|
|
|
intent.putExtra(VerifyIdentityActivity.ADDRESS_EXTRA, sender.getAddress());
|
2017-06-07 01:03:09 +00:00
|
|
|
intent.putExtra(VerifyIdentityActivity.IDENTITY_EXTRA, new IdentityKeyParcelable(result.get().getIdentityKey()));
|
|
|
|
intent.putExtra(VerifyIdentityActivity.VERIFIED_EXTRA, result.get().getVerifiedStatus() == IdentityDatabase.VerifiedStatus.VERIFIED);
|
2016-08-30 00:49:49 +00:00
|
|
|
|
|
|
|
getContext().startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:31:24 +00:00
|
|
|
}
|