chore: merge branch dev to main (#275)

This commit is contained in:
oSumAtrIX 2023-01-07 09:47:28 +01:00 committed by GitHub
commit 05cca001ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 126 additions and 275 deletions

View File

@ -29,8 +29,6 @@ jobs:
with:
node-version: "latest"
cache: 'npm'
- name: Build with Gradle
run: ./gradlew build --no-daemon
- name: Setup semantic-release
run: npm install semantic-release @saithodev/semantic-release-backmerge @semantic-release/git @semantic-release/changelog gradle-semantic-release-plugin -D
- name: Release

View File

@ -1,3 +1,17 @@
# [0.92.0-dev.1](https://github.com/revanced/revanced-integrations/compare/v0.91.3-dev.1...v0.92.0-dev.1) (2023-01-07)
### Features
* **youtube:** `remember-playback-rate` patch ([b5c0c84](https://github.com/revanced/revanced-integrations/commit/b5c0c843a502a7f4938053d136e826fbf7399e7b))
## [0.91.3-dev.1](https://github.com/revanced/revanced-integrations/compare/v0.91.2...v0.91.3-dev.1) (2023-01-05)
### Bug Fixes
* ensure thread safety for class `StringRef` ([#273](https://github.com/revanced/revanced-integrations/issues/273)) ([f5c5fcb](https://github.com/revanced/revanced-integrations/commit/f5c5fcb5e46f43b2e5abbbc4f55a1cf1c52e0549))
## [0.91.2](https://github.com/revanced/revanced-integrations/compare/v0.91.1...v0.91.2) (2023-01-04)

View File

@ -48,6 +48,8 @@ dependencies {
compileOnly(project(mapOf("path" to ":dummy")))
compileOnly("androidx.annotation:annotation:1.5.0")
compileOnly("androidx.appcompat:appcompat:1.5.1")
compileOnly("com.squareup.okhttp3:okhttp:4.10.0")
compileOnly("com.squareup.okhttp3:okhttp:5.0.0-alpha.11")
compileOnly("com.squareup.retrofit2:retrofit:2.9.0")
}
tasks.register("publish") { dependsOn("build") }

View File

@ -1,177 +0,0 @@
package app.revanced.integrations.patches;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
public class VideoSpeedPatch {
public static final float[] videoSpeeds = { 0, 0 }; // Values are useless as they are being overridden by the respective patch
private static Boolean userChangedSpeed = false;
public static int getDefaultSpeed(Object[] speeds, int speed, Object qInterface) {
int speed2;
Exception e;
if (!ReVancedUtils.isNewVideoStarted()) {
return speed;
}
ReVancedUtils.setNewVideo(false);
LogHelper.printDebug(() -> "Speed: " + speed);
float preferredSpeed = SettingsEnum.PREFERRED_VIDEO_SPEED.getFloat();
LogHelper.printDebug(() -> "Preferred speed: " + preferredSpeed);
if (preferredSpeed == -2.0f) {
return speed;
}
Class<?> floatType = Float.TYPE;
ArrayList<Float> iStreamSpeeds = new ArrayList<>();
try {
for (Object streamSpeed : speeds) {
Field[] fields = streamSpeed.getClass().getFields();
for (Field field : fields) {
if (field.getType().isAssignableFrom(floatType)) {
float value = field.getFloat(streamSpeed);
if (field.getName().length() <= 2) {
iStreamSpeeds.add(value);
}
}
}
}
} catch (Exception ignored) {
}
Iterator<Float> it = iStreamSpeeds.iterator();
int index = 0;
while (it.hasNext()) {
float streamSpeed2 = it.next();
final int logIndex = index;
LogHelper.printDebug(() -> "Speed at index " + logIndex + ": " + streamSpeed2);
index++;
}
int speed3 = -1;
for (float streamSpeed3 : iStreamSpeeds) {
if (streamSpeed3 <= preferredSpeed) {
speed3++;
final int speed3ToLog = speed3;
LogHelper.printDebug(() -> "Speed loop at index " + speed3ToLog + ": " + streamSpeed3);
}
}
if (speed3 == -1) {
LogHelper.printDebug(() -> "Speed was not found");
speed2 = 3;
} else {
speed2 = speed3;
}
try {
Method[] declaredMethods = qInterface.getClass().getDeclaredMethods();
for (Method method : declaredMethods) {
if (method.getName().length() <= 2) {
LogHelper.printDebug(() -> "Method name: " + method.getName());
try {
try {
method.invoke(qInterface, videoSpeeds[speed2]);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {
} catch (final Exception e6) {
LogHelper.printException(() -> (e6.getMessage()));
return speed2;
}
} catch (Exception ignored) {
}
}
}
} catch (Exception e10) {
e = e10;
}
LogHelper.printDebug(() -> "Speed changed to: " + speed2);
return speed2;
}
public static void userChangedSpeed() {
userChangedSpeed = true;
}
public static float getSpeedValue(Object[] speeds, int speed) {
int i = 0;
if (!ReVancedUtils.isNewVideoStarted() || userChangedSpeed) {
if (SettingsEnum.DEBUG.getBoolean() && userChangedSpeed) {
LogHelper.printDebug(() -> "Skipping speed change because user changed it: " + speed);
}
userChangedSpeed = false;
return -1.0f;
}
ReVancedUtils.setNewVideo(false);
LogHelper.printDebug(() -> "Speed: " + speed);
float preferredSpeed = SettingsEnum.PREFERRED_VIDEO_SPEED.getFloat();
LogHelper.printDebug(() -> "Preferred speed: " + preferredSpeed);
if (preferredSpeed == -2.0f) {
return -1.0f;
}
Class<?> floatType = Float.TYPE;
ArrayList<Float> iStreamSpeeds = new ArrayList<>();
try {
int length = speeds.length;
int i2 = 0;
while (i2 < length) {
Object streamSpeed = speeds[i2];
Field[] fields = streamSpeed.getClass().getFields();
int length2 = fields.length;
while (i < length2) {
Field field = fields[i];
if (field.getType().isAssignableFrom(floatType)) {
float value = field.getFloat(streamSpeed);
if (field.getName().length() <= 2) {
iStreamSpeeds.add(value);
}
}
i++;
}
i2++;
i = 0;
}
} catch (Exception ignored) {
}
int index = 0;
for (Float iStreamSpeed : iStreamSpeeds) {
float streamSpeed2 = iStreamSpeed;
final int indexToLog = index;
LogHelper.printDebug(() -> "Speed at index " + indexToLog + ": " + streamSpeed2);
index++;
}
int newSpeedIndex = -1;
for (Float iStreamSpeed : iStreamSpeeds) {
float streamSpeed3 = iStreamSpeed;
if (streamSpeed3 <= preferredSpeed) {
newSpeedIndex++;
final int newSpeedIndexToLog = newSpeedIndex;
LogHelper.printDebug(() -> "Speed loop at index " + newSpeedIndexToLog + ": " + streamSpeed3);
}
}
if (newSpeedIndex == -1) {
LogHelper.printDebug(() -> "Speed was not found");
newSpeedIndex = 3;
}
if (newSpeedIndex == speed) {
final int newSpeedIndexToLog = newSpeedIndex;
LogHelper.printDebug(() -> "Trying to set speed to what it already is, skipping...: " + newSpeedIndexToLog);
return -1.0f;
}
final int newSpeedIndexToLog = newSpeedIndex;
LogHelper.printDebug(() -> "Speed changed to: " + newSpeedIndexToLog);
return getSpeedByIndex(newSpeedIndex);
}
private static float getSpeedByIndex(int index) {
if (index == -2) {
return 1.0f;
}
try {
return videoSpeeds[index];
} catch (Exception e) {
return 1.0f;
}
}
}

View File

@ -25,7 +25,7 @@ public class RememberVideoQualityPatch {
Context context = ReVancedUtils.getContext();
if (isConnectedWifi(context)) {
try {
SharedPrefHelper.saveString(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", defaultQuality + "");
SharedPrefHelper.saveString(SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", defaultQuality + "");
} catch (Exception ex) {
LogHelper.printException(() -> ("Failed to change default WI-FI quality:" + ex));
Toast.makeText(context, "Failed to change default WI-FI quality:", Toast.LENGTH_SHORT).show();
@ -34,7 +34,7 @@ public class RememberVideoQualityPatch {
Toast.makeText(context, "Changing default Wi-Fi quality to: " + defaultQuality, Toast.LENGTH_SHORT).show();
} else if (isConnectedMobile(context)) {
try {
SharedPrefHelper.saveString(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", defaultQuality + "");
SharedPrefHelper.saveString(SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", defaultQuality + "");
} catch (Exception ex) {
LogHelper.printDebug(() -> "Failed to change default mobile data quality" + ex);
Toast.makeText(context, "Failed to change default mobile data quality", Toast.LENGTH_SHORT).show();
@ -92,10 +92,10 @@ public class RememberVideoQualityPatch {
return quality;
}
if (isConnectedWifi(context)) {
preferredQuality = SharedPrefHelper.getInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", -2);
preferredQuality = SharedPrefHelper.getInt(SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", -2);
LogHelper.printDebug(() -> "Wi-Fi connection detected, preferred quality: " + preferredQuality);
} else if (isConnectedMobile(context)) {
preferredQuality = SharedPrefHelper.getInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", -2);
preferredQuality = SharedPrefHelper.getInt(SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", -2);
LogHelper.printDebug(() -> "Mobile data connection detected, preferred quality: " + preferredQuality);
} else {
LogHelper.printDebug(() -> "No Internet connection!");
@ -137,7 +137,7 @@ public class RememberVideoQualityPatch {
public static void userChangedQuality(int selectedQuality) {
// Do not remember a **new** quality if REMEMBER_VIDEO_QUALITY is false
if (SettingsEnum.REMEMBER_VIDEO_QUALITY_LAST_SELECTED.getBoolean() == false) return;
if (!SettingsEnum.REMEMBER_VIDEO_QUALITY_LAST_SELECTED.getBoolean()) return;
selectedQuality1 = selectedQuality;
userChangedQuality = true;

View File

@ -1,5 +1,9 @@
package app.revanced.integrations.patches.playback.speed;
public class CustomVideoSpeedPatch {
public static final float[] videoSpeeds = { 0, 0 }; // Values are useless as they are being overridden by the respective patch
// Values are useless as they are being overridden by the respective patch.
// This generates a .array segment in Dalvik bytecode
// which the patch utilizes to store the video speeds in, only
// if it has two or more default values.
public static final float[] videoSpeeds = { 0, 0 };
}

View File

@ -0,0 +1,32 @@
package app.revanced.integrations.patches.playback.speed;
import static app.revanced.integrations.utils.SharedPrefHelper.SharedPrefNames.REVANCED_PREFS;
import static app.revanced.integrations.utils.SharedPrefHelper.getFloat;
import static app.revanced.integrations.utils.SharedPrefHelper.saveFloat;
import android.widget.Toast;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
public final class RememberPlaybackRatePatch {
private static final String REMEMBERED_PLAYBACK_RATE_PREFERENCE_KEY = "revanced_remember_playback_rate_last_value";
public static void rememberPlaybackRate(final float selectedPlaybackRate) {
if (!SettingsEnum.REMEMBER_PLAYBACK_RATE_SELECTED.getBoolean()) return;
Toast.makeText(ReVancedUtils.getContext(), "Playback rate will be remembered", Toast.LENGTH_SHORT).show();
LogHelper.printDebug(() -> "Remembering playback rate: " + selectedPlaybackRate);
saveFloat(REVANCED_PREFS, REMEMBERED_PLAYBACK_RATE_PREFERENCE_KEY, selectedPlaybackRate);
}
public static float getRememberedPlaybackRate() {
final var playbackRateOverride = getFloat(REVANCED_PREFS, REMEMBERED_PLAYBACK_RATE_PREFERENCE_KEY, -2f);
LogHelper.printDebug(() -> "Overriding playback rate: " + playbackRateOverride);
return playbackRateOverride;
}
}

View File

@ -187,8 +187,7 @@ public class ReturnYouTubeDislike {
if (!isEnabled) return;
try {
Objects.requireNonNull(vote);
Context context = Objects.requireNonNull(ReVancedUtils.getContext());
if (SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.YOUTUBE, "user_signed_out", true)) {
if (SharedPrefHelper.getBoolean(SharedPrefHelper.SharedPrefNames.YOUTUBE, "user_signed_out", true)) {
return;
}

View File

@ -22,8 +22,9 @@ public enum SettingsEnum {
// Video settings
OLD_STYLE_VIDEO_QUALITY_PLAYER_SETTINGS("revanced_use_old_style_quality_settings", true, ReturnType.BOOLEAN),
PREFERRED_VIDEO_SPEED("revanced_pref_video_speed", -2.0f, ReturnType.FLOAT),
REMEMBER_VIDEO_QUALITY_LAST_SELECTED("revanced_remember_video_quality_last_selected", true, ReturnType.BOOLEAN),
REMEMBER_PLAYBACK_RATE_SELECTED("revanced_remember_playback_rate_selected", true, ReturnType.BOOLEAN),
// Whitelist settings
//ToDo: Not used atm, Patch missing
@ -288,21 +289,23 @@ public enum SettingsEnum {
//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(context, setting.sharedPref, setting.getPath(), (float) setting.getDefaultValue());
value = SharedPrefHelper.getFloat(setting.sharedPref, path, (float) defaultValue);
break;
case LONG:
value = SharedPrefHelper.getLong(context, setting.sharedPref, setting.getPath(), (long) setting.getDefaultValue());
value = SharedPrefHelper.getLong(setting.sharedPref, path, (long) defaultValue);
break;
case BOOLEAN:
value = SharedPrefHelper.getBoolean(context, setting.sharedPref, setting.getPath(), (boolean) setting.getDefaultValue());
value = SharedPrefHelper.getBoolean(setting.sharedPref, path, (boolean) defaultValue);
break;
case INTEGER:
value = SharedPrefHelper.getInt(context, setting.sharedPref, setting.getPath(), (int) setting.getDefaultValue());
value = SharedPrefHelper.getInt(setting.sharedPref, path, (int) defaultValue);
break;
case STRING:
value = SharedPrefHelper.getString(context, setting.sharedPref, setting.getPath(), (String) setting.getDefaultValue());
value = SharedPrefHelper.getString(setting.sharedPref, path, (String) defaultValue);
break;
default:
LogHelper.printException(() -> ("Setting does not have a valid Type. Name is: " + setting.name()));
@ -345,9 +348,9 @@ public enum SettingsEnum {
Context context = ReVancedUtils.getContext();
if (context != null) {
if (returnType == ReturnType.BOOLEAN) {
SharedPrefHelper.saveBoolean(context, sharedPref, path, (Boolean) newValue);
SharedPrefHelper.saveBoolean(sharedPref, path, (Boolean) newValue);
} else {
SharedPrefHelper.saveString(context, sharedPref, path, newValue + "");
SharedPrefHelper.saveString(sharedPref, path, newValue + "");
}
value = newValue;
} else {

View File

@ -70,20 +70,6 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
break;
}
setting.setValue(value);
} else if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref;
if (setting == SettingsEnum.PREFERRED_VIDEO_SPEED) {
try {
String value = sharedPreferences.getString(setting.getPath(), setting.getDefaultValue() + "");
listPref.setDefaultValue(value);
listPref.setSummary(videoSpeedEntries[listPref.findIndexOfValue(value)]);
SettingsEnum.PREFERRED_VIDEO_SPEED.saveValue(value);
} catch (Throwable th) {
LogHelper.printException(() -> ("Error setting value of speed" + th));
}
} else {
LogHelper.printException(() -> ("No valid setting found: " + setting.toString()));
}
} else {
LogHelper.printException(() -> ("Setting cannot be handled! " + pref.toString()));
}

View File

@ -52,7 +52,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(context);
setPreferenceScreen(preferenceScreen);
SponsorBlockSettings.update(context);
SponsorBlockSettings.update(getActivity());
{
SwitchPreference preference = new SwitchPreference(context);
@ -349,7 +349,6 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
return;
Context context = ((AlertDialog) dialog).getContext();
Context applicationContext = context.getApplicationContext();
SharedPreferences preferences = SharedPrefHelper.getPreferences(context, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK);
switch (which) {
case DialogInterface.BUTTON_NEUTRAL:

View File

@ -56,8 +56,7 @@ public class PlayerController {
return;
}
Context context = ReVancedUtils.getContext();
SponsorBlockSettings.update(context);
SponsorBlockSettings.update(null);
if (!SettingsEnum.SB_ENABLED.getBoolean()) {
currentVideoId = null;

View File

@ -2,7 +2,7 @@ package app.revanced.integrations.sponsorblock;
import static app.revanced.integrations.sponsorblock.StringRef.sf;
import android.content.Context;
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Paint;
@ -16,7 +16,6 @@ import java.util.Map;
import java.util.UUID;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.SharedPrefHelper;
public class SponsorBlockSettings {
@ -25,10 +24,8 @@ public class SponsorBlockSettings {
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.IGNORE;
public static String sponsorBlockUrlCategories = "[]";
public static void update(Context context) {
if (context == null) return;
SharedPreferences preferences = SharedPrefHelper.getPreferences(context, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK);
public static void update(Activity _activity) {
SharedPreferences preferences = SharedPrefHelper.getPreferences(SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK);
if (!SettingsEnum.SB_ENABLED.getBoolean()) {
SkipSegmentView.hide();

View File

@ -514,7 +514,7 @@ public abstract class SponsorBlockUtils {
JSONArray categorySelectionsArray = settingsJson.getJSONArray("categorySelections");
SharedPreferences.Editor editor = SharedPrefHelper.getPreferences(context, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK).edit();
SharedPreferences.Editor editor = SharedPrefHelper.getPreferences(SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK).edit();
SponsorBlockSettings.SegmentInfo[] categories = SponsorBlockSettings.SegmentInfo.valuesWithoutUnsubmitted();
for (SponsorBlockSettings.SegmentInfo category : categories) {
@ -605,7 +605,7 @@ public abstract class SponsorBlockUtils {
}
public static boolean isSBButtonEnabled(Context context, String key) {
return SettingsEnum.SB_ENABLED.getBoolean() && SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, key, false);
return SettingsEnum.SB_ENABLED.getBoolean() && SharedPrefHelper.getBoolean(SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, key, false);
}
public enum VoteOption {

View File

@ -5,16 +5,20 @@ import android.content.res.Resources;
import androidx.annotation.NonNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
// should probably move this class into utils package
public class StringRef {
private static Resources resources;
private static String packageName;
private static final HashMap<String, StringRef> strings = new HashMap<>();
// must use a thread safe map, as this class is used both on and off the main thread
private static final Map<String, StringRef> strings = Collections.synchronizedMap(new HashMap());
/**
* Gets strings reference from shared collection or creates if not exists yet,
@ -90,9 +94,11 @@ public class StringRef {
@NonNull
public String toString() {
if (!resolved) {
Context context = ReVancedUtils.getContext();
resources = context.getResources();
packageName = context.getPackageName();
if (resources == null || packageName == null) {
Context context = ReVancedUtils.getContext();
resources = context.getResources();
packageName = context.getPackageName();
}
resolved = true;
if (resources != null) {
final int identifier = resources.getIdentifier(value, "string", packageName);

View File

@ -21,7 +21,7 @@ public class SwipeHelper {
try {
_frameLayout = (FrameLayout) obj;
Context appContext = ReVancedUtils.getContext();
if (ReVancedUtils.isTablet(appContext) || SharedPrefHelper.getBoolean(appContext, SharedPrefHelper.SharedPrefNames.YOUTUBE,"pref_swipe_tablet", false)) {
if (ReVancedUtils.isTablet(appContext) || SharedPrefHelper.getBoolean(SharedPrefHelper.SharedPrefNames.YOUTUBE, "pref_swipe_tablet", false)) {
isTabletMode = true;
}
} catch (Exception e) {

View File

@ -5,12 +5,12 @@ import android.content.Context;
import app.revanced.integrations.utils.SharedPrefHelper;
public class ButtonVisibility {
public static Visibility getButtonVisibility(Context context, String key) {
return getButtonVisibility(context, key, SharedPrefHelper.SharedPrefNames.YOUTUBE);
public static Visibility getButtonVisibility(String key) {
return getButtonVisibility(key, SharedPrefHelper.SharedPrefNames.YOUTUBE);
}
public static Visibility getButtonVisibility(Context context, String key, SharedPrefHelper.SharedPrefNames name) {
String value = SharedPrefHelper.getString(context, name, key, null);
public static Visibility getButtonVisibility(String key, SharedPrefHelper.SharedPrefNames name) {
String value = SharedPrefHelper.getString(name, key, null);
if (value == null || value.isEmpty()) return Visibility.NONE;
@ -26,12 +26,12 @@ public class ButtonVisibility {
}
}
public static boolean isVisibleInContainer(Context context, String key) {
return isVisibleInContainer(getButtonVisibility(context, key));
public static boolean isVisibleInContainer(String key) {
return isVisibleInContainer(getButtonVisibility(key));
}
public static boolean isVisibleInContainer(Context context, String key, SharedPrefHelper.SharedPrefNames name) {
return isVisibleInContainer(getButtonVisibility(context, key, name));
public static boolean isVisibleInContainer(String key, SharedPrefHelper.SharedPrefNames name) {
return isVisibleInContainer(getButtonVisibility(key, name));
}
public static boolean isVisibleInContainer(Visibility visibility) {

View File

@ -3,62 +3,51 @@ package app.revanced.integrations.utils;
import android.content.Context;
import android.content.SharedPreferences;
import java.util.Objects;
public class SharedPrefHelper {
public static void saveString(Context context, SharedPrefNames prefName, String key, String value) {
SharedPreferences sharedPreferences = getPreferences(context, prefName);
sharedPreferences.edit().putString(key, value).apply();
public static void saveString(SharedPrefNames prefName, String key, String value) {
getPreferences(prefName).edit().putString(key, value).apply();
}
public static void saveBoolean(Context context, SharedPrefNames prefName, String key, Boolean value) {
SharedPreferences sharedPreferences = getPreferences(context, prefName);
sharedPreferences.edit().putBoolean(key, value).apply();
public static void saveBoolean(SharedPrefNames prefName, String key, Boolean value) {
getPreferences(prefName).edit().putBoolean(key, value).apply();
}
public static String getString(Context context, SharedPrefNames prefName, String key, String _default) {
SharedPreferences sharedPreferences = getPreferences(context, prefName);
return (sharedPreferences.getString(key, _default));
public static void saveFloat(SharedPrefNames prefName, String key, Float value) {
getPreferences(prefName).edit().putFloat(key, value).apply();
}
public static Boolean getBoolean(Context context, SharedPrefNames prefName, String key, Boolean _default) {
SharedPreferences sharedPreferences = getPreferences(context, prefName);
return (sharedPreferences.getBoolean(key, _default));
public static void saveInt(SharedPrefNames prefName, String key, Integer value) {
getPreferences(prefName).edit().putInt(key, value).apply();
}
public static Long getLong(Context context, SharedPrefNames prefName, String key, Long _default) {
SharedPreferences sharedPreferences = getPreferences(context, prefName);
try {
return Long.valueOf(sharedPreferences.getString(key, _default + ""));
} catch (ClassCastException ex) {
return sharedPreferences.getLong(key, _default);
}
public static void saveLong(SharedPrefNames prefName, String key, Long value) {
getPreferences(prefName).edit().putLong(key, value).apply();
}
public static Float getFloat(Context context, SharedPrefNames prefName, String key, Float _default) {
SharedPreferences sharedPreferences = getPreferences(context, prefName);
try {
return Float.valueOf(sharedPreferences.getString(key, _default + ""));
} catch (ClassCastException ex) {
return sharedPreferences.getFloat(key, _default);
}
public static String getString(SharedPrefNames prefName, String key, String _default) {
return getPreferences(prefName).getString(key, _default);
}
public static Integer getInt(Context context, SharedPrefNames prefName, String key, Integer _default) {
SharedPreferences sharedPreferences = getPreferences(context, prefName);
try {
return Integer.valueOf(sharedPreferences.getString(key, _default + ""));
} catch (ClassCastException ex) {
return sharedPreferences.getInt(key, _default);
}
public static Boolean getBoolean(SharedPrefNames prefName, String key, Boolean _default) {
return getPreferences(prefName).getBoolean(key, _default);
}
public static SharedPreferences getPreferences(Context context, SharedPrefNames name) {
if (context == null) return null;
return context.getSharedPreferences(name.getName(), Context.MODE_PRIVATE);
public static Long getLong(SharedPrefNames prefName, String key, Long _default) {
return getPreferences(prefName).getLong(key, _default);
}
public static SharedPreferences getPreferences(Context context, String name) {
if (context == null) return null;
return context.getSharedPreferences(name, Context.MODE_PRIVATE);
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) {
return getPreferences(prefName).getInt(key, _default);
}
public static SharedPreferences getPreferences(SharedPrefNames name) {
return Objects.requireNonNull(ReVancedUtils.getContext()).getSharedPreferences(name.getName(), Context.MODE_PRIVATE);
}
public enum SharedPrefNames {

View File

@ -1,3 +1,3 @@
org.gradle.jvmargs = -Xmx2048m
android.useAndroidX = true
version = 0.91.2
version = 0.92.0-dev.1