use delta colors for the avatars in the notification area, remove dead code wrt colors

This commit is contained in:
B. Petersen
2018-12-13 13:27:53 +01:00
parent b9c43c7b6a
commit c09333d5d6
8 changed files with 3 additions and 159 deletions
@@ -1,14 +1,10 @@
package org.thoughtcrime.securesms.color;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import org.thoughtcrime.securesms.R;
import java.util.HashMap;
import java.util.Map;
import static org.thoughtcrime.securesms.util.ThemeUtil.isDarkTheme;
public enum MaterialColor {
@@ -23,29 +19,6 @@ public enum MaterialColor {
ORANGE (R.color.conversation_orange, R.color.conversation_orange_shade, "orange"),
GREY (R.color.conversation_grey, R.color.conversation_grey_shade, "grey");
private static final Map<String, MaterialColor> COLOR_MATCHES = new HashMap<String, MaterialColor>() {{
put("red", RED);
put("brown", RED);
put("pink", PINK);
put("purple", PURPLE);
put("deep_purple", PURPLE);
put("indigo", INDIGO);
put("blue", BLUE);
put("light_blue", BLUE);
put("cyan", CYAN);
put("blue_grey", CYAN);
put("teal", TEAL);
put("green", GREEN);
put("light_green", GREEN);
put("lime", GREEN);
put("orange", ORANGE);
put("amber", ORANGE);
put("deep_orange", ORANGE);
put("yellow", ORANGE);
put("grey", GREY);
put("group_color", BLUE);
}};
private final int conversationColorLight;
private final int actionBarColorLight;
private final int statusBarColorLight;
@@ -92,18 +65,4 @@ public enum MaterialColor {
return serialized;
}
public static MaterialColor fromSerialized(String serialized) throws UnknownColorException {
if (COLOR_MATCHES.containsKey(serialized)) {
return COLOR_MATCHES.get(serialized);
}
throw new UnknownColorException("Unknown color: " + serialized);
}
public static class UnknownColorException extends Exception {
public UnknownColorException(String message) {
super(message);
}
}
}
@@ -1,40 +0,0 @@
package org.thoughtcrime.securesms.color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MaterialColors {
public static final MaterialColorList CONVERSATION_PALETTE = new MaterialColorList(new ArrayList<>(Arrays.asList(
MaterialColor.ORANGE,
MaterialColor.RED,
MaterialColor.PINK,
MaterialColor.PURPLE,
MaterialColor.INDIGO,
MaterialColor.BLUE,
MaterialColor.GREEN,
MaterialColor.TEAL,
MaterialColor.CYAN
)));
public static class MaterialColorList {
private final List<MaterialColor> colors;
private MaterialColorList(List<MaterialColor> colors) {
this.colors = colors;
}
public MaterialColor get(int index) {
return colors.get(index);
}
public int size() {
return colors.size();
}
}
}
@@ -23,7 +23,6 @@ public class AvatarImageView extends AppCompatImageView {
private static final String TAG = AvatarImageView.class.getSimpleName();
private boolean inverted;
private OnClickListener listener = null;
public AvatarImageView(Context context) {
@@ -37,7 +36,6 @@ public class AvatarImageView extends AppCompatImageView {
if (attrs != null) {
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AvatarImageView, 0, 0);
//inverted = typedArray.getBoolean(0, false);
typedArray.recycle();
}
}
@@ -61,7 +59,7 @@ public class AvatarImageView extends AppCompatImageView {
setAvatarClickHandler(recipient, quickContactEnabled);
}
} else {
setImageDrawable(new GeneratedContactPhoto("+").asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted));
setImageDrawable(new GeneratedContactPhoto("+").asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), false));
super.setOnClickListener(listener);
}
}
@@ -1,39 +1,10 @@
package org.thoughtcrime.securesms.contacts.avatars;
import android.support.annotation.NonNull;
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.color.MaterialColors;
public class ContactColors {
public static final MaterialColor UNKNOWN_COLOR = MaterialColor.GREY;
private static final String[] LEGACY_PALETTE = new String[] {
"red",
"pink",
"purple",
"deep_purple",
"indigo",
"blue",
"light_blue",
"cyan",
"teal",
"green",
"light_green",
"orange",
"deep_orange",
"amber",
"blue_grey"
};
public static MaterialColor generateFor(@NonNull String name) {
String serialized = LEGACY_PALETTE[Math.abs(name.hashCode()) % LEGACY_PALETTE.length];
try {
return MaterialColor.fromSerialized(serialized);
} catch (MaterialColor.UnknownColorException e) {
return MaterialColors.CONVERSATION_PALETTE.get(Math.abs(name.hashCode()) % MaterialColors.CONVERSATION_PALETTE.size());
}
}
}
@@ -1,13 +1,10 @@
package org.thoughtcrime.securesms.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.guava.Optional;
import java.util.LinkedList;
@@ -17,8 +14,6 @@ public class RecipientDatabase extends Database {
private static final String TAG = RecipientDatabase.class.getSimpleName();
private static final String COLOR = "color";
public enum RegisteredState {
UNKNOWN(0), REGISTERED(1), NOT_REGISTERED(2);
@@ -41,24 +36,13 @@ public class RecipientDatabase extends Database {
return null;
}
public void setColor(@NonNull Recipient recipient, @NonNull MaterialColor color) {
ContentValues values = new ContentValues();
values.put(COLOR, color.serialize());
updateOrInsert(recipient.getAddress(), values);
recipient.resolve().setColor(color);
}
public List<Address> getRegistered() {
List<Address> results = new LinkedList<>();
return results;
}
private void updateOrInsert(Address address, ContentValues contentValues) {
}
public static class RecipientSettings {
private final boolean blocked;
private final MaterialColor color;
private final boolean seenInviteReminder;
private final int defaultSubscriptionId;
private final int expireMessages;
@@ -72,7 +56,6 @@ public class RecipientDatabase extends Database {
private final String signalProfileAvatar;
RecipientSettings(boolean blocked, long muteUntil,
@Nullable MaterialColor color,
boolean seenInviteReminder,
int defaultSubscriptionId,
int expireMessages,
@@ -86,7 +69,6 @@ public class RecipientDatabase extends Database {
@Nullable String signalProfileAvatar)
{
this.blocked = blocked;
this.color = color;
this.seenInviteReminder = seenInviteReminder;
this.defaultSubscriptionId = defaultSubscriptionId;
this.expireMessages = expireMessages;
@@ -100,10 +82,6 @@ public class RecipientDatabase extends Database {
this.signalProfileAvatar = signalProfileAvatar;
}
public @Nullable MaterialColor getColor() {
return color;
}
public boolean isBlocked() {
return blocked;
}
@@ -78,10 +78,10 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
.get());
} catch (InterruptedException | ExecutionException e) {
Log.w(TAG, e);
setLargeIcon(fallbackContactPhoto.asDrawable(context, recipient.getColor().toConversationColor(context)));
setLargeIcon(fallbackContactPhoto.asDrawable(context, recipient.getFallbackAvatarColor(context)));
}
} else {
setLargeIcon(fallbackContactPhoto.asDrawable(context, recipient.getColor().toConversationColor(context)));
setLargeIcon(fallbackContactPhoto.asDrawable(context, recipient.getFallbackAvatarColor(context)));
}
} else {
@@ -25,10 +25,8 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto;
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
@@ -72,7 +70,6 @@ public class Recipient implements RecipientModifiedListener {
private Optional<Integer> defaultSubscriptionId = Optional.absent();
private @NonNull RegisteredState registered = RegisteredState.UNKNOWN;
private @Nullable MaterialColor color;
private boolean seenInviteReminder;
private @Nullable byte[] profileKey;
private @Nullable String profileName;
@@ -114,7 +111,6 @@ public class Recipient implements RecipientModifiedListener {
this.contactUri = details.contactUri;
this.name = details.name;
this.systemContactPhoto = details.systemContactPhoto;
this.color = details.color;
this.customLabel = details.customLabel;
this.blocked = details.blocked;
this.expireMessages = details.expireMessages;
@@ -159,20 +155,6 @@ public class Recipient implements RecipientModifiedListener {
if (notify) notifyListeners();
}
public synchronized @NonNull MaterialColor getColor() {
if (color != null) return color;
else if (name != null) return ContactColors.generateFor(name);
else return ContactColors.UNKNOWN_COLOR;
}
public void setColor(@NonNull MaterialColor color) {
synchronized (this) {
this.color = color;
}
notifyListeners();
}
public @NonNull Address getAddress() {
return address;
}
@@ -369,7 +351,6 @@ public class Recipient implements RecipientModifiedListener {
", expireMessages=" + expireMessages +
", defaultSubscriptionId=" + defaultSubscriptionId +
", registered=" + registered +
", color=" + color +
", seenInviteReminder=" + seenInviteReminder +
", profileKey=" + Arrays.toString(profileKey) +
", profileName='" + profileName + '\'' +
@@ -20,7 +20,6 @@ import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
import org.thoughtcrime.securesms.util.Util;
@@ -40,7 +39,6 @@ public class RecipientProvider {
@Nullable final Uri systemContactPhoto;
@Nullable final Uri contactUri;
@Nullable final Long groupAvatarId;
@Nullable final MaterialColor color;
final boolean blocked;
final int expireMessages;
@NonNull final List<Recipient> participants;
@@ -60,7 +58,6 @@ public class RecipientProvider {
this.systemContactPhoto = settings != null ? Util.uri(settings.getSystemContactPhotoUri()) : null;
this.customLabel = settings != null ? settings.getSystemPhoneLabel() : null;
this.contactUri = settings != null ? Util.uri(settings.getSystemContactUri()) : null;
this.color = settings != null ? settings.getColor() : null;
this.blocked = settings != null && settings.isBlocked();
this.expireMessages = settings != null ? settings.getExpireMessages() : 0;
this.participants = participants == null ? new LinkedList<>() : participants;