Skip to content

Commit dd8afa2

Browse files
authored
feat(YouTube - Hide player overlay buttons): Add in app setting for "Hide player control buttons background" (#5147)
1 parent 1d46ad0 commit dd8afa2

File tree

6 files changed

+78
-30
lines changed

6 files changed

+78
-30
lines changed

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/HidePlayerOverlayButtonsPatch.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app.revanced.extension.youtube.patches;
22

33
import android.view.View;
4+
import android.view.ViewGroup;
45
import android.widget.ImageView;
56

67
import app.revanced.extension.shared.Logger;
@@ -58,6 +59,22 @@ public static void hidePreviousNextButtons(View parentView) {
5859
});
5960
}
6061

62+
/**
63+
* Injection point.
64+
*/
65+
public static void hidePlayerControlButtonsBackground(View rootView) {
66+
try {
67+
if (!Settings.HIDE_PLAYER_CONTROL_BUTTONS_BACKGROUND.get()) {
68+
return;
69+
}
70+
71+
// Each button is an ImageView with a background set to another drawable.
72+
removeImageViewsBackgroundRecursive(rootView);
73+
} catch (Exception ex) {
74+
Logger.printException(() -> "removePlayerControlButtonsBackground failure", ex);
75+
}
76+
}
77+
6178
private static void hideView(View parentView, int resourceId) {
6279
View nextPreviousButton = parentView.findViewById(resourceId);
6380

@@ -69,4 +86,16 @@ private static void hideView(View parentView, int resourceId) {
6986
Logger.printDebug(() -> "Hiding previous/next button");
7087
Utils.hideViewByRemovingFromParentUnderCondition(true, nextPreviousButton);
7188
}
89+
90+
private static void removeImageViewsBackgroundRecursive(View currentView) {
91+
if (currentView instanceof ImageView imageView) {
92+
imageView.setBackground(null);
93+
}
94+
95+
if (currentView instanceof ViewGroup viewGroup) {
96+
for (int i = 0; i < viewGroup.getChildCount(); i++) {
97+
removeImageViewsBackgroundRecursive(viewGroup.getChildAt(i));
98+
}
99+
}
100+
}
72101
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public class Settings extends BaseSettings {
135135
public static final BooleanSetting HIDE_AUTOPLAY_BUTTON = new BooleanSetting("revanced_hide_autoplay_button", TRUE, true);
136136
public static final BooleanSetting HIDE_CAPTIONS_BUTTON = new BooleanSetting("revanced_hide_captions_button", FALSE);
137137
public static final BooleanSetting HIDE_CAST_BUTTON = new BooleanSetting("revanced_hide_cast_button", TRUE, true);
138+
public static final BooleanSetting HIDE_PLAYER_CONTROL_BUTTONS_BACKGROUND = new BooleanSetting("revanced_hide_player_control_buttons_background", FALSE, true);
138139
public static final BooleanSetting HIDE_CHANNEL_BAR = new BooleanSetting("revanced_hide_channel_bar", FALSE);
139140
public static final BooleanSetting HIDE_CHANNEL_MEMBER_SHELF = new BooleanSetting("revanced_hide_channel_member_shelf", TRUE);
140141
public static final BooleanSetting HIDE_COMMUNITY_GUIDELINES = new BooleanSetting("revanced_hide_community_guidelines", TRUE);

patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/Fingerprints.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app.revanced.patches.youtube.layout.buttons.overlay
22

33
import app.revanced.patcher.fingerprint
44
import app.revanced.util.containsLiteralInstruction
5+
import app.revanced.util.literal
56
import com.android.tools.smali.dexlib2.AccessFlags
67

78
internal val playerControlsPreviousNextOverlayTouchFingerprint = fingerprint {
@@ -20,3 +21,10 @@ internal val mediaRouteButtonFingerprint = fingerprint {
2021
methodDef.definingClass.endsWith("/MediaRouteButton;") && methodDef.name == "setVisibility"
2122
}
2223
}
24+
25+
internal val inflateControlsGroupLayoutStubFingerprint = fingerprint {
26+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
27+
parameters()
28+
returns("V")
29+
literal { controlsButtonGroupLayoutStub }
30+
}

patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ internal var playerControlPreviousButtonTouchArea = -1L
2828
private set
2929
internal var playerControlNextButtonTouchArea = -1L
3030
private set
31+
internal var controlsButtonGroupLayoutStub = -1L
32+
private set
3133

3234
private val hidePlayerOverlayButtonsResourcePatch = resourcePatch {
3335
dependsOn(resourceMappingPatch)
3436

3537
execute {
3638
playerControlPreviousButtonTouchArea = resourceMappings["id", "player_control_previous_button_touch_area"]
3739
playerControlNextButtonTouchArea = resourceMappings["id", "player_control_next_button_touch_area"]
40+
controlsButtonGroupLayoutStub = resourceMappings["id", "youtube_controls_button_group_layout_stub"]
3841
}
3942
}
4043

@@ -43,7 +46,8 @@ private const val EXTENSION_CLASS_DESCRIPTOR =
4346

4447
val hidePlayerOverlayButtonsPatch = bytecodePatch(
4548
name = "Hide player overlay buttons",
46-
description = "Adds options to hide the player Cast, Autoplay, Captions, and Previous & Next buttons.",
49+
description = "Adds options to hide the player Cast, Autoplay, Captions, Previous & Next buttons, and the player " +
50+
"control buttons background.",
4751
) {
4852
dependsOn(
4953
sharedExtensionPatch,
@@ -72,6 +76,7 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch(
7276
SwitchPreference("revanced_hide_cast_button"),
7377
SwitchPreference("revanced_hide_captions_button"),
7478
SwitchPreference("revanced_hide_autoplay_button"),
79+
SwitchPreference("revanced_hide_player_control_buttons_background"),
7580
)
7681

7782
// region Hide player next/previous button.
@@ -147,5 +152,32 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch(
147152
}
148153

149154
// endregion
155+
156+
// region Hide player control buttons background.
157+
158+
inflateControlsGroupLayoutStubFingerprint.method.apply {
159+
val controlsButtonGroupLayoutStubResIdConstIndex =
160+
indexOfFirstLiteralInstructionOrThrow(controlsButtonGroupLayoutStub)
161+
val inflateControlsGroupLayoutStubIndex =
162+
indexOfFirstInstruction(controlsButtonGroupLayoutStubResIdConstIndex) {
163+
getReference<MethodReference>()?.name == "inflate"
164+
}
165+
166+
val freeRegister = findFreeRegister(inflateControlsGroupLayoutStubIndex)
167+
val hidePlayerControlButtonsBackgroundDescriptor =
168+
"$EXTENSION_CLASS_DESCRIPTOR->hidePlayerControlButtonsBackground(Landroid/view/View;)V"
169+
170+
addInstructions(
171+
inflateControlsGroupLayoutStubIndex + 1,
172+
"""
173+
# Move the inflated layout to a temporary register.
174+
# The result of the inflate method is by default not moved to a register after the method is called.
175+
move-result-object v$freeRegister
176+
invoke-static { v$freeRegister }, $hidePlayerControlButtonsBackgroundDescriptor
177+
"""
178+
)
179+
}
180+
181+
// endregion
150182
}
151183
}
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,12 @@
11
package app.revanced.patches.youtube.layout.player.background
22

33
import app.revanced.patcher.patch.resourcePatch
4-
import app.revanced.util.doRecursively
5-
import org.w3c.dom.Element
4+
import app.revanced.patches.youtube.layout.buttons.overlay.hidePlayerOverlayButtonsPatch
65

76
@Suppress("unused")
7+
@Deprecated("Functionality added to hidePlayerOverlayButtonsPatch", ReplaceWith("hidePlayerOverlayButtonsPatch"))
88
val playerControlsBackgroundPatch = resourcePatch(
9-
name = "Remove player controls background",
10-
description = "Removes the dark background surrounding the video player controls.",
11-
use = false,
9+
description = "Removes the dark background surrounding the video player control buttons.",
1210
) {
13-
compatibleWith(
14-
"com.google.android.youtube"(
15-
"19.16.39",
16-
"19.25.37",
17-
"19.34.42",
18-
"19.43.41",
19-
"19.47.53",
20-
"20.07.39",
21-
"20.12.46",
22-
)
23-
)
24-
25-
execute {
26-
document("res/drawable/player_button_circle_background.xml").use { document ->
27-
28-
document.doRecursively node@{ node ->
29-
if (node !is Element) return@node
30-
31-
node.getAttributeNode("android:color")?.let { attribute ->
32-
attribute.textContent = "@android:color/transparent"
33-
}
34-
}
35-
}
36-
}
11+
dependsOn(hidePlayerOverlayButtonsPatch)
3712
}

patches/src/main/resources/addresources/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ To show the Audio track menu, change \'Spoof video streams\' to iOS TV"</string>
743743
<string name="revanced_hide_autoplay_button_title">Hide Autoplay button</string>
744744
<string name="revanced_hide_autoplay_button_summary_on">Autoplay button is hidden</string>
745745
<string name="revanced_hide_autoplay_button_summary_off">Autoplay button is shown</string>
746+
<string name="revanced_hide_player_control_buttons_background_title">Hide player control buttons background</string>
747+
<string name="revanced_hide_player_control_buttons_background_summary_on">Player control buttons background is hidden</string>
748+
<string name="revanced_hide_player_control_buttons_background_summary_off">Player control buttons background is shown</string>
746749
</patch>
747750
<patch id="layout.hide.endscreencards.hideEndscreenCardsResourcePatch">
748751
<string name="revanced_hide_endscreen_cards_title">Hide end screen cards</string>

0 commit comments

Comments
 (0)