mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 08:28:57 +00:00
Refactor colorization to support dark theme.
// FREEBIE
This commit is contained in:
@@ -10,6 +10,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
@@ -57,7 +58,7 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
NOTIFICATION + " TEXT DEFAULT NULL, " +
|
||||
VIBRATE + " INTEGER DEFAULT " + VibrateState.DEFAULT.getId() + ", " +
|
||||
MUTE_UNTIL + " INTEGER DEFAULT 0, " +
|
||||
COLOR + " INTEGER DEFAULT -1);";
|
||||
COLOR + " TEXT DEFAULT NULL);";
|
||||
|
||||
public RecipientPreferenceDatabase(Context context, SQLiteOpenHelper databaseHelper) {
|
||||
super(context, databaseHelper);
|
||||
@@ -89,16 +90,23 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
String notification = cursor.getString(cursor.getColumnIndexOrThrow(NOTIFICATION));
|
||||
int vibrateState = cursor.getInt(cursor.getColumnIndexOrThrow(VIBRATE));
|
||||
long muteUntil = cursor.getLong(cursor.getColumnIndexOrThrow(MUTE_UNTIL));
|
||||
int color = cursor.getInt(cursor.getColumnIndexOrThrow(COLOR));
|
||||
String serializedColor = cursor.getString(cursor.getColumnIndexOrThrow(COLOR));
|
||||
Uri notificationUri = notification == null ? null : Uri.parse(notification);
|
||||
|
||||
MaterialColor color;
|
||||
|
||||
try {
|
||||
color = serializedColor == null ? null : MaterialColor.fromSerialized(serializedColor);
|
||||
} catch (MaterialColor.UnknownColorException e) {
|
||||
Log.w(TAG, e);
|
||||
color = null;
|
||||
}
|
||||
|
||||
Log.w(TAG, "Muted until: " + muteUntil);
|
||||
|
||||
return Optional.of(new RecipientsPreferences(blocked, muteUntil,
|
||||
VibrateState.fromId(vibrateState),
|
||||
notificationUri,
|
||||
color == -1 ? Optional.<Integer>absent() :
|
||||
Optional.of(color)));
|
||||
notificationUri, color));
|
||||
}
|
||||
|
||||
return Optional.absent();
|
||||
@@ -107,9 +115,9 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(Recipients recipients, int color) {
|
||||
public void setColor(Recipients recipients, MaterialColor color) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLOR, color);
|
||||
values.put(COLOR, color.serialize());
|
||||
updateOrInsert(recipients, values);
|
||||
}
|
||||
|
||||
@@ -158,14 +166,16 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
}
|
||||
|
||||
public static class RecipientsPreferences {
|
||||
private final boolean blocked;
|
||||
private final long muteUntil;
|
||||
private final VibrateState vibrateState;
|
||||
private final Uri notification;
|
||||
private final Optional<Integer> color;
|
||||
private final boolean blocked;
|
||||
private final long muteUntil;
|
||||
private final VibrateState vibrateState;
|
||||
private final Uri notification;
|
||||
private final MaterialColor color;
|
||||
|
||||
public RecipientsPreferences(boolean blocked, long muteUntil, VibrateState vibrateState,
|
||||
Uri notification, Optional<Integer> color)
|
||||
public RecipientsPreferences(boolean blocked, long muteUntil,
|
||||
@NonNull VibrateState vibrateState,
|
||||
@Nullable Uri notification,
|
||||
@Nullable MaterialColor color)
|
||||
{
|
||||
this.blocked = blocked;
|
||||
this.muteUntil = muteUntil;
|
||||
@@ -174,7 +184,7 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Optional<Integer> getColor() {
|
||||
public @Nullable MaterialColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user