Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
refactor: Use switch instead of list preference
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Oct 20, 2024
1 parent 432f04f commit fc75465
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ShortsLoopBehavior> CHANGE_SHORTS_REPEAT_STATE = new EnumSetting<>("revanced_shorts_repeat_behavior", REPEAT);
public static final EnumSetting<ShortsLoopBehavior> 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);
Expand Down

0 comments on commit fc75465

Please sign in to comment.