diff --git a/api/revanced-patches.api b/api/revanced-patches.api index ac962636..75d89226 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1840,6 +1840,12 @@ public final class app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch : public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + public final class app/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt index 24444979..7cdb7d06 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt @@ -4,13 +4,19 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.video.speed.button.PlaybackSpeedButtonPatch import app.revanced.patches.youtube.video.speed.custom.CustomPlaybackSpeedPatch import app.revanced.patches.youtube.video.speed.remember.RememberPlaybackSpeedPatch @Patch( name = "Playback speed", - description = "Adds options to customize available playback speeds and to remember the last playback speed selected.", - dependencies = [CustomPlaybackSpeedPatch::class, RememberPlaybackSpeedPatch::class], + description = "Adds options to customize available playback speeds, remember the last playback speed selected " + + "and show a speed dialog button to the video player.", + dependencies = [ + PlaybackSpeedButtonPatch::class, + CustomPlaybackSpeedPatch::class, + RememberPlaybackSpeedPatch::class, + ], compatiblePackages = [ CompatiblePackage( "com.google.android.youtube", @@ -42,4 +48,4 @@ object PlaybackSpeedPatch : BytecodePatch(emptySet()) { override fun execute(context: BytecodeContext) { // All patches this patch depends on succeed. } -} +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch.kt new file mode 100644 index 00000000..19895fa8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.youtube.video.speed.button + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.all.misc.resources.AddResourcesPatch +import app.revanced.patches.shared.misc.settings.preference.SwitchPreference +import app.revanced.patches.youtube.misc.playercontrols.PlayerControlsBytecodePatch +import app.revanced.patches.youtube.misc.settings.SettingsPatch +import app.revanced.patches.youtube.video.speed.custom.CustomPlaybackSpeedPatch + +@Patch( + description = "Adds the option to display playback speed dialog button in the video player.", + dependencies = [ + PlaybackSpeedButtonResourcePatch::class, + CustomPlaybackSpeedPatch::class, + PlayerControlsBytecodePatch::class, + SettingsPatch::class, + AddResourcesPatch::class, + ], +) +@Suppress("unused") +object PlaybackSpeedButtonPatch : BytecodePatch(emptySet()) { + private const val SPEED_BUTTON_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/youtube/videoplayer/PlaybackSpeedDialogButton;" + + override fun execute(context: BytecodeContext) { + + AddResourcesPatch(this::class) + + SettingsPatch.PreferenceScreen.PLAYER.addPreferences( + SwitchPreference("revanced_playback_speed_dialog_button"), + ) + + PlayerControlsBytecodePatch.initializeControl("$SPEED_BUTTON_CLASS_DESCRIPTOR->initializeButton(Landroid/view/View;)V") + PlayerControlsBytecodePatch.injectVisibilityCheckCall("$SPEED_BUTTON_CLASS_DESCRIPTOR->changeVisibility(Z)V") + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonResourcePatch.kt new file mode 100644 index 00000000..ffc8d8f1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonResourcePatch.kt @@ -0,0 +1,25 @@ +package app.revanced.patches.youtube.video.speed.button + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.misc.playercontrols.BottomControlsResourcePatch +import app.revanced.util.ResourceGroup +import app.revanced.util.copyResources + +@Patch( + dependencies = [BottomControlsResourcePatch::class], +) +internal object PlaybackSpeedButtonResourcePatch : ResourcePatch() { + override fun execute(context: ResourceContext) { + context.copyResources( + "speedbutton", + ResourceGroup( + "drawable", + "revanced_playback_speed_dialog_button.xml", + ), + ) + + BottomControlsResourcePatch.addControls("speedbutton") + } +} diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index 34b2a380..dc0f814e 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -1065,6 +1065,11 @@ wifi Changed default %1$s quality to: %2$s + + Show speed dialog button + Button is shown + Button is not shown + Custom playback speeds Add or change the available playback speeds diff --git a/src/main/resources/speedbutton/drawable/revanced_playback_speed_dialog_button.xml b/src/main/resources/speedbutton/drawable/revanced_playback_speed_dialog_button.xml new file mode 100644 index 00000000..b42dd57f --- /dev/null +++ b/src/main/resources/speedbutton/drawable/revanced_playback_speed_dialog_button.xml @@ -0,0 +1,30 @@ + + + + + diff --git a/src/main/resources/speedbutton/host/layout/youtube_controls_bottom_ui_container.xml b/src/main/resources/speedbutton/host/layout/youtube_controls_bottom_ui_container.xml new file mode 100644 index 00000000..ddd8a125 --- /dev/null +++ b/src/main/resources/speedbutton/host/layout/youtube_controls_bottom_ui_container.xml @@ -0,0 +1,4 @@ + + + +