Display generic 'group' avatar for MMS groups.

Fixes #3386
// FREEBIE
This commit is contained in:
Moxie Marlinspike
2015-06-14 11:20:19 -07:00
parent ed0e1c07b9
commit 4feedab02c
6 changed files with 30 additions and 14 deletions

View File

@@ -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);