Utilize GeneratedContactPhoto for named folk.

This commit is contained in:
Alex Hart
2020-12-01 17:08:30 -04:00
committed by Greyson Parrelli
parent 283ff44da9
commit cea4ee4ea9
7 changed files with 43 additions and 16 deletions

View File

@@ -18,10 +18,10 @@ import java.util.Objects;
public final class FallbackPhoto80dp implements FallbackContactPhoto {
@DrawableRes private final int drawable80dp;
private final MaterialColor backgroundColor;
@DrawableRes private final int drawable80dp;
private final int backgroundColor;
public FallbackPhoto80dp(@DrawableRes int drawable80dp, @NonNull MaterialColor backgroundColor) {
public FallbackPhoto80dp(@DrawableRes int drawable80dp, int backgroundColor) {
this.drawable80dp = drawable80dp;
this.backgroundColor = backgroundColor;
}
@@ -53,7 +53,7 @@ public final class FallbackPhoto80dp implements FallbackContactPhoto {
LayerDrawable drawable = new LayerDrawable(new Drawable[]{background, foreground, gradient});
int foregroundInset = ViewUtil.dpToPx(24);
DrawableCompat.setTint(background, backgroundColor.toAvatarColor(context));
DrawableCompat.setTint(background, backgroundColor);
drawable.setLayerInset(1, foregroundInset, foregroundInset, foregroundInset, foregroundInset);

View File

@@ -27,10 +27,18 @@ public class GeneratedContactPhoto implements FallbackContactPhoto {
private final String name;
private final int fallbackResId;
private final int targetSize;
private final int fontSize;
public GeneratedContactPhoto(@NonNull String name, @DrawableRes int fallbackResId) {
this(name, fallbackResId, -1, ViewUtil.dpToPx(24));
}
public GeneratedContactPhoto(@NonNull String name, @DrawableRes int fallbackResId, int targetSize, int fontSize) {
this.name = name;
this.fallbackResId = fallbackResId;
this.targetSize = targetSize;
this.fontSize = fontSize;
}
@Override
@@ -40,7 +48,10 @@ public class GeneratedContactPhoto implements FallbackContactPhoto {
@Override
public Drawable asDrawable(Context context, int color, boolean inverted) {
int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
int targetSize = this.targetSize != -1
? this.targetSize
: context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
String character = getAbbreviation(name);
if (!TextUtils.isEmpty(character)) {
@@ -49,7 +60,7 @@ public class GeneratedContactPhoto implements FallbackContactPhoto {
.width(targetSize)
.height(targetSize)
.useFont(TYPEFACE)
.fontSize(ViewUtil.dpToPx(context, 24))
.fontSize(fontSize)
.textColor(inverted ? color : Color.WHITE)
.endConfig()
.buildRound(character, inverted ? Color.WHITE : color);