generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 314
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 (#4223)
- Loading branch information
1 parent
119092f
commit bb5d03b
Showing
16 changed files
with
189 additions
and
25 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
49 changes: 49 additions & 0 deletions
49
...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,49 @@ | ||
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; | ||
|
||
@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 (Utils.isLandscapeOrientation()) { | ||
if (mode == FullscreenMode.PORTRAIT) { | ||
return; | ||
} | ||
} else if (mode == FullscreenMode.LANDSCAPE) { | ||
return; | ||
} | ||
|
||
ImageView fullscreenButton = PlayerControlsPatch.fullscreenButtonRef.get(); | ||
if (fullscreenButton != null) { | ||
Logger.printDebug(() -> "Clicking fullscreen button"); | ||
fullscreenButton.performClick(); | ||
} | ||
} | ||
} 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
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
65 changes: 65 additions & 0 deletions
65
.../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,65 @@ | ||
package app.revanced.patches.youtube.layout.player.fullscreen | ||
|
||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
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.shared.autoRepeatFingerprint | ||
import app.revanced.patches.youtube.shared.autoRepeatParentFingerprint | ||
|
||
@Suppress("unused") | ||
internal val exitFullscreenPatch = bytecodePatch( | ||
name = "Exit fullscreen mode", | ||
description = "Adds options to automatically exit fullscreen mode when a video reaches the end." | ||
) { | ||
|
||
compatibleWith( | ||
"com.google.android.youtube"( | ||
"18.38.44", | ||
"18.49.37", | ||
"19.16.39", | ||
"19.25.37", | ||
"19.34.42", | ||
"19.43.41", | ||
"19.45.38", | ||
"19.46.42", | ||
"19.47.53", | ||
) | ||
) | ||
|
||
dependsOn( | ||
sharedExtensionPatch, | ||
settingsPatch, | ||
addResourcesPatch, | ||
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, | ||
) | ||
) | ||
|
||
autoRepeatFingerprint.match(autoRepeatParentFingerprint.originalClassDef).method.addInstruction( | ||
0, | ||
"invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->endOfVideoReached()V", | ||
) | ||
} | ||
} |
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