Utilize themed colors in fallback resource photos.

This commit is contained in:
Alex Hart
2022-08-26 13:40:12 -03:00
parent e7dbc874bb
commit 0b0c4eb8c0
4 changed files with 29 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.contacts.avatars;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
@@ -63,14 +64,26 @@ public class ResourceContactPhoto implements FallbackContactPhoto {
}
private @NonNull Drawable buildDrawable(@NonNull Context context, int resourceId, @NonNull AvatarColor color, boolean inverted) {
Avatars.ForegroundColor foregroundColor = Avatars.getForegroundColor(color);
Drawable background = Objects.requireNonNull(ContextCompat.getDrawable(context, R.drawable.circle_tintable));
RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(AppCompatResources.getDrawable(context, resourceId));
final int backgroundColor;
final int foregroundColor;
if (color == AvatarColor.UNKNOWN) {
backgroundColor = ContextCompat.getColor(context, R.color.signal_colorSurfaceVariant);
foregroundColor = ContextCompat.getColor(context, R.color.signal_colorOnSurface);
} else {
Avatars.ForegroundColor foregroundAvatarColor = Avatars.getForegroundColor(color);
backgroundColor = color.colorInt();
foregroundColor = foregroundAvatarColor.getColorInt();
}
Drawable background = Objects.requireNonNull(ContextCompat.getDrawable(context, R.drawable.circle_tintable));
RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(AppCompatResources.getDrawable(context, resourceId));
//noinspection ConstantConditions
foreground.setScaleType(scaleType);
background.setColorFilter(inverted ? foregroundColor.getColorInt() : color.colorInt(), PorterDuff.Mode.SRC_IN);
foreground.setColorFilter(inverted ? color.colorInt() : foregroundColor.getColorInt(), PorterDuff.Mode.SRC_ATOP);
background.setColorFilter(inverted ? foregroundColor : backgroundColor, PorterDuff.Mode.SRC_IN);
foreground.setColorFilter(inverted ? backgroundColor : foregroundColor, PorterDuff.Mode.SRC_ATOP);
return new ExpandingLayerDrawable(new Drawable[] {background, foreground});
}

View File

@@ -23,9 +23,8 @@ public enum AvatarColor {
A180("A180", 0xFFFEF5D0),
A190("A190", 0xFFEAE6D5),
A200("A200", 0xFFD2D2DC),
A210("A210", 0xFFD7D7D9);
public static final AvatarColor UNKNOWN = A210;
A210("A210", 0xFFD7D7D9),
UNKNOWN("UNKNOWN", 0x00000000);
/** Fast map of name to enum, while also giving us a location to map old colors to new ones. */
private static final Map<String, AvatarColor> NAME_MAP = new HashMap<>();

View File

@@ -3785,6 +3785,8 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
val recipientId = RecipientId.from(cursor.requireLong(idColumnName))
val capabilities = cursor.requireLong(CAPABILITIES)
val distributionListId: DistributionListId? = DistributionListId.fromNullable(cursor.requireLong(DISTRIBUTION_LIST_ID))
val avatarColor: AvatarColor = if (distributionListId != null) AvatarColor.UNKNOWN else AvatarColor.deserialize(cursor.requireString(AVATAR_COLOR))
return RecipientRecord(
id = recipientId,
@@ -3794,7 +3796,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
e164 = cursor.requireString(PHONE),
email = cursor.requireString(EMAIL),
groupId = GroupId.parseNullableOrThrow(cursor.requireString(GROUP_ID)),
distributionListId = DistributionListId.fromNullable(cursor.requireLong(DISTRIBUTION_LIST_ID)),
distributionListId = distributionListId,
groupType = GroupType.fromId(cursor.requireInt(GROUP_TYPE)),
isBlocked = cursor.requireBoolean(BLOCKED),
muteUntil = cursor.requireLong(MUTE_UNTIL),
@@ -3832,7 +3834,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
mentionSetting = MentionSetting.fromId(cursor.requireInt(MENTION_SETTING)),
wallpaper = chatWallpaper,
chatColors = chatColors,
avatarColor = AvatarColor.deserialize(cursor.requireString(AVATAR_COLOR)),
avatarColor = avatarColor,
about = cursor.requireString(ABOUT),
aboutEmoji = cursor.requireString(ABOUT_EMOJI),
syncExtras = getSyncExtras(cursor),