From 10d13b3133a18ab9d6603193aec1908c0f9fc4ac Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:25:18 +0400 Subject: [PATCH 1/5] feat(YouTube - Navigation buttons): Add options to enable/disable translucent status bar and navigation buttons --- .../patches/NavigationButtonsPatch.java | 22 +++++++++ .../extension/youtube/settings/Settings.java | 6 ++- .../layout/buttons/navigation/Fingerprints.kt | 28 +++++++++++ .../navigation/NavigationButtonsPatch.kt | 48 +++++++++++++++---- .../resources/addresources/values/strings.xml | 7 +++ 5 files changed, 100 insertions(+), 11 deletions(-) diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java index 8c581fc1c4..09d999eb07 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java @@ -3,6 +3,7 @@ import static app.revanced.extension.shared.Utils.hideViewUnderCondition; import static app.revanced.extension.youtube.shared.NavigationBar.NavigationButton; +import android.os.Build; import android.view.View; import java.util.EnumMap; @@ -26,6 +27,13 @@ public final class NavigationButtonsPatch { private static final boolean SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = Settings.SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON.get(); + private static final Boolean TRANSLUCENT_STATUS_BAR + = Settings.TRANSLUCENT_STATUS_BAR.get(); + + private static final Boolean TRANSLUCENT_NAVIGATION_BUTTONS + = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + && Settings.TRANSLUCENT_NAVIGATION_BUTTONS.get(); + /** * Injection point. */ @@ -48,4 +56,18 @@ public static void navigationTabCreated(NavigationButton button, View tabView) { public static void hideNavigationButtonLabels(TextView navigationLabelsView) { hideViewUnderCondition(Settings.HIDE_NAVIGATION_BUTTON_LABELS, navigationLabelsView); } + + /** + * Injection point. + */ + public static boolean useTranslucentNavigationStatusBar(boolean original) { + return TRANSLUCENT_STATUS_BAR; + } + + /** + * Injection point. + */ + public static boolean useTranslucentNavigationButtons(boolean original) { + return TRANSLUCENT_NAVIGATION_BUTTONS; + } } diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java index 950f34be4d..7809ebf91a 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -16,7 +16,6 @@ import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.MODERN_2; import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.MODERN_3; import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.MODERN_4; -import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.PHONE; import static app.revanced.extension.youtube.patches.SeekbarThumbnailsPatch.SeekbarThumbnailsHighQualityAvailability; import static app.revanced.extension.youtube.patches.VersionCheckPatch.IS_19_17_OR_GREATER; import static app.revanced.extension.youtube.sponsorblock.objects.CategoryBehaviour.IGNORE; @@ -217,6 +216,8 @@ public class Settings extends BaseSettings { public static final BooleanSetting HIDE_SUBSCRIPTIONS_BUTTON = new BooleanSetting("revanced_hide_subscriptions_button", FALSE, true); public static final BooleanSetting HIDE_NAVIGATION_BUTTON_LABELS = new BooleanSetting("revanced_hide_navigation_button_labels", FALSE, true); public static final BooleanSetting SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = new BooleanSetting("revanced_switch_create_with_notifications_button", TRUE, true); + public static final BooleanSetting TRANSLUCENT_STATUS_BAR = new BooleanSetting("revanced_translucent_status_bar", TRUE, true); + public static final BooleanSetting TRANSLUCENT_NAVIGATION_BUTTONS = new BooleanSetting("revanced_translucent_navigation_buttons", FALSE, true); // Shorts public static final BooleanSetting DISABLE_RESUMING_SHORTS_PLAYER = new BooleanSetting("revanced_disable_resuming_shorts_player", FALSE); @@ -388,7 +389,8 @@ public class Settings extends BaseSettings { } // Migrate renamed enum. - if (MINIPLAYER_TYPE.get() == PHONE) { + //noinspection deprecation + if (MINIPLAYER_TYPE.get() == MiniplayerType.PHONE) { MINIPLAYER_TYPE.save(MINIMAL); } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/Fingerprints.kt index eebd0befb9..a4e65eb28b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/Fingerprints.kt @@ -3,6 +3,7 @@ package app.revanced.patches.youtube.layout.buttons.navigation import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.AccessFlags import app.revanced.patcher.fingerprint +import app.revanced.util.literal internal const val ANDROID_AUTOMOTIVE_STRING = "Android Automotive" @@ -22,4 +23,31 @@ internal val createPivotBarFingerprint = fingerprint { Opcode.INVOKE_VIRTUAL, Opcode.RETURN_VOID, ) +} + +internal const val TRANSLUCENT_NAVIGATION_STATUS_BAR_FEATURE_FLAG = 45400535L + +internal val translucentNavigationStatusBarFeatureFlagFingerprint = fingerprint { + accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) + returns("Z") + literal { TRANSLUCENT_NAVIGATION_STATUS_BAR_FEATURE_FLAG } +} + +internal const val TRANSLUCENT_NAVIGATION_BUTTONS_FEATURE_FLAG = 45630927L + +internal val translucentNavigationButtonsFeatureFlagFingerprint = fingerprint { + accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) + returns("V") + literal { TRANSLUCENT_NAVIGATION_BUTTONS_FEATURE_FLAG } +} + +/** + * The device on screen back/home/recent buttons. + */ +internal const val TRANSLUCENT_NAVIGATION_BUTTONS_SYSTEM_FEATURE_FLAG = 45632194L + +internal val translucentNavigationButtonsSystemFeatureFlagFingerprint = fingerprint { + accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) + returns("Z") + literal { TRANSLUCENT_NAVIGATION_BUTTONS_SYSTEM_FEATURE_FLAG } } \ No newline at end of file diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt index 3fd159933c..ecaad3e1c5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt @@ -12,10 +12,13 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.navigation.hookNavigationButtonCreated import app.revanced.patches.youtube.misc.navigation.navigationBarHookPatch +import app.revanced.patches.youtube.misc.playservice.is_19_25_or_greater +import app.revanced.patches.youtube.misc.playservice.versionCheckPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.insertFeatureFlagBooleanOverride import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -32,6 +35,7 @@ val navigationButtonsPatch = bytecodePatch( settingsPatch, addResourcesPatch, navigationBarHookPatch, + versionCheckPatch ) compatibleWith( @@ -50,19 +54,26 @@ val navigationButtonsPatch = bytecodePatch( execute { addResources("youtube", "layout.buttons.navigation.navigationButtonsPatch") + val preferences = mutableSetOf( + SwitchPreference("revanced_hide_home_button"), + SwitchPreference("revanced_hide_shorts_button"), + SwitchPreference("revanced_hide_create_button"), + SwitchPreference("revanced_hide_subscriptions_button"), + SwitchPreference("revanced_switch_create_with_notifications_button"), + SwitchPreference("revanced_hide_navigation_button_labels"), + ) + + if (is_19_25_or_greater) { + preferences += SwitchPreference("revanced_translucent_status_bar") + preferences += SwitchPreference("revanced_translucent_navigation_buttons") + } + PreferenceScreen.GENERAL_LAYOUT.addPreferences( PreferenceScreenPreference( key = "revanced_navigation_buttons_screen", sorting = Sorting.UNSORTED, - preferences = setOf( - SwitchPreference("revanced_hide_home_button"), - SwitchPreference("revanced_hide_shorts_button"), - SwitchPreference("revanced_hide_create_button"), - SwitchPreference("revanced_hide_subscriptions_button"), - SwitchPreference("revanced_switch_create_with_notifications_button"), - SwitchPreference("revanced_hide_navigation_button_labels"), - ), - ), + preferences = preferences + ) ) // Switch create with notifications button. @@ -101,5 +112,24 @@ val navigationButtonsPatch = bytecodePatch( // Hook navigation button created, in order to hide them. hookNavigationButtonCreated(EXTENSION_CLASS_DESCRIPTOR) + + + // Force on/off translucent effect on status bar and navigation buttons. + if (is_19_25_or_greater) { + translucentNavigationStatusBarFeatureFlagFingerprint.method.insertFeatureFlagBooleanOverride( + TRANSLUCENT_NAVIGATION_STATUS_BAR_FEATURE_FLAG, + "$EXTENSION_CLASS_DESCRIPTOR->useTranslucentNavigationStatusBar(Z)Z", + ) + + translucentNavigationButtonsFeatureFlagFingerprint.method.insertFeatureFlagBooleanOverride( + TRANSLUCENT_NAVIGATION_BUTTONS_FEATURE_FLAG, + "$EXTENSION_CLASS_DESCRIPTOR->useTranslucentNavigationButtons(Z)Z", + ) + + translucentNavigationButtonsSystemFeatureFlagFingerprint.method.insertFeatureFlagBooleanOverride( + TRANSLUCENT_NAVIGATION_BUTTONS_SYSTEM_FEATURE_FLAG, + "$EXTENSION_CLASS_DESCRIPTOR->useTranslucentNavigationButtons(Z)Z", + ) + } } } diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index 56db255896..583df57229 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -522,6 +522,13 @@ Note: Enabling this also forcibly hides video ads" Hide navigation button labels Labels are hidden Labels are shown + Use translucent status bar + Status bar is translucent + Status bar is opaque + Use translucent buttons + "Buttons are translucent +(Requires Android 12)" + Buttons are opaque Flyout menu From dfcdb5029305d5dd0f56eea722e62e59e791791f Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:57:55 +0400 Subject: [PATCH 2/5] Adjust text --- patches/src/main/resources/addresources/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index 583df57229..2c348fa7a2 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -522,10 +522,10 @@ Note: Enabling this also forcibly hides video ads" Hide navigation button labels Labels are hidden Labels are shown - Use translucent status bar + Enable translucent status bar Status bar is translucent Status bar is opaque - Use translucent buttons + Enable translucent buttons "Buttons are translucent (Requires Android 12)" Buttons are opaque From b368bf708001ed6bcfc54eafce7d133e1dd22e32 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:53:19 +0400 Subject: [PATCH 3/5] fix: Can set navbar differently for light/dark mode --- .../patches/NavigationButtonsPatch.java | 21 +++++++++++++++---- .../extension/youtube/settings/Settings.java | 3 ++- .../navigation/NavigationButtonsPatch.kt | 3 ++- .../resources/addresources/values/strings.xml | 15 ++++++++----- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java index 09d999eb07..68358fe0d8 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java @@ -10,6 +10,8 @@ import java.util.Map; import android.widget.TextView; + +import app.revanced.extension.shared.Utils; import app.revanced.extension.youtube.settings.Settings; @SuppressWarnings("unused") @@ -28,11 +30,16 @@ public final class NavigationButtonsPatch { = Settings.SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON.get(); private static final Boolean TRANSLUCENT_STATUS_BAR - = Settings.TRANSLUCENT_STATUS_BAR.get(); + = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + && Settings.TRANSLUCENT_STATUS_BAR.get(); + + private static final Boolean TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT + = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + && Settings.TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT.get(); - private static final Boolean TRANSLUCENT_NAVIGATION_BUTTONS + private static final Boolean TRANSLUCENT_NAVIGATION_BUTTONS_DARK = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S - && Settings.TRANSLUCENT_NAVIGATION_BUTTONS.get(); + && Settings.TRANSLUCENT_NAVIGATION_BUTTONS_DARK.get(); /** * Injection point. @@ -68,6 +75,12 @@ public static boolean useTranslucentNavigationStatusBar(boolean original) { * Injection point. */ public static boolean useTranslucentNavigationButtons(boolean original) { - return TRANSLUCENT_NAVIGATION_BUTTONS; + if (!TRANSLUCENT_NAVIGATION_BUTTONS_DARK && !TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT) { + return false; + } + + return Utils.isDarkModeEnabled(Utils.getContext()) + ? TRANSLUCENT_NAVIGATION_BUTTONS_DARK + : TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT; } } diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java index 7809ebf91a..21a3f6f3a2 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -217,7 +217,8 @@ public class Settings extends BaseSettings { public static final BooleanSetting HIDE_NAVIGATION_BUTTON_LABELS = new BooleanSetting("revanced_hide_navigation_button_labels", FALSE, true); public static final BooleanSetting SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = new BooleanSetting("revanced_switch_create_with_notifications_button", TRUE, true); public static final BooleanSetting TRANSLUCENT_STATUS_BAR = new BooleanSetting("revanced_translucent_status_bar", TRUE, true); - public static final BooleanSetting TRANSLUCENT_NAVIGATION_BUTTONS = new BooleanSetting("revanced_translucent_navigation_buttons", FALSE, true); + public static final BooleanSetting TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT = new BooleanSetting("revanced_translucent_navigation_buttons_light", FALSE, true); + public static final BooleanSetting TRANSLUCENT_NAVIGATION_BUTTONS_DARK = new BooleanSetting("revanced_translucent_navigation_buttons_dark", FALSE, true); // Shorts public static final BooleanSetting DISABLE_RESUMING_SHORTS_PLAYER = new BooleanSetting("revanced_disable_resuming_shorts_player", FALSE); diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt index ecaad3e1c5..dcff113532 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt @@ -65,7 +65,8 @@ val navigationButtonsPatch = bytecodePatch( if (is_19_25_or_greater) { preferences += SwitchPreference("revanced_translucent_status_bar") - preferences += SwitchPreference("revanced_translucent_navigation_buttons") + preferences += SwitchPreference("revanced_translucent_navigation_buttons_light") + preferences += SwitchPreference("revanced_translucent_navigation_buttons_dark") } PreferenceScreen.GENERAL_LAYOUT.addPreferences( diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index 2c348fa7a2..9568bc1877 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -523,12 +523,17 @@ Note: Enabling this also forcibly hides video ads" Labels are hidden Labels are shown Enable translucent status bar - Status bar is translucent + "Status bar is translucent +(requires Android 12)" Status bar is opaque - Enable translucent buttons - "Buttons are translucent -(Requires Android 12)" - Buttons are opaque + Enable translucent light buttons + "Light mode buttons are translucent +(requires Android 12)" + Light mode buttons are opaque + Enable translucent dark buttons + "Dark mode buttons are translucent +(requires Android 12)" + Dark mode buttons are opaque Flyout menu From 4dbd450938498fc3684164b8742d35ef5478f53b Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:25:31 +0400 Subject: [PATCH 4/5] fix: Nav buttons only works with Android 13+ --- .../patches/NavigationButtonsPatch.java | 18 ++++++++++++------ .../resources/addresources/values/strings.xml | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java index 68358fe0d8..2d22b12a03 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java @@ -30,16 +30,13 @@ public final class NavigationButtonsPatch { = Settings.SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON.get(); private static final Boolean TRANSLUCENT_STATUS_BAR - = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S - && Settings.TRANSLUCENT_STATUS_BAR.get(); + = Settings.TRANSLUCENT_STATUS_BAR.get(); private static final Boolean TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT - = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S - && Settings.TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT.get(); + = Settings.TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT.get(); private static final Boolean TRANSLUCENT_NAVIGATION_BUTTONS_DARK - = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S - && Settings.TRANSLUCENT_NAVIGATION_BUTTONS_DARK.get(); + = Settings.TRANSLUCENT_NAVIGATION_BUTTONS_DARK.get(); /** * Injection point. @@ -68,6 +65,11 @@ public static void hideNavigationButtonLabels(TextView navigationLabelsView) { * Injection point. */ public static boolean useTranslucentNavigationStatusBar(boolean original) { + // Must check Android version, as forcing this on Android 11 or lower causes app hang and crash. + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + return original; + } + return TRANSLUCENT_STATUS_BAR; } @@ -75,6 +77,10 @@ public static boolean useTranslucentNavigationStatusBar(boolean original) { * Injection point. */ public static boolean useTranslucentNavigationButtons(boolean original) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + return original; + } + if (!TRANSLUCENT_NAVIGATION_BUTTONS_DARK && !TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT) { return false; } diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index 9568bc1877..cf5cd323a5 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -528,11 +528,11 @@ Note: Enabling this also forcibly hides video ads" Status bar is opaque Enable translucent light buttons "Light mode buttons are translucent -(requires Android 12)" +(requires Android 13)" Light mode buttons are opaque Enable translucent dark buttons "Dark mode buttons are translucent -(requires Android 12)" +(requires Android 13)" Dark mode buttons are opaque From fe03c7f003f0e7e6e5d5da2f5b47fd2ff907594b Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:05:04 +0400 Subject: [PATCH 5/5] refactor: change to 'disable' type --- .../patches/NavigationButtonsPatch.java | 29 ++++++++++++------- .../extension/youtube/settings/Settings.java | 6 ++-- .../navigation/NavigationButtonsPatch.kt | 6 ++-- .../resources/addresources/values/strings.xml | 21 ++++++-------- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java index 2d22b12a03..3494ada584 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/NavigationButtonsPatch.java @@ -29,14 +29,14 @@ public final class NavigationButtonsPatch { private static final boolean SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = Settings.SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON.get(); - private static final Boolean TRANSLUCENT_STATUS_BAR - = Settings.TRANSLUCENT_STATUS_BAR.get(); + private static final Boolean DISABLE_TRANSLUCENT_STATUS_BAR + = Settings.DISABLE_TRANSLUCENT_STATUS_BAR.get(); - private static final Boolean TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT - = Settings.TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT.get(); + private static final Boolean DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT + = Settings.DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT.get(); - private static final Boolean TRANSLUCENT_NAVIGATION_BUTTONS_DARK - = Settings.TRANSLUCENT_NAVIGATION_BUTTONS_DARK.get(); + private static final Boolean DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK + = Settings.DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK.get(); /** * Injection point. @@ -70,23 +70,32 @@ public static boolean useTranslucentNavigationStatusBar(boolean original) { return original; } - return TRANSLUCENT_STATUS_BAR; + if (DISABLE_TRANSLUCENT_STATUS_BAR) { + return false; + } + + return original; } /** * Injection point. */ public static boolean useTranslucentNavigationButtons(boolean original) { + // Feature requires Android 13+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { return original; } - if (!TRANSLUCENT_NAVIGATION_BUTTONS_DARK && !TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT) { + if (!DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK && !DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT) { + return original; + } + + if (DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK && DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT) { return false; } return Utils.isDarkModeEnabled(Utils.getContext()) - ? TRANSLUCENT_NAVIGATION_BUTTONS_DARK - : TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT; + ? !DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK + : !DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT; } } diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java index 21a3f6f3a2..a88711cf5b 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -216,9 +216,9 @@ public class Settings extends BaseSettings { public static final BooleanSetting HIDE_SUBSCRIPTIONS_BUTTON = new BooleanSetting("revanced_hide_subscriptions_button", FALSE, true); public static final BooleanSetting HIDE_NAVIGATION_BUTTON_LABELS = new BooleanSetting("revanced_hide_navigation_button_labels", FALSE, true); public static final BooleanSetting SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = new BooleanSetting("revanced_switch_create_with_notifications_button", TRUE, true); - public static final BooleanSetting TRANSLUCENT_STATUS_BAR = new BooleanSetting("revanced_translucent_status_bar", TRUE, true); - public static final BooleanSetting TRANSLUCENT_NAVIGATION_BUTTONS_LIGHT = new BooleanSetting("revanced_translucent_navigation_buttons_light", FALSE, true); - public static final BooleanSetting TRANSLUCENT_NAVIGATION_BUTTONS_DARK = new BooleanSetting("revanced_translucent_navigation_buttons_dark", FALSE, true); + public static final BooleanSetting DISABLE_TRANSLUCENT_STATUS_BAR = new BooleanSetting("revanced_disable_translucent_status_bar", FALSE, true); + public static final BooleanSetting DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT = new BooleanSetting("revanced_disable_translucent_navigation_bar_light", FALSE, true); + public static final BooleanSetting DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK = new BooleanSetting("revanced_disable_translucent_navigation_bar_dark", FALSE, true); // Shorts public static final BooleanSetting DISABLE_RESUMING_SHORTS_PLAYER = new BooleanSetting("revanced_disable_resuming_shorts_player", FALSE); diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt index dcff113532..33ce5e1908 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt @@ -64,9 +64,9 @@ val navigationButtonsPatch = bytecodePatch( ) if (is_19_25_or_greater) { - preferences += SwitchPreference("revanced_translucent_status_bar") - preferences += SwitchPreference("revanced_translucent_navigation_buttons_light") - preferences += SwitchPreference("revanced_translucent_navigation_buttons_dark") + preferences += SwitchPreference("revanced_disable_translucent_status_bar") + preferences += SwitchPreference("revanced_disable_translucent_navigation_bar_light") + preferences += SwitchPreference("revanced_disable_translucent_navigation_bar_dark") } PreferenceScreen.GENERAL_LAYOUT.addPreferences( diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index cf5cd323a5..2152769d6c 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -522,18 +522,15 @@ Note: Enabling this also forcibly hides video ads" Hide navigation button labels Labels are hidden Labels are shown - Enable translucent status bar - "Status bar is translucent -(requires Android 12)" - Status bar is opaque - Enable translucent light buttons - "Light mode buttons are translucent -(requires Android 13)" - Light mode buttons are opaque - Enable translucent dark buttons - "Dark mode buttons are translucent -(requires Android 13)" - Dark mode buttons are opaque + Disable translucent status bar + Status bar is opaque + Status bar is opaque or translucent + Disable light translucent bar + Light mode navigation bar is opaque + Light mode navigation bar is opaque or translucent + Disable dark translucent bar + Dark mode navigation bar is opaque + Dark mode navigation bar is opaque or translucent Flyout menu