1
mirror of https://github.com/revanced/revanced-integrations synced 2024-11-27 11:13:38 +01:00

feat: toast notifications for remember-quality patch (#106)

This commit is contained in:
Canny1913 2022-07-28 21:22:18 +03:00 committed by GitHub
parent 93a5edc2ba
commit 35ee3415f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 16 deletions

View File

@ -1,9 +1,9 @@
package app.revanced.integrations.patches; package app.revanced.integrations.patches;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.widget.Toast;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -12,6 +12,7 @@ import java.util.Collections;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils; import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
public class VideoQualityPatch { public class VideoQualityPatch {
public static final int[] videoResolutions = {0, 144, 240, 360, 480, 720, 1080, 1440, 2160, 4320}; 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) { public static void changeDefaultQuality(int defaultQuality) {
Context context = ReVancedUtils.getContext(); Context context = ReVancedUtils.getContext();
if (isConnectedWifi(context)) { if (isConnectedWifi(context)) {
SharedPreferences wifi = context.getSharedPreferences("revanced_prefs", 0); try {
SharedPreferences.Editor wifieditor = wifi.edit(); SharedPrefHelper.saveInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", defaultQuality);
wifieditor.putInt("wifi_quality", defaultQuality); } catch (Exception ex) {
wifieditor.apply(); 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); 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)) { } else if (isConnectedMobile(context)) {
SharedPreferences mobile = context.getSharedPreferences("revanced_prefs", 0); try {
SharedPreferences.Editor mobileeditor = mobile.edit(); SharedPrefHelper.saveInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", defaultQuality);
mobileeditor.putInt("mobile_quality", defaultQuality); } catch (Exception ex) {
mobileeditor.apply(); LogHelper.debug(VideoQualityPatch.class, "Failed to change default mobile data quality" + ex);
LogHelper.debug(VideoQualityPatch.class, "Changing default mobile data quality to: " + defaultQuality); 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 { } 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; userChangedQuality = false;
} }
@ -81,12 +89,10 @@ public class VideoQualityPatch {
return quality; return quality;
} }
if (isConnectedWifi(context)) { if (isConnectedWifi(context)) {
SharedPreferences wifi = context.getSharedPreferences("revanced_prefs", 0); preferredQuality = SharedPrefHelper.getInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", -2);
preferredQuality = wifi.getInt("wifi_quality", -2);
LogHelper.debug(VideoQualityPatch.class, "Wi-Fi connection detected, preferred quality: " + preferredQuality); LogHelper.debug(VideoQualityPatch.class, "Wi-Fi connection detected, preferred quality: " + preferredQuality);
} else if (isConnectedMobile(context)) { } else if (isConnectedMobile(context)) {
SharedPreferences mobile = context.getSharedPreferences("revanced_prefs", 0); preferredQuality = SharedPrefHelper.getInt(context, SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", -2);
preferredQuality = mobile.getInt("mobile_quality", -2);
LogHelper.debug(VideoQualityPatch.class, "Mobile data connection detected, preferred quality: " + preferredQuality); LogHelper.debug(VideoQualityPatch.class, "Mobile data connection detected, preferred quality: " + preferredQuality);
} else { } else {
LogHelper.debug(VideoQualityPatch.class, "No Internet connection!"); LogHelper.debug(VideoQualityPatch.class, "No Internet connection!");
@ -119,6 +125,7 @@ public class VideoQualityPatch {
return qualityIndex; return qualityIndex;
} catch (Exception ex) { } catch (Exception ex) {
LogHelper.printException(VideoQualityPatch.class, "Failed to set quality", ex); LogHelper.printException(VideoQualityPatch.class, "Failed to set quality", ex);
Toast.makeText(context, "Failed to set quality", Toast.LENGTH_SHORT).show();
return qualityIndex; return qualityIndex;
} }
} }

View File

@ -68,7 +68,8 @@ public class SharedPrefHelper {
YOUTUBE("youtube"), YOUTUBE("youtube"),
RYD("ryd"), RYD("ryd"),
SPONSOR_BLOCK("sponsor-block"); SPONSOR_BLOCK("sponsor-block"),
REVANCED_PREFS("revanced_prefs");
private final String name; private final String name;