feat(YouTube - Fullscreen components): Add Enter fullscreen mode setting

This commit is contained in:
inotia00
2025-01-03 21:54:27 +09:00
parent 428047b725
commit 1f95e07e7a
6 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,67 @@
package app.revanced.extension.youtube.patches.player;
import androidx.annotation.NonNull;
import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.shared.utils.Utils;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;
import app.revanced.extension.youtube.utils.VideoUtils;
@SuppressWarnings("unused")
public class EnterFullscreenPatch {
private static volatile boolean isForeground = true;
@NonNull
private static String videoId = "";
/**
* Injection point.
*/
public static void onAppBackgrounded() {
isForeground = false;
}
/**
* Injection point.
*/
public static void onAppForegrounded() {
isForeground = true;
}
/**
* Injection point.
*/
public static void enterFullscreen(@NonNull String newlyLoadedChannelId, @NonNull String newlyLoadedChannelName,
@NonNull String newlyLoadedVideoId, @NonNull String newlyLoadedVideoTitle,
final long newlyLoadedVideoLength, boolean newlyLoadedLiveStreamValue) {
try {
if (!Settings.ENTER_FULLSCREEN.get()) {
return;
}
PlayerType playerType = PlayerType.getCurrent();
// 1. The user opened the video while playing a video in the feed.
// 2. This is a valid request, so the videoId is not saved.
if (playerType == PlayerType.INLINE_MINIMAL) {
return;
}
if (videoId.equals(newlyLoadedVideoId)) {
return;
}
videoId = newlyLoadedVideoId;
// 1. User clicks home button in [PlayerType.WATCH_WHILE_MAXIMIZED], thus entering audio only mode.
// 2. PlayerType is still [PlayerType.WATCH_WHILE_MAXIMIZED].
// 3. Next video starts in audio only mode, then returns to foreground mode.
// 4. Enters fullscreen for a moment and then returns.
// We can prevent this by checking if the app is in the foreground.
if (playerType == PlayerType.WATCH_WHILE_MAXIMIZED && isForeground) {
// It works without delay, but in this case sometimes portrait videos have landscape orientation.
Utils.runOnMainThreadDelayed(VideoUtils::enterFullscreenMode, 250L);
}
} catch (Exception ex) {
Logger.printException(() -> "enterFullscreen failure", ex);
}
}
}

View File

@ -335,6 +335,7 @@ public class Settings extends BaseSettings {
// PreferenceScreen: Player - Fullscreen
public static final BooleanSetting DISABLE_ENGAGEMENT_PANEL = new BooleanSetting("revanced_disable_engagement_panel", FALSE, true);
public static final BooleanSetting ENTER_FULLSCREEN = new BooleanSetting("revanced_enter_fullscreen", FALSE);
public static final EnumSetting<FullscreenMode> EXIT_FULLSCREEN = new EnumSetting<>("revanced_exit_fullscreen", FullscreenMode.DISABLED);
public static final BooleanSetting SHOW_VIDEO_TITLE_SECTION = new BooleanSetting("revanced_show_video_title_section", TRUE, true, parent(DISABLE_ENGAGEMENT_PANEL));
public static final BooleanSetting HIDE_AUTOPLAY_PREVIEW = new BooleanSetting("revanced_hide_autoplay_preview", FALSE, true);