Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

chore: merge branch dev to main #277

Merged
merged 2 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,44 +281,32 @@ private static void load() {
Context context = ReVancedUtils.getContext();
if (context == null) {
Log.e("revanced: SettingsEnum", "Context returned null! Setings NOT initialized");
} else {
try {
for (SettingsEnum setting : values()) {
Object value = setting.getDefaultValue();

//LogHelper is not initialized here
Log.d("revanced: SettingsEnum", "Loading Setting: " + setting.name());

var path = setting.getPath();
var defaultValue = setting.getDefaultValue();
switch (setting.getReturnType()) {
case FLOAT:
value = SharedPrefHelper.getFloat(setting.sharedPref, path, (float) defaultValue);
break;
case LONG:
value = SharedPrefHelper.getLong(setting.sharedPref, path, (long) defaultValue);
break;
case BOOLEAN:
value = SharedPrefHelper.getBoolean(setting.sharedPref, path, (boolean) defaultValue);
break;
case INTEGER:
value = SharedPrefHelper.getInt(setting.sharedPref, path, (int) defaultValue);
break;
case STRING:
value = SharedPrefHelper.getString(setting.sharedPref, path, (String) defaultValue);
break;
default:
LogHelper.printException(() -> ("Setting does not have a valid Type. Name is: " + setting.name()));
break;
}
setting.setValue(value);

//LogHelper is not initialized here
Log.d("revanced: SettingsEnum", "Loaded Setting: " + setting.name() + " Value: " + value);
}
} catch (Throwable th) {
LogHelper.printException(() -> ("Error during load()!"), th);
return;
}
for (SettingsEnum setting : values()) {
var path = setting.getPath();
var defaultValue = setting.getDefaultValue();
switch (setting.getReturnType()) {
case FLOAT:
defaultValue = SharedPrefHelper.getFloat(setting.sharedPref, path, (float) defaultValue);
break;
case LONG:
defaultValue = SharedPrefHelper.getLong(setting.sharedPref, path, (long) defaultValue);
break;
case BOOLEAN:
defaultValue = SharedPrefHelper.getBoolean(setting.sharedPref, path, (boolean) defaultValue);
break;
case INTEGER:
defaultValue = SharedPrefHelper.getInt(setting.sharedPref, path, (int) defaultValue);
break;
case STRING:
defaultValue = SharedPrefHelper.getString(setting.sharedPref, path, (String) defaultValue);
break;
default:
LogHelper.printException(() -> ("Setting does not have a valid Type. Name is: " + setting.name()));
break;
}
setting.setValue(defaultValue);
}
}

Expand Down Expand Up @@ -346,16 +334,34 @@ public void setValue(Object newValue) {
*/
public void saveValue(Object newValue) {
Context context = ReVancedUtils.getContext();
if (context != null) {
if (returnType == ReturnType.BOOLEAN) {
SharedPrefHelper.saveBoolean(sharedPref, path, (Boolean) newValue);
} else {
SharedPrefHelper.saveString(sharedPref, path, newValue + "");
}
value = newValue;
} else {

if (context == null) {
LogHelper.printException(() -> ("Context on SaveValue is null!"));
return;
}

switch (getReturnType()) {
case FLOAT:
SharedPrefHelper.saveFloat(sharedPref, path, (float) defaultValue);
break;
case LONG:
SharedPrefHelper.saveLong(sharedPref, path, (long) defaultValue);
break;
case BOOLEAN:
SharedPrefHelper.saveBoolean(sharedPref, path, (boolean) newValue);
break;
case INTEGER:
SharedPrefHelper.saveInt(sharedPref, path, (int) defaultValue);
break;
case STRING:
SharedPrefHelper.saveString(sharedPref, path, (String) defaultValue);
break;
default:
LogHelper.printException(() -> ("Setting does not have a valid Type. Name is: " + name()));
break;
}

value = newValue;
}

public int getInt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@ public static void saveString(SharedPrefNames prefName, String key, String value
getPreferences(prefName).edit().putString(key, value).apply();
}

public static void saveBoolean(SharedPrefNames prefName, String key, Boolean value) {
public static void saveBoolean(SharedPrefNames prefName, String key, boolean value) {
getPreferences(prefName).edit().putBoolean(key, value).apply();
}

public static void saveFloat(SharedPrefNames prefName, String key, Float value) {
public static void saveFloat(SharedPrefNames prefName, String key, float value) {
getPreferences(prefName).edit().putFloat(key, value).apply();
}

public static void saveInt(SharedPrefNames prefName, String key, Integer value) {
public static void saveInt(SharedPrefNames prefName, String key, int value) {
getPreferences(prefName).edit().putInt(key, value).apply();
}

public static void saveLong(SharedPrefNames prefName, String key, Long value) {
public static void saveLong(SharedPrefNames prefName, String key, long value) {
getPreferences(prefName).edit().putLong(key, value).apply();
}

public static String getString(SharedPrefNames prefName, String key, String _default) {
return getPreferences(prefName).getString(key, _default);
}

public static Boolean getBoolean(SharedPrefNames prefName, String key, Boolean _default) {
public static boolean getBoolean(SharedPrefNames prefName, String key, boolean _default) {
return getPreferences(prefName).getBoolean(key, _default);
}

public static Long getLong(SharedPrefNames prefName, String key, Long _default) {
public static long getLong(SharedPrefNames prefName, String key, long _default) {
return getPreferences(prefName).getLong(key, _default);
}

public static Float getFloat(SharedPrefNames prefName, String key, Float _default) {
public static float getFloat(SharedPrefNames prefName, String key, float _default) {
return getPreferences(prefName).getFloat(key, _default);
}

public static Integer getInt(SharedPrefNames prefName, String key, Integer _default) {
public static int getInt(SharedPrefNames prefName, String key, int _default) {
return getPreferences(prefName).getInt(key, _default);
}

Expand Down
17 changes: 9 additions & 8 deletions app/src/main/java/app/revanced/tiktok/settings/SettingsEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,17 @@ public void setValue(Object newValue) {

public void saveValue(Object newValue) {
Context context = ReVancedUtils.getAppContext();
if (context != null) {
if (returnType == ReturnType.BOOLEAN) {
SharedPrefHelper.saveBoolean(context, sharedPref, path, (Boolean) newValue);
} else {
SharedPrefHelper.saveString(context, sharedPref, path, newValue + "");
}
value = newValue;
} else {
if (context == null) {
LogHelper.printException(SettingsEnum.class, "Context on SaveValue is null!");
return;
}

if (returnType == ReturnType.BOOLEAN) {
SharedPrefHelper.saveBoolean(context, sharedPref, path, (Boolean) newValue);
} else {
SharedPrefHelper.saveString(context, sharedPref, path, newValue + "");
}
value = newValue;
}

public int getInt() {
Expand Down