Hide avatar when not enabled

pull/147/head
M66B 6 years ago
parent 0a7ac9f9c4
commit 2fff4ba163

@ -349,56 +349,59 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvError.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f); tvError.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f);
} }
ivAvatar.setVisibility(compact ? View.GONE : View.INVISIBLE); if (avatars || identicons) {
ivAvatar.setVisibility(compact ? View.GONE : View.INVISIBLE);
Bundle aargs = new Bundle(); Bundle aargs = new Bundle();
aargs.putLong("id", message.id); aargs.putLong("id", message.id);
aargs.putString("uri", message.avatar); aargs.putString("uri", message.avatar);
if (message.from != null && message.from.length > 0) if (message.from != null && message.from.length > 0)
aargs.putString("from", message.from[0].toString()); aargs.putString("from", message.from[0].toString());
ivAvatar.setTag(message.id); ivAvatar.setTag(message.id);
new SimpleTask<Drawable>() { new SimpleTask<Drawable>() {
@Override @Override
protected Drawable onLoad(Context context, Bundle args) { protected Drawable onLoad(Context context, Bundle args) {
String uri = args.getString("uri"); String uri = args.getString("uri");
if (avatars && !outgoing && uri != null) if (avatars && !outgoing && uri != null)
try { try {
ContentResolver resolver = context.getContentResolver(); ContentResolver resolver = context.getContentResolver();
InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(resolver, Uri.parse(uri)); InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(resolver, Uri.parse(uri));
if (is != null) if (is != null)
return Drawable.createFromStream(is, "avatar"); return Drawable.createFromStream(is, "avatar");
} catch (SecurityException ex) { } catch (SecurityException ex) {
Log.e(ex); Log.e(ex);
}
String from = args.getString("from");
if (identicons && !outgoing && from != null) {
return new BitmapDrawable(
context.getResources(),
Identicon.generate(from, dp24, 5, "light".equals(theme)));
} }
String from = args.getString("from"); return null;
if (identicons && !outgoing && from != null) {
return new BitmapDrawable(
context.getResources(),
Identicon.generate(from, dp24, 5, "light".equals(theme)));
} }
return null; @Override
} protected void onLoaded(Bundle args, Drawable avatar) {
if (avatar != null) {
@Override if ((long) ivAvatar.getTag() == args.getLong("id")) {
protected void onLoaded(Bundle args, Drawable avatar) { ivAvatar.setImageDrawable(avatar);
if (avatar != null) { ivAvatar.setVisibility(View.VISIBLE);
if ((long) ivAvatar.getTag() == args.getLong("id")) { } else
ivAvatar.setImageDrawable(avatar); Log.i("Skipping avatar");
ivAvatar.setVisibility(View.VISIBLE); }
} else
Log.i("Skipping avatar");
} }
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex); Helper.unexpectedError(context, owner, ex);
} }
}.load(context, owner, aargs); }.load(context, owner, aargs);
} else
ivAvatar.setVisibility(View.GONE);
vwColor.setBackgroundColor(message.accountColor == null ? Color.TRANSPARENT : message.accountColor); vwColor.setBackgroundColor(message.accountColor == null ? Color.TRANSPARENT : message.accountColor);
vwColor.setVisibility(View.VISIBLE); vwColor.setVisibility(View.VISIBLE);

Loading…
Cancel
Save