mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Fix for occasional generated avatar mis-sizing in conversation.
Drawables are (strangely) mutable objects. We reuse a single drawable for each recipient, but some avatar views (the conversation list -- 40dp) are larger than others (the conversation -- 30dp). This results in a situation where TextDrawable doesn't render itself appropriately, because the bounds are modified by a larger view. Giving the Drawable an intrinsic width and height resolves this conflict. // FREEBIE
This commit is contained in:
parent
338caf7da9
commit
68234959c4
@ -1,17 +1,8 @@
|
||||
package org.thoughtcrime.securesms.contacts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.net.Uri;
|
||||
@ -20,7 +11,6 @@ import android.os.Build.VERSION_CODES;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
@ -63,9 +53,13 @@ public class ContactPhotoFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public static Drawable getDefaultContactPhoto(@Nullable String name) {
|
||||
public static Drawable getDefaultContactPhoto(Context context, @Nullable String name) {
|
||||
if (name != null && !name.isEmpty()) {
|
||||
return TextDrawable.builder().buildRound(String.valueOf(name.charAt(0)),
|
||||
int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
|
||||
return TextDrawable.builder().beginConfig()
|
||||
.width(targetSize)
|
||||
.height(targetSize)
|
||||
.endConfig().buildRound(String.valueOf(name.charAt(0)),
|
||||
COLOR_GENERATOR.getColor(name));
|
||||
}
|
||||
|
||||
@ -118,7 +112,7 @@ public class ContactPhotoFactory {
|
||||
}
|
||||
}
|
||||
|
||||
return getDefaultContactPhoto(name);
|
||||
return getDefaultContactPhoto(context, name);
|
||||
}
|
||||
|
||||
public static Drawable getGroupContactPhoto(Context context, @Nullable byte[] avatar) {
|
||||
|
@ -147,7 +147,7 @@ public class Recipient {
|
||||
|
||||
public static Recipient getUnknownRecipient(Context context) {
|
||||
return new Recipient("Unknown", "Unknown", -1, null,
|
||||
ContactPhotoFactory.getDefaultContactPhoto(null));
|
||||
ContactPhotoFactory.getDefaultContactPhoto(context, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,7 +75,7 @@ public class RecipientProvider {
|
||||
} else {
|
||||
final Drawable defaultPhoto = isGroupRecipient
|
||||
? ContactPhotoFactory.getDefaultGroupPhoto(context)
|
||||
: ContactPhotoFactory.getDefaultContactPhoto(null);
|
||||
: ContactPhotoFactory.getDefaultContactPhoto(context, null);
|
||||
|
||||
recipient = new Recipient(null, number, recipientId, null, defaultPhoto);
|
||||
}
|
||||
@ -143,7 +143,7 @@ public class RecipientProvider {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null));
|
||||
return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(context, null));
|
||||
}
|
||||
|
||||
private RecipientDetails getGroupRecipientDetails(Context context, String groupId) {
|
||||
|
Loading…
Reference in New Issue
Block a user