Skip to content

Commit

Permalink
fix: load numeric preferences as type String
Browse files Browse the repository at this point in the history
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
oSumAtrIX committed Jan 7, 2023
1 parent 758b645 commit 212d3a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,37 @@ public static boolean getBoolean(SharedPrefNames prefName, String key, boolean _
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);
}
Expand Down

0 comments on commit 212d3a7

Please sign in to comment.