fix: load numeric preferences as type String

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
oSumAtrIX 2023-01-07 14:19:00 +01:00
parent 758b645913
commit 212d3a72d8
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 26 additions and 7 deletions

View File

@ -280,7 +280,7 @@ public enum SettingsEnum {
private static void load() {
Context context = ReVancedUtils.getContext();
if (context == null) {
Log.e("revanced: SettingsEnum", "Context returned null! Setings NOT initialized");
LogHelper.printException(() -> "SettingsEnum.load() called before ReVancedUtils.init()");
return;
}
for (SettingsEnum setting : values()) {

View File

@ -34,18 +34,37 @@ public class SharedPrefHelper {
return getPreferences(prefName).getBoolean(key, _default);
}
public static long getLong(SharedPrefNames prefName, String key, long _default) {
return getPreferences(prefName).getLong(key, _default);
// region Hack, unknown why required
public static Long getLong(SharedPrefNames prefName, String key, Long _default) {
SharedPreferences sharedPreferences = getPreferences(prefName);
try {
return Long.valueOf(sharedPreferences.getString(key, _default + ""));
} catch (ClassCastException ex) {
return sharedPreferences.getLong(key, _default);
}
}
public static float getFloat(SharedPrefNames prefName, String key, float _default) {
return getPreferences(prefName).getFloat(key, _default);
public static Float getFloat(SharedPrefNames prefName, String key, Float _default) {
SharedPreferences sharedPreferences = getPreferences(prefName);
try {
return Float.valueOf(sharedPreferences.getString(key, _default + ""));
} catch (ClassCastException ex) {
return sharedPreferences.getFloat(key, _default);
}
}
public static int getInt(SharedPrefNames prefName, String key, int _default) {
return getPreferences(prefName).getInt(key, _default);
public static Integer getInt(SharedPrefNames prefName, String key, Integer _default) {
SharedPreferences sharedPreferences = getPreferences(prefName);
try {
return Integer.valueOf(sharedPreferences.getString(key, _default + ""));
} catch (ClassCastException ex) {
return sharedPreferences.getInt(key, _default);
}
}
// endregion
public static SharedPreferences getPreferences(SharedPrefNames name) {
return Objects.requireNonNull(ReVancedUtils.getContext()).getSharedPreferences(name.getName(), Context.MODE_PRIVATE);
}