From 55089baf1fec965e554234d806b03445b8f27bc5 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:31:04 -0400 Subject: [PATCH] feat(YouTube): Merge multiple player overlay patches into `Hide player overlay buttons` (#722) --- .../integrations/shared/settings/Setting.java | 2 ++ .../patches/HideAutoplayButtonPatch.java | 16 ---------- .../patches/HideCaptionsButtonPatch.java | 13 -------- .../youtube/patches/HideCastButtonPatch.java | 14 --------- ...ava => HidePlayerOverlayButtonsPatch.java} | 31 +++++++++++++++++-- .../youtube/settings/Settings.java | 4 +++ 6 files changed, 34 insertions(+), 46 deletions(-) delete mode 100644 app/src/main/java/app/revanced/integrations/youtube/patches/HideAutoplayButtonPatch.java delete mode 100644 app/src/main/java/app/revanced/integrations/youtube/patches/HideCaptionsButtonPatch.java delete mode 100644 app/src/main/java/app/revanced/integrations/youtube/patches/HideCastButtonPatch.java rename app/src/main/java/app/revanced/integrations/youtube/patches/{HidePlayerButtonsPatch.java => HidePlayerOverlayButtonsPatch.java} (62%) diff --git a/app/src/main/java/app/revanced/integrations/shared/settings/Setting.java b/app/src/main/java/app/revanced/integrations/shared/settings/Setting.java index 499e4d0b..3dbaabe0 100644 --- a/app/src/main/java/app/revanced/integrations/shared/settings/Setting.java +++ b/app/src/main/java/app/revanced/integrations/shared/settings/Setting.java @@ -208,6 +208,8 @@ public abstract class Setting { * Migrate a setting value if the path is renamed but otherwise the old and new settings are identical. */ public static void migrateOldSettingToNew(@NonNull Setting oldSetting, @NonNull Setting newSetting) { + if (oldSetting == newSetting) throw new IllegalArgumentException(); + if (!oldSetting.isSetToDefault()) { Logger.printInfo(() -> "Migrating old setting value: " + oldSetting + " into replacement setting: " + newSetting); newSetting.save(oldSetting.value); diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/HideAutoplayButtonPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/HideAutoplayButtonPatch.java deleted file mode 100644 index d4619857..00000000 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/HideAutoplayButtonPatch.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.revanced.integrations.youtube.patches; - -import app.revanced.integrations.youtube.settings.Settings; - -@SuppressWarnings("unused") -public class HideAutoplayButtonPatch { - - private static final boolean HIDE_AUTOPLAY_BUTTON_ENABLED = Settings.HIDE_AUTOPLAY_BUTTON.get(); - - /** - * Injection point. - */ - public static boolean hideAutoPlayButton() { - return HIDE_AUTOPLAY_BUTTON_ENABLED; - } -} diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/HideCaptionsButtonPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/HideCaptionsButtonPatch.java deleted file mode 100644 index d6487b44..00000000 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/HideCaptionsButtonPatch.java +++ /dev/null @@ -1,13 +0,0 @@ -package app.revanced.integrations.youtube.patches; - -import android.widget.ImageView; - -import app.revanced.integrations.youtube.settings.Settings; - -@SuppressWarnings("unused") -public class HideCaptionsButtonPatch { - //Used by app.revanced.patches.youtube.layout.hidecaptionsbutton.patch.HideCaptionsButtonPatch - public static void hideCaptionsButton(ImageView imageView) { - imageView.setVisibility(Settings.HIDE_CAPTIONS_BUTTON.get() ? ImageView.GONE : ImageView.VISIBLE); - } -} diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/HideCastButtonPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/HideCastButtonPatch.java deleted file mode 100644 index aec2fbfc..00000000 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/HideCastButtonPatch.java +++ /dev/null @@ -1,14 +0,0 @@ -package app.revanced.integrations.youtube.patches; - -import android.view.View; - -import app.revanced.integrations.youtube.settings.Settings; - -@SuppressWarnings("unused") -public class HideCastButtonPatch { - - // Used by app.revanced.patches.youtube.layout.castbutton.patch.HideCastButonPatch - public static int getCastButtonOverrideV2(int original) { - return Settings.HIDE_CAST_BUTTON.get() ? View.GONE : original; - } -} diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/HidePlayerButtonsPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/HidePlayerOverlayButtonsPatch.java similarity index 62% rename from app/src/main/java/app/revanced/integrations/youtube/patches/HidePlayerButtonsPatch.java rename to app/src/main/java/app/revanced/integrations/youtube/patches/HidePlayerOverlayButtonsPatch.java index bc876cc3..b0cb40b6 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/HidePlayerButtonsPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/HidePlayerOverlayButtonsPatch.java @@ -1,15 +1,40 @@ package app.revanced.integrations.youtube.patches; import android.view.View; +import android.widget.ImageView; import app.revanced.integrations.shared.Logger; import app.revanced.integrations.shared.Utils; import app.revanced.integrations.youtube.settings.Settings; @SuppressWarnings("unused") -public final class HidePlayerButtonsPatch { +public final class HidePlayerOverlayButtonsPatch { - private static final boolean HIDE_PLAYER_BUTTONS_ENABLED = Settings.HIDE_PLAYER_BUTTONS.get(); + private static final boolean HIDE_AUTOPLAY_BUTTON_ENABLED = Settings.HIDE_AUTOPLAY_BUTTON.get(); + + /** + * Injection point. + */ + public static boolean hideAutoPlayButton() { + return HIDE_AUTOPLAY_BUTTON_ENABLED; + } + + /** + * Injection point. + */ + public static int getCastButtonOverrideV2(int original) { + return Settings.HIDE_CAST_BUTTON.get() ? View.GONE : original; + } + + /** + * Injection point. + */ + public static void hideCaptionsButton(ImageView imageView) { + imageView.setVisibility(Settings.HIDE_CAPTIONS_BUTTON.get() ? ImageView.GONE : ImageView.VISIBLE); + } + + private static final boolean HIDE_PLAYER_PREVIOUS_NEXT_BUTTONS_ENABLED + = Settings.HIDE_PLAYER_PREVIOUS_NEXT_BUTTONS.get(); private static final int PLAYER_CONTROL_PREVIOUS_BUTTON_TOUCH_AREA_ID = Utils.getResourceIdentifier("player_control_previous_button_touch_area", "id"); @@ -21,7 +46,7 @@ public final class HidePlayerButtonsPatch { * Injection point. */ public static void hidePreviousNextButtons(View parentView) { - if (!HIDE_PLAYER_BUTTONS_ENABLED) { + if (!HIDE_PLAYER_PREVIOUS_NEXT_BUTTONS_ENABLED) { return; } diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java index e02f4820..1b3147f2 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java @@ -131,6 +131,8 @@ public class Settings extends BaseSettings { public static final BooleanSetting DISABLE_LIKE_SUBSCRIBE_GLOW = new BooleanSetting("revanced_disable_like_subscribe_glow", FALSE); public static final BooleanSetting HIDE_AUTOPLAY_BUTTON = new BooleanSetting("revanced_hide_autoplay_button", TRUE, true); public static final BooleanSetting HIDE_CAST_BUTTON = new BooleanSetting("revanced_hide_cast_button", TRUE, true); + public static final BooleanSetting HIDE_PLAYER_PREVIOUS_NEXT_BUTTONS = new BooleanSetting("revanced_hide_player_previous_next_buttons", FALSE, true); + @Deprecated public static final BooleanSetting HIDE_PLAYER_BUTTONS = new BooleanSetting("revanced_hide_player_buttons", FALSE, true); public static final BooleanSetting COPY_VIDEO_URL = new BooleanSetting("revanced_copy_video_url", FALSE); public static final BooleanSetting COPY_VIDEO_URL_TIMESTAMP = new BooleanSetting("revanced_copy_video_url_timestamp", TRUE); @@ -438,6 +440,8 @@ public class Settings extends BaseSettings { migrateOldSettingToNew(HIDE_LOAD_MORE_BUTTON, HIDE_SHOW_MORE_BUTTON); + migrateOldSettingToNew(HIDE_PLAYER_BUTTONS, HIDE_PLAYER_PREVIOUS_NEXT_BUTTONS); + // endregion } }