generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Add
Exit fullscreen mode
patch
- Loading branch information
1 parent
85e8b27
commit fa8f514
Showing
11 changed files
with
174 additions
and
8 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
...ons/youtube/src/main/java/app/revanced/extension/youtube/patches/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,53 @@ | ||
package app.revanced.extension.youtube.patches; | ||
|
||
import android.widget.ImageView; | ||
|
||
import app.revanced.extension.shared.Logger; | ||
import app.revanced.extension.shared.Utils; | ||
import app.revanced.extension.youtube.settings.Settings; | ||
import app.revanced.extension.youtube.shared.PlayerType; | ||
import app.revanced.extension.youtube.shared.VideoState; | ||
|
||
@SuppressWarnings("unused") | ||
public class ExitFullscreenPatch { | ||
|
||
public enum FullscreenMode { | ||
DISABLED, | ||
PORTRAIT, | ||
LANDSCAPE, | ||
PORTRAIT_LANDSCAPE, | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static void setVideoTime(long millis) { | ||
try { | ||
FullscreenMode mode = Settings.EXIT_FULLSCREEN.get(); | ||
if (mode == FullscreenMode.DISABLED) { | ||
return; | ||
} | ||
|
||
if (Utils.isLandscapeOrientation()) { | ||
if (mode == FullscreenMode.PORTRAIT) { | ||
return; | ||
} | ||
} else if (mode == FullscreenMode.LANDSCAPE) { | ||
return; | ||
} | ||
|
||
if (PlayerType.getCurrent() == PlayerType.WATCH_WHILE_FULLSCREEN | ||
&& VideoState.getCurrent() == VideoState.PLAYING | ||
&& VideoInformation.isAtEndOfVideo()) { | ||
ImageView fullscreenButton = PlayerControlsPatch.fullscreenButtonRef.get(); | ||
|
||
if (fullscreenButton != null) { | ||
Logger.printDebug(() -> "Clicking fullscreen button"); | ||
fullscreenButton.performClick(); | ||
} | ||
} | ||
} catch (Exception ex) { | ||
Logger.printException(() -> "setVideoTime 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
50 changes: 50 additions & 0 deletions
50
.../main/kotlin/app/revanced/patches/youtube/layout/player/fullscreen/ExitFullscreenPatch.kt
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,50 @@ | ||
package app.revanced.patches.youtube.layout.player.fullscreen | ||
|
||
import app.revanced.patcher.patch.bytecodePatch | ||
import app.revanced.patches.all.misc.resources.addResources | ||
import app.revanced.patches.all.misc.resources.addResourcesPatch | ||
import app.revanced.patches.shared.misc.settings.preference.ListPreference | ||
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch | ||
import app.revanced.patches.youtube.misc.playercontrols.playerControlsPatch | ||
import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch | ||
import app.revanced.patches.youtube.misc.settings.PreferenceScreen | ||
import app.revanced.patches.youtube.misc.settings.settingsPatch | ||
import app.revanced.patches.youtube.video.information.videoInformationPatch | ||
import app.revanced.patches.youtube.video.information.videoTimeHook | ||
|
||
@Suppress("unused") | ||
internal val exitFullscreenPatch = bytecodePatch( | ||
name = "Exit fullscreen mode", | ||
description = "Adds options to automatically exit fullscreen mode when a video reaches the end." | ||
) { | ||
dependsOn( | ||
sharedExtensionPatch, | ||
settingsPatch, | ||
addResourcesPatch, | ||
videoInformationPatch, | ||
playerTypeHookPatch, | ||
playerControlsPatch | ||
) | ||
|
||
// Cannot declare as top level since this patch is in the same package as | ||
// other patches that declare same constant name with internal visibility. | ||
@Suppress("LocalVariableName") | ||
val EXTENSION_CLASS_DESCRIPTOR = | ||
"Lapp/revanced/extension/youtube/patches/ExitFullscreenPatch;" | ||
|
||
execute { | ||
addResources("youtube", "layout.player.fullscreen.exitFullscreenPatch") | ||
|
||
PreferenceScreen.PLAYER.addPreferences( | ||
ListPreference( | ||
"revanced_exit_fullscreen", | ||
summaryKey = null, | ||
) | ||
) | ||
|
||
videoTimeHook( | ||
EXTENSION_CLASS_DESCRIPTOR, | ||
"setVideoTime", | ||
) | ||
} | ||
} |
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