From fc754657eb19c437ce596a9bdc05dc2d26ba531c Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:27:09 -0400 Subject: [PATCH] refactor: Use switch instead of list preference --- ...eatPatch.java => ShortsAutoplayPatch.java} | 35 +++++++++++-------- .../youtube/settings/Settings.java | 6 ++-- 2 files changed, 22 insertions(+), 19 deletions(-) rename app/src/main/java/app/revanced/integrations/youtube/patches/{ChangeShortsRepeatPatch.java => ShortsAutoplayPatch.java} (80%) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/ChangeShortsRepeatPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/ShortsAutoplayPatch.java similarity index 80% rename from app/src/main/java/app/revanced/integrations/youtube/patches/ChangeShortsRepeatPatch.java rename to app/src/main/java/app/revanced/integrations/youtube/patches/ShortsAutoplayPatch.java index b4306587e3..953ff9df86 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/ChangeShortsRepeatPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/ShortsAutoplayPatch.java @@ -12,9 +12,9 @@ import app.revanced.integrations.youtube.settings.Settings; @SuppressWarnings("unused") -public class ChangeShortsRepeatPatch { +public class ShortsAutoplayPatch { - public enum ShortsLoopBehavior { + private enum ShortsLoopBehavior { UNKNOWN, /** * Repeat the same Short forever! @@ -95,23 +95,28 @@ public static void setYTShortsRepeatEnum(Enum ytEnum) { @RequiresApi(api = Build.VERSION_CODES.N) public static Enum changeShortsRepeatBehavior(Enum original) { try { - // 19.34+ is required to set background play behavior. - final boolean inPiPModeAndCanChangeBehavior = - VersionCheckPatch.IS_19_34_OR_GREATER && isAppInBackgroundPiPMode(); - - ShortsLoopBehavior behavior = inPiPModeAndCanChangeBehavior - ? Settings.CHANGE_SHORTS_BACKGROUND_REPEAT_STATE.get() - : Settings.CHANGE_SHORTS_REPEAT_STATE.get(); - - if (behavior == ShortsLoopBehavior.UNKNOWN) { - Logger.printDebug(() -> "Behavior setting is default. " - + "Using original: " + original.name()); - return original; + final boolean autoplay; + + if (isAppInBackgroundPiPMode()) { + if (!VersionCheckPatch.IS_19_34_OR_GREATER) { + // 19.34+ is required to set background play behavior. + Logger.printDebug(() -> "PiP Shorts not supported, using original repeat behavior"); + + return original; + } + + autoplay = Settings.SHORTS_AUTOPLAY_BACKGROUND.get(); + } else { + autoplay = Settings.SHORTS_AUTOPLAY.get(); } + final ShortsLoopBehavior behavior = autoplay + ? ShortsLoopBehavior.SINGLE_PLAY + : ShortsLoopBehavior.REPEAT; + if (behavior.ytEnumValue != null) { Logger.printDebug(() -> behavior.ytEnumValue == original - ? "Changing Shorts repeat behavior from: " + original.name() + " to: " + behavior.name() + ? "Changing Shorts repeat behavior from: " + original.name() + " to: " + behavior.ytEnumValue : "Behavior setting is same as original. Using original: " + original.name() ); 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 8216cbf6db..e02f482033 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 @@ -8,8 +8,6 @@ import static app.revanced.integrations.youtube.patches.MiniplayerPatch.MiniplayerType; import static app.revanced.integrations.youtube.patches.MiniplayerPatch.MiniplayerType.*; import static app.revanced.integrations.youtube.sponsorblock.objects.CategoryBehaviour.*; -import static app.revanced.integrations.youtube.patches.ChangeShortsRepeatPatch.ShortsLoopBehavior; -import static app.revanced.integrations.youtube.patches.ChangeShortsRepeatPatch.ShortsLoopBehavior.*; import java.util.Arrays; import java.util.HashSet; @@ -249,8 +247,8 @@ public class Settings extends BaseSettings { public static final BooleanSetting HIDE_SHORTS_SOUND_METADATA_LABEL = new BooleanSetting("revanced_hide_shorts_sound_metadata_label", FALSE); public static final BooleanSetting HIDE_SHORTS_FULL_VIDEO_LINK_LABEL = new BooleanSetting("revanced_hide_shorts_full_video_link_label", FALSE); public static final BooleanSetting HIDE_SHORTS_NAVIGATION_BAR = new BooleanSetting("revanced_hide_shorts_navigation_bar", FALSE, true); - public static final EnumSetting CHANGE_SHORTS_REPEAT_STATE = new EnumSetting<>("revanced_shorts_repeat_behavior", REPEAT); - public static final EnumSetting CHANGE_SHORTS_BACKGROUND_REPEAT_STATE = new EnumSetting<>("revanced_shorts_background_repeat_behavior", SINGLE_PLAY); + public static final BooleanSetting SHORTS_AUTOPLAY = new BooleanSetting("revanced_shorts_autoplay", FALSE); + public static final BooleanSetting SHORTS_AUTOPLAY_BACKGROUND = new BooleanSetting("revanced_shorts_autoplay_background", TRUE); // Seekbar public static final BooleanSetting DISABLE_PRECISE_SEEKING_GESTURE = new BooleanSetting("revanced_disable_precise_seeking_gesture", TRUE);