mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-06-01 13:03:09 +01:00
committed by
Moxie Marlinspike
parent
4314a4b42b
commit
61386e9ca9
@@ -3,13 +3,8 @@ package org.thoughtcrime.securesms.components;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -21,13 +16,10 @@ import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
|
||||
|
||||
public class AvatarImageView extends ImageView {
|
||||
|
||||
private boolean inverted;
|
||||
private boolean showBadge;
|
||||
|
||||
public AvatarImageView(Context context) {
|
||||
super(context);
|
||||
@@ -41,7 +33,6 @@ public class AvatarImageView extends ImageView {
|
||||
if (attrs != null) {
|
||||
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AvatarImageView, 0, 0);
|
||||
inverted = typedArray.getBoolean(0, false);
|
||||
showBadge = typedArray.getBoolean(1, false);
|
||||
typedArray.recycle();
|
||||
}
|
||||
}
|
||||
@@ -51,12 +42,9 @@ public class AvatarImageView extends ImageView {
|
||||
MaterialColor backgroundColor = recipients.getColor();
|
||||
setImageDrawable(recipients.getContactPhoto().asDrawable(getContext(), backgroundColor.toConversationColor(getContext()), inverted));
|
||||
setAvatarClickHandler(recipients, quickContactEnabled);
|
||||
setTag(recipients);
|
||||
if (showBadge) new BadgeResolutionTask(getContext()).execute(recipients);
|
||||
} else {
|
||||
setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(null).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted));
|
||||
setOnClickListener(null);
|
||||
setTag(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,30 +73,4 @@ public class AvatarImageView extends ImageView {
|
||||
setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
private class BadgeResolutionTask extends AsyncTask<Recipients,Void,Pair<Recipients, Boolean>> {
|
||||
private final Context context;
|
||||
|
||||
public BadgeResolutionTask(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<Recipients, Boolean> doInBackground(Recipients... recipients) {
|
||||
Capability textCapability = DirectoryHelper.getUserCapabilities(context, recipients[0]).getTextCapability();
|
||||
return new Pair<>(recipients[0], textCapability == Capability.SUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Pair<Recipients, Boolean> result) {
|
||||
if (getTag() == result.first && result.second) {
|
||||
final Drawable badged = new LayerDrawable(new Drawable[] {
|
||||
getDrawable(),
|
||||
ContextCompat.getDrawable(context, R.drawable.badge_drawable)
|
||||
});
|
||||
|
||||
setImageDrawable(badged);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user