feat(YouTube - Playback speed): Add option to show speed dialog button in video player (#3197)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
MarcaD 2024-06-02 18:48:35 +03:00 committed by GitHub
parent 8f2359febc
commit ad00305ff5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 117 additions and 3 deletions

View file

@ -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

View file

@ -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",

View file

@ -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")
}
}

View file

@ -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")
}
}

View file

@ -1065,6 +1065,11 @@
<string name="revanced_remember_video_quality_wifi">wifi</string>
<string name="revanced_remember_video_quality_toast">Changed default %1$s quality to: %2$s</string>
</patch>
<patch id="video.speed.button.PlaybackSpeedButtonPatch">
<string name="revanced_playback_speed_dialog_button_title">Show speed dialog button</string>
<string name="revanced_playback_speed_dialog_button_summary_on">Button is shown</string>
<string name="revanced_playback_speed_dialog_button_summary_off">Button is not shown</string>
</patch>
<patch id="video.speed.custom.CustomPlaybackSpeedPatch">
<string name="revanced_custom_playback_speeds_title">Custom playback speeds</string>
<string name="revanced_custom_playback_speeds_summary">Add or change the available playback speeds</string>

View file

@ -0,0 +1,30 @@
<!--
https://github.com/google/material-design-icons/blob/9beae745bb758f3ad56654fb377ea5cf62be4915/symbols/android/slow_motion_video/materialsymbolsoutlined/slow_motion_video_wght200gradN25_24px.xml
The icon has been resized
Copyright 2022 Google
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:tint="#FFFFFF"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M 6.0798492,16.70271 Q 5.3667836,15.77782 4.9972798,14.87317 4.6275665,13.96852 4.5,12.83942 h 0.7949215 q 0.1275665,0.9249 0.4677271,1.7656 0.3401706,0.8407 0.8797497,1.53346 z M 4.5,11.16058 Q 4.6373409,10.04469 5.002167,9.14154 5.3667836,8.2386 6.0798492,7.3137 L 6.6423983,7.87793 Q 6.1028192,8.5707 5.7626486,9.40308 5.422488,10.23568 5.2949215,11.16058 Z M 11.110466,19.5 Q 9.8992727,19.32286 9.0431213,18.95346 8.1871793,18.58406 7.2572507,17.89299 l 0.5627586,-0.57382 q 0.6818173,0.52458 1.5126748,0.89527 0.8308479,0.37047 1.7777819,0.49836 z M 7.8625281,6.66442 7.2899951,6.09059 Q 8.2197042,5.39953 9.0758557,5.03823 9.9320071,4.67714 11.152995,4.5 V 5.2872 Q 10.19861,5.41509 9.3677624,5.77746 8.5371243,6.13983 7.8625281,6.66442 Z M 10.32873,14.97101 V 9.02899 L 14.953488,12 Z M 12.827456,19.5 v -0.7872 q 2.53571,-0.36237 4.211668,-2.26097 1.675948,-1.89882 1.675948,-4.45183 0,-2.55301 -1.675948,-4.45183 Q 15.363166,5.64957 12.827456,5.2872 V 4.5 Q 15.70589,4.80844 17.60294,6.95069 19.5,9.09294 19.5,12 q 0,2.8964 -1.89706,5.04398 -1.89705,2.14758 -4.775484,2.45602 z"/>
</vector>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:yt="http://schemas.android.com/apk/res-auto" android:id="@+id/youtube_controls_bottom_ui_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layoutDirection="ltr">
<com.google.android.libraries.youtube.common.ui.TouchImageView android:id="@+id/revanced_playback_speed_dialog_button" android:paddingLeft="12dp" android:paddingTop="22dp" android:paddingRight="12dp" android:paddingBottom="16dp" android:longClickable="false" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/revanced_playback_speed_dialog_button" android:scaleType="center" yt:layout_constraintBottom_toTopOf="@+id/quick_actions_container" yt:layout_constraintRight_toLeftOf="@+id/fullscreen_button" style="@style/YouTubePlayerButton"/>
</android.support.constraint.ConstraintLayout>