Skip to content

Commit

Permalink
fix: default-video-quality patch crashing (ReVanced#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Canny1913 authored Jul 26, 2022
1 parent 17a291f commit c6b7528
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
import app.revanced.integrations.utils.ReVancedUtils;

public class VideoQualityPatch {
public static final int[] videoResolutions = {0, 144, 240, 360, 480, 720, 1080, 1440, 2160};
private static Boolean userChangedQuality = false;
public static final int[] videoResolutions = {0, 144, 240, 360, 480, 720, 1080, 1440, 2160, 4320};
public static int selectedQuality1 = -2;
private static Boolean newVideo = false;
private static Boolean userChangedQuality = false;

public static void changeDefaultQuality(int defaultQuality) {
Context context = ReVancedUtils.getContext();
if (isConnectedWifi(context)) {
SharedPreferences wifi = context.getSharedPreferences("revanced_prefs", 0);
SharedPreferences.Editor wifieditor = wifi.edit();
wifieditor.putInt("wifi_quality",defaultQuality);
wifieditor.putInt("wifi_quality", defaultQuality);
wifieditor.apply();
LogHelper.debug(VideoQualityPatch.class, "Changing default Wi-Fi quality to: " + defaultQuality);
} else if (isConnectedMobile(context)) {
SharedPreferences mobile = context.getSharedPreferences("revanced_prefs", 0);
SharedPreferences.Editor mobileeditor = mobile.edit();
mobileeditor.putInt("mobile_quality",defaultQuality);
mobileeditor.putInt("mobile_quality", defaultQuality);
mobileeditor.apply();
LogHelper.debug(VideoQualityPatch.class, "Changing default mobile data quality to: " + defaultQuality);
} else {
Expand All @@ -41,7 +42,7 @@ public static void changeDefaultQuality(int defaultQuality) {
public static int setVideoQuality(Object[] qualities, int quality, Object qInterface, String qIndexMethod) {
int preferredQuality;
Field[] fields;
if (!ReVancedUtils.isNewVideoStarted() && !userChangedQuality || qInterface == null) {
if (!(newVideo || userChangedQuality) || qInterface == null) {
return quality;
}
Class<?> intType = Integer.TYPE;
Expand Down Expand Up @@ -72,7 +73,7 @@ public static int setVideoQuality(Object[] qualities, int quality, Object qInter
}
}
}
ReVancedUtils.setNewVideo(false);
newVideo = false;
LogHelper.debug(VideoQualityPatch.class, "Quality: " + quality);
Context context = ReVancedUtils.getContext();
if (context == null) {
Expand Down Expand Up @@ -127,6 +128,9 @@ public static void userChangedQuality(int selectedQuality) {
userChangedQuality = true;
}

public static void newVideoStarted(String videoId) {
newVideo = true;
}

private static NetworkInfo getNetworkInfo(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Expand Down

0 comments on commit c6b7528

Please sign in to comment.