mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-27 01:17:00 +00:00
Display a generated avatar icon rather than a single default.
If the contact doesn't have an image, render a color-coded background and the first letter of the contact's name. 1) Don't display anything during recipient resolution. 2) Display a # icon in material gray for recipients with no name. 3) Display a material group icon in material gray for groups with no avatar icon set. Closes #3104 // FREEBIE
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.ContactsContract;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
||||
public class AvatarImageView extends ImageView {
|
||||
|
||||
public AvatarImageView(Context context) {
|
||||
super(context);
|
||||
setScaleType(ScaleType.CENTER_INSIDE);
|
||||
}
|
||||
|
||||
public AvatarImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setScaleType(ScaleType.CENTER_INSIDE);
|
||||
}
|
||||
|
||||
public void setAvatar(Recipient recipient, boolean quickContactEnabled) {
|
||||
setImageDrawable(recipient.getContactPhoto());
|
||||
setAvatarClickHandler(recipient, quickContactEnabled);
|
||||
}
|
||||
|
||||
private void setAvatarClickHandler(final Recipient recipient, boolean quickContactEnabled) {
|
||||
if (!recipient.isGroupRecipient() && quickContactEnabled) {
|
||||
setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (recipient.getContactUri() != null) {
|
||||
ContactsContract.QuickContact.showQuickContact(getContext(), AvatarImageView.this, recipient.getContactUri(), ContactsContract.QuickContact.MODE_LARGE, null);
|
||||
} else {
|
||||
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);
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user