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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.HideNavigationButtonLabelsFingerprint
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 @@ -56,7 +62,10 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
)
@Suppress("unused")
object NavigationButtonsPatch : BytecodePatch(
setOf(AddCreateButtonViewFingerprint),
setOf(
AddCreateButtonViewFingerprint,
HideNavigationButtonLabelsFingerprint,
),
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/youtube/patches/NavigationButtonsPatch;"
Expand All @@ -73,6 +82,7 @@ object NavigationButtonsPatch : BytecodePatch(
SwitchPreference("revanced_hide_shorts_button"),
SwitchPreference("revanced_hide_create_button"),
SwitchPreference("revanced_hide_subscriptions_button"),
SwitchPreference("revanced_hide_navigation_labels"),
MarcaDian marked this conversation as resolved.
Show resolved Hide resolved
SwitchPreference("revanced_switch_create_with_notifications_button"),
),
),
Expand All @@ -99,6 +109,22 @@ object NavigationButtonsPatch : BytecodePatch(
}
} ?: throw AddCreateButtonViewFingerprint.exception

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

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

addInstruction(
targetIndex,
"invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideNavigationLabels(Landroid/widget/TextView;)V"
)
}
} ?: throw HideNavigationButtonLabelsFingerprint.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,21 @@
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 HideNavigationButtonLabelsFingerprint : 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,
),
customFingerprint = { methodDef, _ -> methodDef.name == "<init>" }
)
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 @@ -433,6 +433,9 @@
<string name="revanced_hide_subscriptions_button_title">Hide Subscriptions</string>
<string name="revanced_hide_subscriptions_button_summary_on">Subscriptions button is hidden</string>
<string name="revanced_hide_subscriptions_button_summary_off">Subscriptions button is shown</string>
<string name="revanced_hide_navigation_labels_title">Hide navigation button labels</string>
<string name="revanced_hide_navigation_labels_summary_on">Navigation button labels are hidden</string>
<string name="revanced_hide_navigation_labels_summary_off">Navigation button labels are shown</string>
<!-- 'Notifications' should be translated using the same localized wording YouTube displays the tab. -->
<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>
Expand Down