fix(YouTube - Settings): Add a listener only if edge-to-edge display is supported

This commit is contained in:
inotia00 2025-03-24 20:36:32 +09:00
parent 84b122f628
commit 872db64da1
2 changed files with 27 additions and 4 deletions

View File

@ -30,9 +30,9 @@ public class PackageUtils extends Utils {
}
public static boolean isPackageEnabled(@NonNull String packageName) {
try {
return getContext().getPackageManager().getApplicationInfo(packageName, 0).enabled;
} catch (PackageManager.NameNotFoundException ignored) {
ApplicationInfo applicationInfo = getApplicationInfo(packageName);
if (applicationInfo != null) {
return applicationInfo.enabled;
}
return false;
@ -47,6 +47,26 @@ public class PackageUtils extends Utils {
}
// utils
@Nullable
public static Integer getTargetSDKVersion(@NonNull String packageName) {
ApplicationInfo applicationInfo = getApplicationInfo(packageName);
if (applicationInfo != null) {
return applicationInfo.targetSdkVersion;
}
return null;
}
@Nullable
private static ApplicationInfo getApplicationInfo(@NonNull String packageName) {
try {
return getContext().getPackageManager().getApplicationInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
Logger.printException(() -> "Failed to get application Info!" + e);
}
return null;
}
@Nullable
private static PackageInfo getPackageInfo() {
try {

View File

@ -197,6 +197,9 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {
}
}
Integer targetSDKVersion = ExtendedUtils.getTargetSDKVersion(getContext().getPackageName());
boolean isEdgeToEdgeSupported = isSDKAbove(35) && targetSDKVersion != null && targetSDKVersion >= 35;
for (PreferenceScreen mPreferenceScreen : preferenceScreenMap.values()) {
mPreferenceScreen.setOnPreferenceClickListener(
preferenceScreen -> {
@ -218,7 +221,7 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {
//
// Since ReVanced Settings Activity do not use AndroidX libraries,
// You will need to manually fix the layout breakage caused by edge-to-edge.
if (isSDKAbove(35)) {
if (isEdgeToEdgeSupported) {
rootView.setOnApplyWindowInsetsListener((v, insets) -> {
Insets statusInsets = insets.getInsets(WindowInsets.Type.statusBars());
Insets navInsets = insets.getInsets(WindowInsets.Type.navigationBars());