Add recipient listener to ConversationItem

Fixes #3626
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-07-22 17:47:38 -07:00
parent b1f336c874
commit 7de1683195

View File

@ -72,7 +72,7 @@ import java.util.Set;
* *
*/ */
public class ConversationItem extends LinearLayout { public class ConversationItem extends LinearLayout implements Recipient.RecipientModifiedListener {
private final static String TAG = ConversationItem.class.getSimpleName(); private final static String TAG = ConversationItem.class.getSimpleName();
private MessageRecord messageRecord; private MessageRecord messageRecord;
@ -80,6 +80,7 @@ public class ConversationItem extends LinearLayout {
private Locale locale; private Locale locale;
private boolean groupThread; private boolean groupThread;
private boolean pushDestination; private boolean pushDestination;
private Recipient recipient;
private View bodyBubble; private View bodyBubble;
private TextView bodyText; private TextView bodyText;
@ -172,15 +173,18 @@ public class ConversationItem extends LinearLayout {
this.selectionClickListener = selectionClickListener; this.selectionClickListener = selectionClickListener;
this.groupThread = groupThread; this.groupThread = groupThread;
this.pushDestination = pushDestination; this.pushDestination = pushDestination;
this.recipient = messageRecord.getIndividualRecipient();
this.recipient.addListener(this);
setSelectionBackgroundDrawables(messageRecord); setSelectionBackgroundDrawables(messageRecord);
setBodyText(messageRecord); setBodyText(messageRecord);
if (hasConversationBubble(messageRecord)) { if (hasConversationBubble(messageRecord)) {
setBubbleState(messageRecord); setBubbleState(messageRecord, recipient);
setStatusIcons(messageRecord); setStatusIcons(messageRecord);
setContactPhoto(messageRecord); setContactPhoto(recipient);
setGroupMessageStatus(messageRecord); setGroupMessageStatus(messageRecord, recipient);
setEvents(messageRecord); setEvents(messageRecord);
setMinimumWidth(); setMinimumWidth();
setMediaAttributes(messageRecord); setMediaAttributes(messageRecord);
@ -200,6 +204,9 @@ public class ConversationItem extends LinearLayout {
} }
public void unbind() { public void unbind() {
if (recipient != null) {
recipient.removeListener(this);
}
} }
public MessageRecord getMessageRecord() { public MessageRecord getMessageRecord() {
@ -208,13 +215,11 @@ public class ConversationItem extends LinearLayout {
/// MessageRecord Attribute Parsers /// MessageRecord Attribute Parsers
private void setBubbleState(MessageRecord messageRecord) { private void setBubbleState(MessageRecord messageRecord, Recipient recipient) {
if (messageRecord.isOutgoing()) { if (messageRecord.isOutgoing()) {
bodyBubble.getBackground().setColorFilter(defaultBubbleColor, PorterDuff.Mode.MULTIPLY); bodyBubble.getBackground().setColorFilter(defaultBubbleColor, PorterDuff.Mode.MULTIPLY);
} else { } else {
bodyBubble.getBackground().setColorFilter(messageRecord.getIndividualRecipient() bodyBubble.getBackground().setColorFilter(recipient.getColor().toConversationColor(context),
.getColor()
.toConversationColor(context),
PorterDuff.Mode.MULTIPLY); PorterDuff.Mode.MULTIPLY);
} }
@ -277,9 +282,9 @@ public class ConversationItem extends LinearLayout {
} }
} }
private void setContactPhoto(MessageRecord messageRecord) { private void setContactPhoto(Recipient recipient) {
if (! messageRecord.isOutgoing()) { if (! messageRecord.isOutgoing()) {
setContactPhotoForRecipient(messageRecord.getIndividualRecipient()); setContactPhotoForRecipient(recipient);
} }
} }
@ -339,9 +344,9 @@ public class ConversationItem extends LinearLayout {
} }
} }
private void setGroupMessageStatus(MessageRecord messageRecord) { private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) {
if (groupThread && !messageRecord.isOutgoing()) { if (groupThread && !messageRecord.isOutgoing()) {
this.groupStatusText.setText(messageRecord.getIndividualRecipient().toShortString()); this.groupStatusText.setText(recipient.toShortString());
this.groupStatusText.setVisibility(View.VISIBLE); this.groupStatusText.setVisibility(View.VISIBLE);
} else { } else {
this.groupStatusText.setVisibility(View.GONE); this.groupStatusText.setVisibility(View.GONE);
@ -394,6 +399,15 @@ public class ConversationItem extends LinearLayout {
new ConfirmIdentityDialog(context, masterSecret, messageRecord, mismatches.get(0)).show(); new ConfirmIdentityDialog(context, masterSecret, messageRecord, mismatches.get(0)).show();
} }
@Override
public void onModified(Recipient recipient) {
if (hasConversationBubble(messageRecord)) {
setBubbleState(messageRecord, recipient);
setContactPhoto(recipient);
setGroupMessageStatus(messageRecord, recipient);
}
}
private class ThumbnailClickListener implements ThumbnailView.ThumbnailClickListener { private class ThumbnailClickListener implements ThumbnailView.ThumbnailClickListener {
private void fireIntent(Slide slide) { private void fireIntent(Slide slide) {
Log.w(TAG, "Clicked: " + slide.getUri() + " , " + slide.getContentType()); Log.w(TAG, "Clicked: " + slide.getUri() + " , " + slide.getContentType());
@ -417,7 +431,7 @@ public class ConversationItem extends LinearLayout {
Intent intent = new Intent(context, MediaPreviewActivity.class); Intent intent = new Intent(context, MediaPreviewActivity.class);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(slide.getUri(), slide.getContentType()); intent.setDataAndType(slide.getUri(), slide.getContentType());
if (!messageRecord.isOutgoing()) intent.putExtra(MediaPreviewActivity.RECIPIENT_EXTRA, messageRecord.getIndividualRecipient().getRecipientId()); if (!messageRecord.isOutgoing()) intent.putExtra(MediaPreviewActivity.RECIPIENT_EXTRA, recipient.getRecipientId());
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getDateReceived()); intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getDateReceived());
context.startActivity(intent); context.startActivity(intent);