mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-19 02:19:23 +01:00
feat: toast notifications for remember-quality
patch (#106)
This commit is contained in:
parent
93a5edc2ba
commit
35ee3415f0
@ -1,9 +1,9 @@
|
||||
package app.revanced.integrations.patches;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
@ -12,6 +12,7 @@ import java.util.Collections;
|
||||
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
import app.revanced.integrations.utils.ReVancedUtils;
|
||||
import app.revanced.integrations.utils.SharedPrefHelper;
|
||||
|
||||
public class VideoQualityPatch {
|
||||
public static final int[] videoResolutions = {0, 144, 240, 360, 480, 720, 1080, 1440, 2160, 4320};
|
||||
@ -22,19 +23,26 @@ public class VideoQualityPatch {
|
||||
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.apply();
|
||||
try {
|
||||
SharedPrefHelper.saveInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", defaultQuality);
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(VideoQualityPatch.class, "Failed to change default WI-FI quality:" + ex);
|
||||
Toast.makeText(context, "Failed to change default WI-FI quality:", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
LogHelper.debug(VideoQualityPatch.class, "Changing default Wi-Fi quality to: " + defaultQuality);
|
||||
Toast.makeText(context, "Changing default Wi-Fi quality to: " + defaultQuality, Toast.LENGTH_SHORT).show();
|
||||
} else if (isConnectedMobile(context)) {
|
||||
SharedPreferences mobile = context.getSharedPreferences("revanced_prefs", 0);
|
||||
SharedPreferences.Editor mobileeditor = mobile.edit();
|
||||
mobileeditor.putInt("mobile_quality", defaultQuality);
|
||||
mobileeditor.apply();
|
||||
LogHelper.debug(VideoQualityPatch.class, "Changing default mobile data quality to: " + defaultQuality);
|
||||
try {
|
||||
SharedPrefHelper.saveInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", defaultQuality);
|
||||
} catch (Exception ex) {
|
||||
LogHelper.debug(VideoQualityPatch.class, "Failed to change default mobile data quality" + ex);
|
||||
Toast.makeText(context, "Failed to change default mobile data quality", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
LogHelper.debug(VideoQualityPatch.class, "Changing default mobile data quality to:" + defaultQuality);
|
||||
Toast.makeText(context, "Changing default mobile data quality to:" + defaultQuality, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
LogHelper.debug(VideoQualityPatch.class, "No Internet connection, aborting default quality change.");
|
||||
LogHelper.debug(VideoQualityPatch.class, "No internet connection.");
|
||||
Toast.makeText(context, "No internet connection.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
userChangedQuality = false;
|
||||
}
|
||||
@ -81,12 +89,10 @@ public class VideoQualityPatch {
|
||||
return quality;
|
||||
}
|
||||
if (isConnectedWifi(context)) {
|
||||
SharedPreferences wifi = context.getSharedPreferences("revanced_prefs", 0);
|
||||
preferredQuality = wifi.getInt("wifi_quality", -2);
|
||||
preferredQuality = SharedPrefHelper.getInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", -2);
|
||||
LogHelper.debug(VideoQualityPatch.class, "Wi-Fi connection detected, preferred quality: " + preferredQuality);
|
||||
} else if (isConnectedMobile(context)) {
|
||||
SharedPreferences mobile = context.getSharedPreferences("revanced_prefs", 0);
|
||||
preferredQuality = mobile.getInt("mobile_quality", -2);
|
||||
preferredQuality = SharedPrefHelper.getInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", -2);
|
||||
LogHelper.debug(VideoQualityPatch.class, "Mobile data connection detected, preferred quality: " + preferredQuality);
|
||||
} else {
|
||||
LogHelper.debug(VideoQualityPatch.class, "No Internet connection!");
|
||||
@ -119,6 +125,7 @@ public class VideoQualityPatch {
|
||||
return qualityIndex;
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(VideoQualityPatch.class, "Failed to set quality", ex);
|
||||
Toast.makeText(context, "Failed to set quality", Toast.LENGTH_SHORT).show();
|
||||
return qualityIndex;
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,8 @@ public class SharedPrefHelper {
|
||||
|
||||
YOUTUBE("youtube"),
|
||||
RYD("ryd"),
|
||||
SPONSOR_BLOCK("sponsor-block");
|
||||
SPONSOR_BLOCK("sponsor-block"),
|
||||
REVANCED_PREFS("revanced_prefs");
|
||||
|
||||
private final String name;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user