Skip to content

Commit

Permalink
Update GlobalConfig.java
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBRDeveloper authored Dec 15, 2023
1 parent cc44801 commit 9fd94f0
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ public static <T extends Serializable> T get(Key<T> key) {
return (T) value;
}

//Need synchronized why SharedPreferences don't support aysnc write
public static synchronized <T extends Serializable> void set(Key<T> key, T value) {
if (value instanceof String) {
data.edit().putString(key.name, (String) value).apply();
} else if (value instanceof Integer) {
data.edit().putInt(key.name, (Integer) value).apply();
data.edit().putInt(key.name, (int) value).apply();
} else if (value instanceof Boolean) {
data.edit().putBoolean(key.name, (Boolean) value).apply();
data.edit().putBoolean(key.name, (boolean) value).apply();
} else if (value instanceof Long) {
data.edit().putLong(key.name, (Long) value).apply();
data.edit().putLong(key.name, (long) value).apply();
} else if (value instanceof Float) {
data.edit().putFloat(key.name, (Float) value).apply();
data.edit().putFloat(key.name, (float) value).apply();
} else {
throw new IllegalArgumentException("Invalid global config value instance");
}
Expand All @@ -58,4 +57,4 @@ private Key(String name, T defaultValue) {
this.defaultValue = defaultValue;
}
}
}
}

0 comments on commit 9fd94f0

Please sign in to comment.