Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(YouTube - Navigation buttons): Add option to hide navigation button labels #3189

Merged
merged 3 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.revanced.patches.youtube.layout.buttons.navigation

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
Expand All @@ -12,11 +13,16 @@ import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen.Sor
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.layout.buttons.navigation.fingerprints.ANDROID_AUTOMOTIVE_STRING
import app.revanced.patches.youtube.layout.buttons.navigation.fingerprints.AddCreateButtonViewFingerprint
import app.revanced.patches.youtube.layout.buttons.navigation.fingerprints.CreatePivotBarFingerprint
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
import app.revanced.patches.youtube.misc.navigation.NavigationBarHookPatch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import app.revanced.util.exception
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

@Patch(
name = "Navigation buttons",
Expand Down Expand Up @@ -49,14 +55,17 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
"19.08.36",
"19.09.38",
"19.10.39",
"19.11.43"
"19.11.43",
],
),
],
)
@Suppress("unused")
object NavigationButtonsPatch : BytecodePatch(
setOf(AddCreateButtonViewFingerprint),
setOf(
AddCreateButtonViewFingerprint,
CreatePivotBarFingerprint,
),
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/youtube/patches/NavigationButtonsPatch;"
Expand All @@ -74,6 +83,7 @@ object NavigationButtonsPatch : BytecodePatch(
SwitchPreference("revanced_hide_create_button"),
SwitchPreference("revanced_hide_subscriptions_button"),
SwitchPreference("revanced_switch_create_with_notifications_button"),
SwitchPreference("revanced_hide_navigation_labels"),
),
),
)
Expand All @@ -99,6 +109,21 @@ object NavigationButtonsPatch : BytecodePatch(
}
} ?: throw AddCreateButtonViewFingerprint.exception

// Hide navigation button labels.
CreatePivotBarFingerprint.result?.mutableMethod?.apply {
val setTextIndex = indexOfFirstInstruction {
getReference<MethodReference>()?.name == "setText"
}

val targetRegister = getInstruction<FiveRegisterInstruction>(setTextIndex).registerC

addInstruction(
setTextIndex,
"invoke-static { v$targetRegister }, " +
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideNavigationButtonLabels(Landroid/widget/TextView;)V",
)
} ?: throw CreatePivotBarFingerprint.exception

// Hook navigation button created, in order to hide them.
NavigationBarHookPatch.hookNavigationButtonCreated(INTEGRATIONS_CLASS_DESCRIPTOR)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.revanced.patches.youtube.layout.buttons.navigation.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

internal object CreatePivotBarFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
parameters = listOf(
"Lcom/google/android/libraries/youtube/rendering/ui/pivotbar/PivotBar;",
"Landroid/widget/TextView;",
"Ljava/lang/CharSequence;",
),
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID,
),
)
3 changes: 3 additions & 0 deletions src/main/resources/addresources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@
<string name="revanced_switch_create_with_notifications_button_title">Switch Create with Notifications</string>
<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>
<string name="revanced_switch_create_with_notifications_button_summary_off">Create button is not switched with Notifications button</string>
<string name="revanced_hide_navigation_button_labels_title">Hide navigation button labels</string>
<string name="revanced_hide_navigation_button_labels_summary_on">Labels are hidden</string>
<string name="revanced_hide_navigation_button_labels_summary_off">Labels are shown</string>
</patch>
<patch id="layout.hide.player.flyoutmenupanel.HidePlayerFlyoutMenuPatch">
<string name="revanced_hide_player_flyout_title">Flyout menu</string>
Expand Down