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"),
|
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"),
|
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"),
|
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");
|
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>() {{
|
private static final Map<String, MaterialColor> COLOR_MATCHES = new HashMap<String, MaterialColor>() {{
|
||||||
|
@ -48,6 +49,7 @@ public enum MaterialColor {
|
||||||
put("lime", WINTERGREEN);
|
put("lime", WINTERGREEN);
|
||||||
put("blue_grey", TAUPE);
|
put("blue_grey", TAUPE);
|
||||||
put("grey", STEEL);
|
put("grey", STEEL);
|
||||||
|
put("ultramarine", ULTRAMARINE);
|
||||||
put("group_color", GROUP);
|
put("group_color", GROUP);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
|
|
@ -11,18 +11,19 @@ import java.util.List;
|
||||||
public class MaterialColors {
|
public class MaterialColors {
|
||||||
|
|
||||||
public static final MaterialColorList CONVERSATION_PALETTE = new MaterialColorList(new ArrayList<>(Arrays.asList(
|
public static final MaterialColorList CONVERSATION_PALETTE = new MaterialColorList(new ArrayList<>(Arrays.asList(
|
||||||
MaterialColor.PLUM,
|
MaterialColor.PLUM,
|
||||||
MaterialColor.CRIMSON,
|
MaterialColor.CRIMSON,
|
||||||
MaterialColor.VERMILLION,
|
MaterialColor.VERMILLION,
|
||||||
MaterialColor.VIOLET,
|
MaterialColor.VIOLET,
|
||||||
MaterialColor.BLUE,
|
MaterialColor.INDIGO,
|
||||||
MaterialColor.INDIGO,
|
MaterialColor.TAUPE,
|
||||||
MaterialColor.FOREST,
|
MaterialColor.ULTRAMARINE,
|
||||||
MaterialColor.WINTERGREEN,
|
MaterialColor.BLUE,
|
||||||
MaterialColor.TEAL,
|
MaterialColor.TEAL,
|
||||||
MaterialColor.BURLAP,
|
MaterialColor.FOREST,
|
||||||
MaterialColor.TAUPE,
|
MaterialColor.WINTERGREEN,
|
||||||
MaterialColor.STEEL
|
MaterialColor.BURLAP,
|
||||||
|
MaterialColor.STEEL
|
||||||
)));
|
)));
|
||||||
|
|
||||||
public static class MaterialColorList {
|
public static class MaterialColorList {
|
||||||
|
@ -61,9 +62,6 @@ public class MaterialColors {
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Colors that can be randomly assigned to a contact.
|
||||||
|
*/
|
||||||
public class ContactColors {
|
public class ContactColors {
|
||||||
|
|
||||||
public static final MaterialColor UNKNOWN_COLOR = MaterialColor.STEEL;
|
public static final MaterialColor UNKNOWN_COLOR = MaterialColor.STEEL;
|
||||||
|
@ -23,7 +26,8 @@ public class ContactColors {
|
||||||
MaterialColor.WINTERGREEN,
|
MaterialColor.WINTERGREEN,
|
||||||
MaterialColor.TEAL,
|
MaterialColor.TEAL,
|
||||||
MaterialColor.BURLAP,
|
MaterialColor.BURLAP,
|
||||||
MaterialColor.TAUPE
|
MaterialColor.TAUPE,
|
||||||
|
MaterialColor.ULTRAMARINE
|
||||||
));
|
));
|
||||||
|
|
||||||
public static MaterialColor generateFor(@NonNull String name) {
|
public static MaterialColor generateFor(@NonNull String name) {
|
||||||
|
|
|
@ -2,8 +2,12 @@ package org.thoughtcrime.securesms.contacts.avatars;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
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
|
* Used for migrating legacy colors to modern colors. For normal color generation, use
|
||||||
* {@link ContactColors}.
|
* {@link ContactColors}.
|
||||||
|
@ -28,6 +32,21 @@ public class ContactColorsLegacy {
|
||||||
"blue_grey"
|
"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) {
|
public static MaterialColor generateFor(@NonNull String name) {
|
||||||
String serialized = LEGACY_PALETTE[Math.abs(name.hashCode()) % LEGACY_PALETTE.length];
|
String serialized = LEGACY_PALETTE[Math.abs(name.hashCode()) % LEGACY_PALETTE.length];
|
||||||
try {
|
try {
|
||||||
|
@ -36,4 +55,13 @@ public class ContactColorsLegacy {
|
||||||
return ContactColors.generateFor(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,9 @@ import net.sqlcipher.database.SQLiteDatabase;
|
||||||
import net.sqlcipher.database.SQLiteDatabaseHook;
|
import net.sqlcipher.database.SQLiteDatabaseHook;
|
||||||
import net.sqlcipher.database.SQLiteOpenHelper;
|
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.AvatarHelper;
|
||||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
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 JOB_INPUT_DATA = 58;
|
||||||
private static final int SERVER_TIMESTAMP = 59;
|
private static final int SERVER_TIMESTAMP = 59;
|
||||||
private static final int REMOTE_DELETE = 60;
|
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 static final String DATABASE_NAME = "signal.db";
|
||||||
|
|
||||||
private final Context context;
|
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");
|
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();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
|
|
|
@ -45,10 +45,10 @@ public class ColorPickerPreference extends DialogPreference {
|
||||||
}
|
}
|
||||||
|
|
||||||
colorDescriptions = a.getTextArray(R.styleable.ColorPickerPreference_colorDescriptions);
|
colorDescriptions = a.getTextArray(R.styleable.ColorPickerPreference_colorDescriptions);
|
||||||
color = a.getColor(R.styleable.ColorPickerPreference_currentColor, 0);
|
color = a.getColor(R.styleable.ColorPickerPreference_currentColor, 0);
|
||||||
columns = a.getInt(R.styleable.ColorPickerPreference_columns, 3);
|
columns = a.getInt(R.styleable.ColorPickerPreference_columns, 3);
|
||||||
size = a.getInt(R.styleable.ColorPickerPreference_colorSize, 2);
|
size = a.getInt(R.styleable.ColorPickerPreference_colorSize, 2);
|
||||||
sortColors = a.getBoolean(R.styleable.ColorPickerPreference_sortColors, false);
|
sortColors = a.getBoolean(R.styleable.ColorPickerPreference_sortColors, false);
|
||||||
|
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
|
|
|
@ -413,10 +413,18 @@ public class Recipient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull MaterialColor getColor() {
|
public @NonNull MaterialColor getColor() {
|
||||||
if (isGroupInternal()) return MaterialColor.GROUP;
|
if (isGroupInternal()) {
|
||||||
else if (color != null) return color;
|
return MaterialColor.GROUP;
|
||||||
else if (name != null) return ContactColors.generateFor(name);
|
} else if (color != null) {
|
||||||
else return ContactColors.UNKNOWN_COLOR;
|
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() {
|
public @NonNull Optional<UUID> getUuid() {
|
||||||
|
|
|
@ -48,7 +48,11 @@
|
||||||
<color name="conversation_steel_tint">#bebec6</color>
|
<color name="conversation_steel_tint">#bebec6</color>
|
||||||
<color name="conversation_steel_shade">#5a5a63</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">@color/core_ultramarine</color>
|
||||||
<color name="conversation_group_tint">@color/core_ultramarine_light</color>
|
<color name="conversation_group_tint">#b0c8f9</color>
|
||||||
<color name="conversation_group_shade">@color/core_ultramarine_dark</color>
|
<color name="conversation_group_shade">#1851b4</color>
|
||||||
</resources>
|
</resources>
|
Loading…
Add table
Reference in a new issue