diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index 88e41f8568..e9eb7e1b0b 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -102,7 +102,7 @@ public class ConversationListItem extends RelativeLayout } setBatchState(batchMode); - this.contactPhotoImage.setAvatar(recipients.getPrimaryRecipient(), true); + this.contactPhotoImage.setAvatar(recipients, true); } public void unbind() { @@ -132,7 +132,7 @@ public class ConversationListItem extends RelativeLayout @Override public void run() { fromView.setText(recipients, read); - contactPhotoImage.setAvatar(recipients.getPrimaryRecipient(), true); + contactPhotoImage.setAvatar(recipients, true); } }); } diff --git a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java index 5d658b3ae7..843d213759 100644 --- a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java +++ b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java @@ -111,7 +111,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi } private void setHeader(Recipients recipients) { - this.avatar.setAvatar(recipients.getPrimaryRecipient(), true); + this.avatar.setAvatar(recipients, true); this.title.setText(recipients.toShortString()); if (recipients.isBlocked()) this.blockedIndicator.setVisibility(View.VISIBLE); diff --git a/src/org/thoughtcrime/securesms/ShareListItem.java b/src/org/thoughtcrime/securesms/ShareListItem.java index a1872f6fc8..716aa1ff40 100644 --- a/src/org/thoughtcrime/securesms/ShareListItem.java +++ b/src/org/thoughtcrime/securesms/ShareListItem.java @@ -72,7 +72,7 @@ public class ShareListItem extends RelativeLayout this.fromView.setText(recipients); setBackground(); - this.contactPhotoImage.setAvatar(this.recipients.getPrimaryRecipient(), false); + this.contactPhotoImage.setAvatar(this.recipients, false); } public void unbind() { @@ -106,7 +106,7 @@ public class ShareListItem extends RelativeLayout @Override public void run() { fromView.setText(recipients); - contactPhotoImage.setAvatar(recipients.getPrimaryRecipient(), false); + contactPhotoImage.setAvatar(recipients, false); } }); } diff --git a/src/org/thoughtcrime/securesms/components/AvatarImageView.java b/src/org/thoughtcrime/securesms/components/AvatarImageView.java index dd110396e4..af2ab0fd1f 100644 --- a/src/org/thoughtcrime/securesms/components/AvatarImageView.java +++ b/src/org/thoughtcrime/securesms/components/AvatarImageView.java @@ -10,6 +10,8 @@ import android.widget.ImageView; import org.thoughtcrime.securesms.contacts.ContactPhotoFactory; import org.thoughtcrime.securesms.recipients.Recipient; +import org.thoughtcrime.securesms.recipients.RecipientFactory; +import org.thoughtcrime.securesms.recipients.Recipients; public class AvatarImageView extends ImageView { @@ -23,24 +25,30 @@ public class AvatarImageView extends ImageView { setScaleType(ScaleType.CENTER_CROP); } - public void setAvatar(@Nullable Recipient recipient, boolean quickContactEnabled) { - if (recipient != null) { - setImageDrawable(recipient.getContactPhoto()); - setAvatarClickHandler(recipient, quickContactEnabled); + public void setAvatar(@Nullable Recipients recipients, boolean quickContactEnabled) { + if (recipients != null) { + setImageDrawable(recipients.getContactPhoto(getContext())); + setAvatarClickHandler(recipients, quickContactEnabled); } else { setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(getContext(), null)); setOnClickListener(null); } } - private void setAvatarClickHandler(final Recipient recipient, boolean quickContactEnabled) { - if (!recipient.isGroupRecipient() && quickContactEnabled) { + public void setAvatar(@Nullable Recipient recipient, boolean quickContactEnabled) { + setAvatar(RecipientFactory.getRecipientsFor(getContext(), recipient, true), quickContactEnabled); + } + + private void setAvatarClickHandler(final Recipients recipients, boolean quickContactEnabled) { + if (!recipients.isGroupRecipient() && quickContactEnabled) { setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (recipient.getContactUri() != null) { + Recipient recipient = recipients.getPrimaryRecipient(); + + if (recipient != null && recipient.getContactUri() != null) { ContactsContract.QuickContact.showQuickContact(getContext(), AvatarImageView.this, recipient.getContactUri(), ContactsContract.QuickContact.MODE_LARGE, null); - } else { + } else if (recipient != null) { final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getNumber()); intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); diff --git a/src/org/thoughtcrime/securesms/preferences/BlockedContactListItem.java b/src/org/thoughtcrime/securesms/preferences/BlockedContactListItem.java index fc0811477b..38b78f1ddc 100644 --- a/src/org/thoughtcrime/securesms/preferences/BlockedContactListItem.java +++ b/src/org/thoughtcrime/securesms/preferences/BlockedContactListItem.java @@ -43,7 +43,7 @@ public class BlockedContactListItem extends RelativeLayout implements Recipients @Override public void onModified(Recipients recipients) { - this.contactPhotoImage.setAvatar(recipients.getPrimaryRecipient(), false); + this.contactPhotoImage.setAvatar(recipients, false); this.nameView.setText(recipients.toShortString()); } diff --git a/src/org/thoughtcrime/securesms/recipients/Recipients.java b/src/org/thoughtcrime/securesms/recipients/Recipients.java index eb5e0844b2..b251b33286 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipients.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipients.java @@ -16,11 +16,14 @@ */ package org.thoughtcrime.securesms.recipients; +import android.content.Context; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.support.annotation.Nullable; import android.util.Log; import android.util.Patterns; +import org.thoughtcrime.securesms.contacts.ContactPhotoFactory; import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences; import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.VibrateState; import org.thoughtcrime.securesms.recipients.Recipient.RecipientModifiedListener; @@ -146,6 +149,11 @@ public class Recipients implements Iterable, RecipientModifiedListene notifyListeners(); } + public Drawable getContactPhoto(Context context) { + if (recipients.size() == 1) return recipients.get(0).getContactPhoto(); + else return ContactPhotoFactory.getDefaultGroupPhoto(context); + } + public synchronized void addListener(RecipientsModifiedListener listener) { if (listeners.isEmpty()) { for (Recipient recipient : recipients) {