2015-05-04 11:36:18 -07:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.provider.ContactsContract;
|
2015-05-14 08:53:35 -07:00
|
|
|
import android.support.annotation.Nullable;
|
2015-05-04 11:36:18 -07:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
2015-05-14 08:53:35 -07:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
|
2015-05-04 11:36:18 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-05-14 08:53:35 -07:00
|
|
|
public void setAvatar(@Nullable Recipient recipient, boolean quickContactEnabled) {
|
|
|
|
if (recipient != null) {
|
|
|
|
setImageDrawable(recipient.getContactPhoto());
|
|
|
|
setAvatarClickHandler(recipient, quickContactEnabled);
|
|
|
|
} else {
|
|
|
|
setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(getContext(), null));
|
|
|
|
setOnClickListener(null);
|
|
|
|
}
|
2015-05-04 11:36:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|