Add ultramarine as a conversation color option.
This commit is contained in:
parent
6ecd3b59fd
commit
fc6b5c1d7c
8 changed files with 89 additions and 27 deletions
|
@ -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>() {{
|
||||
|
@ -48,6 +49,7 @@ public enum MaterialColor {
|
|||
put("lime", WINTERGREEN);
|
||||
put("blue_grey", TAUPE);
|
||||
put("grey", STEEL);
|
||||
put("ultramarine", ULTRAMARINE);
|
||||
put("group_color", GROUP);
|
||||
}};
|
||||
|
||||
|
|
|
@ -15,13 +15,14 @@ public class MaterialColors {
|
|||
MaterialColor.CRIMSON,
|
||||
MaterialColor.VERMILLION,
|
||||
MaterialColor.VIOLET,
|
||||
MaterialColor.BLUE,
|
||||
MaterialColor.INDIGO,
|
||||
MaterialColor.TAUPE,
|
||||
MaterialColor.ULTRAMARINE,
|
||||
MaterialColor.BLUE,
|
||||
MaterialColor.TEAL,
|
||||
MaterialColor.FOREST,
|
||||
MaterialColor.WINTERGREEN,
|
||||
MaterialColor.TEAL,
|
||||
MaterialColor.BURLAP,
|
||||
MaterialColor.TAUPE,
|
||||
MaterialColor.STEEL
|
||||
)));
|
||||
|
||||
|
@ -61,9 +62,6 @@ public class MaterialColors {
|
|||
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,9 @@ import java.util.ArrayList;
|
|||
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;
|
||||
|
@ -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) {
|
||||
|
|
|
@ -2,8 +2,12 @@ package org.thoughtcrime.securesms.contacts.avatars;
|
|||
|
||||
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}.
|
||||
|
@ -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 {
|
||||
|
@ -36,4 +55,13 @@ public class ContactColorsLegacy {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ import net.sqlcipher.database.SQLiteDatabase;
|
|||
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;
|
||||
|
@ -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;
|
||||
|
@ -888,6 +892,20 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||
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();
|
||||
|
|
|
@ -413,10 +413,18 @@ public class Recipient {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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>
|
Loading…
Add table
Reference in a new issue