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 MessageRecord messageRecord;
@ -80,6 +80,7 @@ public class ConversationItem extends LinearLayout {
private Locale locale;
private boolean groupThread;
private boolean pushDestination;
private Recipient recipient;
private View bodyBubble;
private TextView bodyText;
@ -172,15 +173,18 @@ public class ConversationItem extends LinearLayout {
this.selectionClickListener = selectionClickListener;
this.groupThread = groupThread;
this.pushDestination = pushDestination;
this.recipient = messageRecord.getIndividualRecipient();
this.recipient.addListener(this);
setSelectionBackgroundDrawables(messageRecord);
setBodyText(messageRecord);
if (hasConversationBubble(messageRecord)) {
setBubbleState(messageRecord);
setBubbleState(messageRecord, recipient);
setStatusIcons(messageRecord);
setContactPhoto(messageRecord);
setGroupMessageStatus(messageRecord);
setContactPhoto(recipient);
setGroupMessageStatus(messageRecord, recipient);
setEvents(messageRecord);
setMinimumWidth();
setMediaAttributes(messageRecord);
@ -200,6 +204,9 @@ public class ConversationItem extends LinearLayout {
}
public void unbind() {
if (recipient != null) {
recipient.removeListener(this);
}
}
public MessageRecord getMessageRecord() {
@ -208,13 +215,11 @@ public class ConversationItem extends LinearLayout {
/// MessageRecord Attribute Parsers
private void setBubbleState(MessageRecord messageRecord) {
private void setBubbleState(MessageRecord messageRecord, Recipient recipient) {
if (messageRecord.isOutgoing()) {
bodyBubble.getBackground().setColorFilter(defaultBubbleColor, PorterDuff.Mode.MULTIPLY);
} else {
bodyBubble.getBackground().setColorFilter(messageRecord.getIndividualRecipient()
.getColor()
.toConversationColor(context),
bodyBubble.getBackground().setColorFilter(recipient.getColor().toConversationColor(context),
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()) {
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()) {
this.groupStatusText.setText(messageRecord.getIndividualRecipient().toShortString());
this.groupStatusText.setText(recipient.toShortString());
this.groupStatusText.setVisibility(View.VISIBLE);
} else {
this.groupStatusText.setVisibility(View.GONE);
@ -394,6 +399,15 @@ public class ConversationItem extends LinearLayout {
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 void fireIntent(Slide slide) {
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.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
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());
context.startActivity(intent);