-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube - Fullscreen components): Remove
Force fullscreen
sett…
…ing, add `Enter fullscreen mode` and `Exit fullscreen mode` settings
- Loading branch information
Showing
13 changed files
with
367 additions
and
134 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...red/src/main/java/app/revanced/extension/youtube/patches/player/EnterFullscreenPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...ared/src/main/java/app/revanced/extension/youtube/patches/player/ExitFullscreenPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.