Skip to content

Commit 0e42d1b

Browse files
MarcaDianoSumAtrIX
andauthored
feat(YouTube - Navigation buttons): Add option to hide navigation button labels (#3189)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent bf61b51 commit 0e42d1b

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app.revanced.patches.youtube.layout.buttons.navigation
22

33
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
45
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
56
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
67
import app.revanced.patcher.patch.BytecodePatch
@@ -12,11 +13,16 @@ import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen.Sor
1213
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
1314
import app.revanced.patches.youtube.layout.buttons.navigation.fingerprints.ANDROID_AUTOMOTIVE_STRING
1415
import app.revanced.patches.youtube.layout.buttons.navigation.fingerprints.AddCreateButtonViewFingerprint
16+
import app.revanced.patches.youtube.layout.buttons.navigation.fingerprints.CreatePivotBarFingerprint
1517
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
1618
import app.revanced.patches.youtube.misc.navigation.NavigationBarHookPatch
1719
import app.revanced.patches.youtube.misc.settings.SettingsPatch
1820
import app.revanced.util.exception
21+
import app.revanced.util.getReference
22+
import app.revanced.util.indexOfFirstInstruction
23+
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
1924
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
25+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
2026

2127
@Patch(
2228
name = "Navigation buttons",
@@ -49,14 +55,17 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
4955
"19.08.36",
5056
"19.09.38",
5157
"19.10.39",
52-
"19.11.43"
58+
"19.11.43",
5359
],
5460
),
5561
],
5662
)
5763
@Suppress("unused")
5864
object NavigationButtonsPatch : BytecodePatch(
59-
setOf(AddCreateButtonViewFingerprint),
65+
setOf(
66+
AddCreateButtonViewFingerprint,
67+
CreatePivotBarFingerprint,
68+
),
6069
) {
6170
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
6271
"Lapp/revanced/integrations/youtube/patches/NavigationButtonsPatch;"
@@ -74,6 +83,7 @@ object NavigationButtonsPatch : BytecodePatch(
7483
SwitchPreference("revanced_hide_create_button"),
7584
SwitchPreference("revanced_hide_subscriptions_button"),
7685
SwitchPreference("revanced_switch_create_with_notifications_button"),
86+
SwitchPreference("revanced_hide_navigation_labels"),
7787
),
7888
),
7989
)
@@ -99,6 +109,21 @@ object NavigationButtonsPatch : BytecodePatch(
99109
}
100110
} ?: throw AddCreateButtonViewFingerprint.exception
101111

112+
// Hide navigation button labels.
113+
CreatePivotBarFingerprint.result?.mutableMethod?.apply {
114+
val setTextIndex = indexOfFirstInstruction {
115+
getReference<MethodReference>()?.name == "setText"
116+
}
117+
118+
val targetRegister = getInstruction<FiveRegisterInstruction>(setTextIndex).registerC
119+
120+
addInstruction(
121+
setTextIndex,
122+
"invoke-static { v$targetRegister }, " +
123+
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideNavigationButtonLabels(Landroid/widget/TextView;)V",
124+
)
125+
} ?: throw CreatePivotBarFingerprint.exception
126+
102127
// Hook navigation button created, in order to hide them.
103128
NavigationBarHookPatch.hookNavigationButtonCreated(INTEGRATIONS_CLASS_DESCRIPTOR)
104129
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package app.revanced.patches.youtube.layout.buttons.navigation.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
import com.android.tools.smali.dexlib2.Opcode
7+
8+
internal object CreatePivotBarFingerprint : MethodFingerprint(
9+
returnType = "V",
10+
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
11+
parameters = listOf(
12+
"Lcom/google/android/libraries/youtube/rendering/ui/pivotbar/PivotBar;",
13+
"Landroid/widget/TextView;",
14+
"Ljava/lang/CharSequence;",
15+
),
16+
opcodes = listOf(
17+
Opcode.INVOKE_VIRTUAL,
18+
Opcode.RETURN_VOID,
19+
),
20+
)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@
437437
<string name="revanced_switch_create_with_notifications_button_title">Switch Create with Notifications</string>
438438
<string name="revanced_switch_create_with_notifications_button_summary_on">Create button is switched with Notifications button\n\nNote: Enabling this also forcibly hides video ads</string>
439439
<string name="revanced_switch_create_with_notifications_button_summary_off">Create button is not switched with Notifications button</string>
440+
<string name="revanced_hide_navigation_button_labels_title">Hide navigation button labels</string>
441+
<string name="revanced_hide_navigation_button_labels_summary_on">Labels are hidden</string>
442+
<string name="revanced_hide_navigation_button_labels_summary_off">Labels are shown</string>
440443
</patch>
441444
<patch id="layout.hide.player.flyoutmenupanel.HidePlayerFlyoutMenuPatch">
442445
<string name="revanced_hide_player_flyout_title">Flyout menu</string>

0 commit comments

Comments
 (0)