Skip to content

Commit

Permalink
Add ultramarine as a conversation color option.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Apr 21, 2020
1 parent 6ecd3b5 commit fc6b5c1
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum MaterialColor {
PLUM (R.color.conversation_plumb, R.color.conversation_plumb_tint, R.color.conversation_plumb_shade, "pink"),
TAUPE (R.color.conversation_taupe, R.color.conversation_taupe_tint, R.color.conversation_taupe_shade, "blue_grey"),
STEEL (R.color.conversation_steel, R.color.conversation_steel_tint, R.color.conversation_steel_shade, "grey"),
ULTRAMARINE(R.color.conversation_ultramarine, R.color.conversation_ultramarine_tint, R.color.conversation_ultramarine_shade, "ultramarine"),
GROUP (R.color.conversation_group, R.color.conversation_group_tint, R.color.conversation_group_shade, "blue");

private static final Map<String, MaterialColor> COLOR_MATCHES = new HashMap<String, MaterialColor>() {{
Expand All @@ -48,6 +49,7 @@ public enum MaterialColor {
put("lime", WINTERGREEN);
put("blue_grey", TAUPE);
put("grey", STEEL);
put("ultramarine", ULTRAMARINE);
put("group_color", GROUP);
}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
public class MaterialColors {

public static final MaterialColorList CONVERSATION_PALETTE = new MaterialColorList(new ArrayList<>(Arrays.asList(
MaterialColor.PLUM,
MaterialColor.CRIMSON,
MaterialColor.VERMILLION,
MaterialColor.VIOLET,
MaterialColor.BLUE,
MaterialColor.INDIGO,
MaterialColor.FOREST,
MaterialColor.WINTERGREEN,
MaterialColor.TEAL,
MaterialColor.BURLAP,
MaterialColor.TAUPE,
MaterialColor.STEEL
MaterialColor.PLUM,
MaterialColor.CRIMSON,
MaterialColor.VERMILLION,
MaterialColor.VIOLET,
MaterialColor.INDIGO,
MaterialColor.TAUPE,
MaterialColor.ULTRAMARINE,
MaterialColor.BLUE,
MaterialColor.TEAL,
MaterialColor.FOREST,
MaterialColor.WINTERGREEN,
MaterialColor.BURLAP,
MaterialColor.STEEL
)));

public static class MaterialColorList {
Expand Down Expand Up @@ -61,9 +62,6 @@ public int[] asConversationColorArray(@NonNull Context context) {

return results;
}

}


}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.util.Arrays;
import java.util.List;

/**
* Colors that can be randomly assigned to a contact.
*/
public class ContactColors {

public static final MaterialColor UNKNOWN_COLOR = MaterialColor.STEEL;
Expand All @@ -23,7 +26,8 @@ public class ContactColors {
MaterialColor.WINTERGREEN,
MaterialColor.TEAL,
MaterialColor.BURLAP,
MaterialColor.TAUPE
MaterialColor.TAUPE,
MaterialColor.ULTRAMARINE
));

public static MaterialColor generateFor(@NonNull String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import androidx.annotation.NonNull;

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.color.MaterialColor;

import java.util.ArrayList;
import java.util.Arrays;

/**
* Used for migrating legacy colors to modern colors. For normal color generation, use
* {@link ContactColors}.
Expand All @@ -28,6 +32,21 @@ public class ContactColorsLegacy {
"blue_grey"
};

private static final String[] LEGACY_PALETTE_2 = new String[]{
"pink",
"red",
"orange",
"purple",
"blue",
"indigo",
"green",
"light_green",
"teal",
"brown",
"blue_grey"
};


public static MaterialColor generateFor(@NonNull String name) {
String serialized = LEGACY_PALETTE[Math.abs(name.hashCode()) % LEGACY_PALETTE.length];
try {
Expand All @@ -36,4 +55,13 @@ public static MaterialColor generateFor(@NonNull String name) {
return ContactColors.generateFor(name);
}
}

public static MaterialColor generateForV2(@NonNull String name) {
String serialized = LEGACY_PALETTE_2[Math.abs(name.hashCode()) % LEGACY_PALETTE_2.length];
try {
return MaterialColor.fromSerialized(serialized);
} catch (MaterialColor.UnknownColorException e) {
return ContactColors.generateFor(name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import net.sqlcipher.database.SQLiteDatabaseHook;
import net.sqlcipher.database.SQLiteOpenHelper;

import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
import org.thoughtcrime.securesms.contacts.avatars.ContactColorsLegacy;
import org.thoughtcrime.securesms.profiles.AvatarHelper;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.thoughtcrime.securesms.recipients.RecipientId;
Expand Down Expand Up @@ -130,8 +133,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
private static final int JOB_INPUT_DATA = 58;
private static final int SERVER_TIMESTAMP = 59;
private static final int REMOTE_DELETE = 60;
private static final int COLOR_MIGRATION = 61;

private static final int DATABASE_VERSION = 60;
private static final int DATABASE_VERSION = 61;
private static final String DATABASE_NAME = "signal.db";

private final Context context;
Expand Down Expand Up @@ -888,6 +892,20 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("ALTER TABLE mms ADD COLUMN remote_deleted INTEGER DEFAULT 0");
}

if (oldVersion < COLOR_MIGRATION) {
try (Cursor cursor = db.rawQuery("SELECT _id, system_display_name FROM recipient WHERE system_display_name NOT NULL AND color IS NULL", null)) {
while (cursor != null && cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow("_id"));
String name = cursor.getString(cursor.getColumnIndexOrThrow("system_display_name"));

ContentValues values = new ContentValues();
values.put("color", ContactColorsLegacy.generateForV2(name).serialize());

db.update("recipient", values, "_id = ?", new String[] { String.valueOf(id) });
}
}
}

db.setTransactionSuccessful();
} finally {
db.endTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public ColorPickerPreference(Context context, AttributeSet attrs, int defStyleAt
}

colorDescriptions = a.getTextArray(R.styleable.ColorPickerPreference_colorDescriptions);
color = a.getColor(R.styleable.ColorPickerPreference_currentColor, 0);
columns = a.getInt(R.styleable.ColorPickerPreference_columns, 3);
size = a.getInt(R.styleable.ColorPickerPreference_colorSize, 2);
sortColors = a.getBoolean(R.styleable.ColorPickerPreference_sortColors, false);
color = a.getColor(R.styleable.ColorPickerPreference_currentColor, 0);
columns = a.getInt(R.styleable.ColorPickerPreference_columns, 3);
size = a.getInt(R.styleable.ColorPickerPreference_colorSize, 2);
sortColors = a.getBoolean(R.styleable.ColorPickerPreference_sortColors, false);

a.recycle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,18 @@ public boolean isLocalNumber() {
}

public @NonNull MaterialColor getColor() {
if (isGroupInternal()) return MaterialColor.GROUP;
else if (color != null) return color;
else if (name != null) return ContactColors.generateFor(name);
else return ContactColors.UNKNOWN_COLOR;
if (isGroupInternal()) {
return MaterialColor.GROUP;
} else if (color != null) {
return color;
} else if (name != null) {
Log.i(TAG, "Saving color for " + id);
MaterialColor color = ContactColors.generateFor(name);
DatabaseFactory.getRecipientDatabase(ApplicationDependencies.getApplication()).setColor(id, color);
return color;
} else {
return ContactColors.UNKNOWN_COLOR;
}
}

public @NonNull Optional<UUID> getUuid() {
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/values/conversation_colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
<color name="conversation_steel_tint">#bebec6</color>
<color name="conversation_steel_shade">#5a5a63</color>

<color name="conversation_ultramarine">@color/core_ultramarine</color>
<color name="conversation_ultramarine_tint">#b0c8f9</color>
<color name="conversation_ultramarine_shade">#1851b4</color>

<color name="conversation_group">@color/core_ultramarine</color>
<color name="conversation_group_tint">@color/core_ultramarine_light</color>
<color name="conversation_group_shade">@color/core_ultramarine_dark</color>
<color name="conversation_group_tint">#b0c8f9</color>
<color name="conversation_group_shade">#1851b4</color>
</resources>

0 comments on commit fc6b5c1

Please sign in to comment.