Skip to content

Commit

Permalink
feat(YouTube - Fullscreen components): Remove Force fullscreen sett…
Browse files Browse the repository at this point in the history
…ing, add `Enter fullscreen mode` and `Exit fullscreen mode` settings
  • Loading branch information
inotia00 authored and anddea committed Jan 5, 2025
1 parent 868db78 commit 155f223
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 134 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package app.revanced.extension.youtube.patches.player;

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 ExitFullscreenPatch {

public enum FullscreenMode {
DISABLED,
PORTRAIT,
LANDSCAPE,
PORTRAIT_LANDSCAPE,
}

/**
* Injection point.
*/
public static void endOfVideoReached() {
try {
FullscreenMode mode = Settings.EXIT_FULLSCREEN.get();
if (mode == FullscreenMode.DISABLED) {
return;
}

if (PlayerType.getCurrent() == PlayerType.WATCH_WHILE_FULLSCREEN) {
if (mode != FullscreenMode.PORTRAIT_LANDSCAPE) {
if (Utils.isLandscapeOrientation()) {
if (mode == FullscreenMode.PORTRAIT) {
return;
}
} else if (mode == FullscreenMode.LANDSCAPE) {
return;
}
}

Utils.runOnMainThread(VideoUtils::exitFullscreenMode);
}
} catch (Exception ex) {
Logger.printException(() -> "endOfVideoReached failure", ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import static app.revanced.extension.shared.utils.Utils.hideViewUnderCondition;
import static app.revanced.extension.youtube.utils.ExtendedUtils.validateValue;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;
Expand All @@ -20,7 +18,6 @@
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import java.lang.ref.WeakReference;
import java.util.Objects;

import app.revanced.extension.shared.settings.BaseSettings;
Expand Down Expand Up @@ -328,37 +325,6 @@ public static void setScreenOn() {
Utils.runOnMainThreadDelayed(() -> isScreenOn = false, Settings.KEEP_LANDSCAPE_MODE_TIMEOUT.get());
}

private static WeakReference<Activity> watchDescriptorActivityRef = new WeakReference<>(null);
private static volatile boolean isLandScapeVideo = true;

public static void setWatchDescriptorActivity(Activity activity) {
watchDescriptorActivityRef = new WeakReference<>(activity);
}

public static boolean forceFullscreen(boolean original) {
if (!Settings.FORCE_FULLSCREEN.get())
return original;

Utils.runOnMainThreadDelayed(PlayerPatch::setOrientation, 1000);
return true;
}

private static void setOrientation() {
final Activity watchDescriptorActivity = watchDescriptorActivityRef.get();
final int requestedOrientation = isLandScapeVideo
? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
: watchDescriptorActivity.getRequestedOrientation();

watchDescriptorActivity.setRequestedOrientation(requestedOrientation);
}

public static void setVideoPortrait(int width, int height) {
if (!Settings.FORCE_FULLSCREEN.get())
return;

isLandScapeVideo = width > height;
}

// endregion

// region [Hide comments component] patch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import app.revanced.extension.youtube.patches.general.MiniplayerPatch;
import app.revanced.extension.youtube.patches.general.YouTubeMusicActionsPatch;
import app.revanced.extension.youtube.patches.misc.WatchHistoryPatch.WatchHistoryType;
import app.revanced.extension.youtube.patches.player.ExitFullscreenPatch.FullscreenMode;
import app.revanced.extension.youtube.patches.shorts.AnimationFeedbackPatch.AnimationType;
import app.revanced.extension.youtube.patches.shorts.ShortsRepeatStatePatch.ShortsLoopBehavior;
import app.revanced.extension.youtube.patches.utils.PatchStatus;
Expand Down Expand Up @@ -339,6 +340,8 @@ 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);
public static final BooleanSetting HIDE_LIVE_CHAT_REPLAY_BUTTON = new BooleanSetting("revanced_hide_live_chat_replay_button", FALSE);
Expand All @@ -358,7 +361,6 @@ public class Settings extends BaseSettings {

public static final BooleanSetting DISABLE_LANDSCAPE_MODE = new BooleanSetting("revanced_disable_landscape_mode", FALSE, true);
public static final BooleanSetting ENABLE_COMPACT_CONTROLS_OVERLAY = new BooleanSetting("revanced_enable_compact_controls_overlay", FALSE, true);
public static final BooleanSetting FORCE_FULLSCREEN = new BooleanSetting("revanced_force_fullscreen", FALSE, true);
public static final BooleanSetting KEEP_LANDSCAPE_MODE = new BooleanSetting("revanced_keep_landscape_mode", FALSE, true);
public static final LongSetting KEEP_LANDSCAPE_MODE_TIMEOUT = new LongSetting("revanced_keep_landscape_mode_timeout", 3000L, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public static void initializeReVancedSettings() {
ChangeHeaderPreferenceLinks();
ExternalDownloaderPreferenceLinks();
FullScreenPanelPreferenceLinks();
LayoutOverrideLinks();
MiniPlayerPreferenceLinks();
NavigationPreferenceLinks();
RYDPreferenceLinks();
Expand Down Expand Up @@ -93,16 +92,6 @@ private static void ExternalDownloaderPreferenceLinks() {
);
}

/**
* Enable/Disable Layout Override Preference
*/
private static void LayoutOverrideLinks() {
enableDisablePreferences(
ExtendedUtils.isTablet(),
Settings.FORCE_FULLSCREEN
);
}

/**
* Enable/Disable Preferences not working in tablet layout
*/
Expand Down Expand Up @@ -139,17 +128,6 @@ private static void FullScreenPanelPreferenceLinks() {
Settings.HIDE_QUICK_ACTIONS_SAVE_TO_PLAYLIST_BUTTON,
Settings.HIDE_QUICK_ACTIONS_SHARE_BUTTON
);

enableDisablePreferences(
Settings.DISABLE_LANDSCAPE_MODE.get(),
Settings.FORCE_FULLSCREEN
);

enableDisablePreferences(
Settings.FORCE_FULLSCREEN.get(),
Settings.DISABLE_LANDSCAPE_MODE
);

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ public static boolean getExternalDownloaderLaunchedState(boolean original) {
return !isExternalDownloaderLaunched.get() && original;
}

/**
* Rest of the implementation added by patch.
*/
public static void enterFullscreenMode() {
Logger.printDebug(() -> "Enter fullscreen mode");
}

/**
* Rest of the implementation added by patch.
*/
public static void exitFullscreenMode() {
Logger.printDebug(() -> "Exit fullscreen mode");
}

/**
* Rest of the implementation added by patch.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ lateinit var onConfigurationChangedMethod: MutableMethod
private set
lateinit var onCreateMethod: MutableMethod
private set
lateinit var onStartMethod: MutableMethod
private set
lateinit var onStopMethod: MutableMethod
private set

private lateinit var constructorMethod: MutableMethod
private lateinit var onBackPressedMethod: MutableMethod
Expand Down Expand Up @@ -45,6 +49,9 @@ fun baseMainActivityResolvePatch(

// set onConfigurationChanged method
onConfigurationChangedMethod = getMainActivityMethod("onConfigurationChanged")

onStartMethod = getMainActivityMethod("onStart")
onStopMethod = getMainActivityMethod("onStop")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ internal val broadcastReceiverFingerprint = legacyFingerprint(
}
)

internal val clientSettingEndpointFingerprint = legacyFingerprint(
name = "clientSettingEndpointFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "Ljava/util/Map;"),
strings = listOf(
"OVERRIDE_EXIT_FULLSCREEN_TO_MAXIMIZED",
"force_fullscreen",
"start_watch_minimized",
"watch"
)
)

internal val engagementPanelFingerprint = legacyFingerprint(
name = "engagementPanelFingerprint",
returnType = "L",
Expand Down Expand Up @@ -72,10 +59,3 @@ internal val relatedEndScreenResultsFingerprint = legacyFingerprint(
literals = listOf(appRelatedEndScreenResults),
)

internal val videoPortraitParentFingerprint = legacyFingerprint(
name = "videoPortraitParentFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "Ljava/util/Map;"),
strings = listOf("Acquiring NetLatencyActionLogger failed. taskId=")
)
Loading

0 comments on commit 155f223

Please sign in to comment.