Skip to content

Commit

Permalink
feat(YouTube - Toolbar components): Add Hide image search button se…
Browse files Browse the repository at this point in the history
…ttings
  • Loading branch information
inotia00 authored and Francesco146 committed Jun 29, 2024
1 parent 7b3e52d commit 457df98
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.general.components.fingerprints.ChipCloudFingerprint
import app.revanced.patches.music.general.components.fingerprints.ContentPillInFingerprint
Expand All @@ -32,7 +31,6 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TopBarM
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.shared.voicesearch.VoiceSearchUtils.patchXml
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
Expand Down Expand Up @@ -74,18 +72,9 @@ object LayoutComponentsPatch : BaseBytecodePatch(
private const val LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR =
"$COMPONENTS_PATH/LayoutComponentsFilter;"

private val ForceHideVoiceSearchButton by booleanPatchOption(
key = "ForceHideVoiceSearchButton",
default = false,
title = "Force hide voice search button",
description = "Permanently hide the voice search button with the legacy method.",
required = true
)

override fun execute(context: BytecodeContext) {
var notificationButtonIncluded = false
var soundSearchButtonIncluded = false
var voiceSearchButtonIncluded = false

// region patch for hide cast button

Expand Down Expand Up @@ -272,31 +261,23 @@ object LayoutComponentsPatch : BaseBytecodePatch(

// region patch for hide voice search button

if (ForceHideVoiceSearchButton == true) {
SettingsPatch.contexts.patchXml(
arrayOf("search_toolbar_view.xml"),
arrayOf("height", "width")
)
} else {
SearchBarFingerprint.resolve(
context,
SearchBarParentFingerprint.resultOrThrow().classDef
)
SearchBarFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val setVisibilityIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setVisibility")
val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex)

replaceInstruction(
setVisibilityIndex,
"invoke-static {v${setVisibilityInstruction.registerC}, v${setVisibilityInstruction.registerD}}, " +
"$GENERAL_CLASS_DESCRIPTOR->hideVoiceSearchButton(Landroid/widget/ImageView;I)V"
)
}
SearchBarFingerprint.resolve(
context,
SearchBarParentFingerprint.resultOrThrow().classDef
)
SearchBarFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val setVisibilityIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setVisibility")
val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex)

replaceInstruction(
setVisibilityIndex,
"invoke-static {v${setVisibilityInstruction.registerC}, v${setVisibilityInstruction.registerD}}, " +
"$GENERAL_CLASS_DESCRIPTOR->hideVoiceSearchButton(Landroid/widget/ImageView;I)V"
)
}
voiceSearchButtonIncluded = true
}

// endregion
Expand Down Expand Up @@ -373,12 +354,10 @@ object LayoutComponentsPatch : BaseBytecodePatch(
"false"
)
}
if (voiceSearchButtonIncluded) {
SettingsPatch.addSwitchPreference(
CategoryType.GENERAL,
"revanced_hide_voice_search_button",
"false"
)
}
SettingsPatch.addSwitchPreference(
CategoryType.GENERAL,
"revanced_hide_voice_search_button",
"false"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.voicesearch.VoiceSearchUtils.patchXml
import app.revanced.patches.youtube.general.toolbar.fingerprints.ActionBarRingoBackgroundFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.ActionBarRingoTextFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.AttributeResolverFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.CreateButtonDrawableFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.CreateSearchSuggestionsFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.DrawerContentViewConstructorFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.DrawerContentViewFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.ImageSearchButtonConfigFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.SearchBarFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.SearchBarParentFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.SearchResultFingerprint
Expand All @@ -45,6 +44,7 @@ import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getTargetIndexWithReferenceReversedOrThrow
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.literalInstructionHook
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
Expand Down Expand Up @@ -77,21 +77,19 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
SearchBarParentFingerprint,
SearchResultFingerprint,
SetActionBarRingoFingerprint,
SetWordMarkHeaderFingerprint
SetWordMarkHeaderFingerprint,
ImageSearchButtonConfigFingerprint,
)
) {
private const val TARGET_RESOURCE_PATH = "res/layout/action_bar_ringo_background.xml"

private val ForceHideVoiceSearchButton by booleanPatchOption(
key = "ForceHideVoiceSearchButton",
default = false,
title = "Force hide voice search button",
description = "Permanently hide the voice search button with the legacy method.",
required = true
)

override fun execute(context: BytecodeContext) {

var settingArray = arrayOf(
"PREFERENCE_SCREEN: GENERAL",
"SETTINGS: TOOLBAR_COMPONENTS"
)

// region patch for change YouTube header

// Invoke YouTube's header attribute into integrations.
Expand Down Expand Up @@ -308,69 +306,55 @@ object ToolBarComponentsPatch : BaseBytecodePatch(

// region patch for hide voice search button

if (ForceHideVoiceSearchButton == true) {
contexts.patchXml(
arrayOf(
"action_bar_search_results_view_mic.xml",
"action_bar_search_view.xml",
"action_bar_search_view_grey.xml",
"action_bar_search_view_mic_out.xml"
),
arrayOf(
"height",
"marginEnd",
"marginStart",
"width"
)
)
} else {
SearchBarFingerprint.resolve(
context,
SearchBarParentFingerprint.resultOrThrow().classDef
if (SettingsPatch.upward1923) {
ImageSearchButtonConfigFingerprint.literalInstructionBooleanHook(
45617544,
"$GENERAL_CLASS_DESCRIPTOR->hideImageSearchButton(Z)Z"
)

SearchBarFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
val setVisibilityIndex =
getTargetIndexWithMethodReferenceNameOrThrow(startIndex, "setVisibility")
val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex)

replaceInstruction(
setVisibilityIndex,
"invoke-static {v${setVisibilityInstruction.registerC}, v${setVisibilityInstruction.registerD}}, " +
"$GENERAL_CLASS_DESCRIPTOR->hideVoiceSearchButton(Landroid/view/View;I)V"
)
}
settingArray += "SETTINGS: HIDE_IMAGE_SEARCH_BUTTON"
}

// endregion

// region patch for hide voice search button

SearchBarFingerprint.resolve(
context,
SearchBarParentFingerprint.resultOrThrow().classDef
)
SearchBarFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
val setVisibilityIndex =
getTargetIndexWithMethodReferenceNameOrThrow(startIndex, "setVisibility")
val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex)

replaceInstruction(
setVisibilityIndex,
"invoke-static {v${setVisibilityInstruction.registerC}, v${setVisibilityInstruction.registerD}}, " +
"$GENERAL_CLASS_DESCRIPTOR->hideVoiceSearchButton(Landroid/view/View;I)V"
)
}
}

SearchResultFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val startIndex = getWideLiteralInstructionIndex(VoiceSearch)
val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceNameOrThrow(
startIndex,
"setOnClickListener"
)
val viewRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC

addInstruction(
setOnClickListenerIndex + 1,
"invoke-static {v$viewRegister}, $GENERAL_CLASS_DESCRIPTOR->hideVoiceSearchButton(Landroid/view/View;)V"
SearchResultFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val startIndex = getWideLiteralInstructionIndex(VoiceSearch)
val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceNameOrThrow(
startIndex,
"setOnClickListener"
)
}
}
val viewRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC

/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"SETTINGS: HIDE_VOICE_SEARCH_BUTTON"
addInstruction(
setOnClickListenerIndex + 1,
"invoke-static {v$viewRegister}, $GENERAL_CLASS_DESCRIPTOR->hideVoiceSearchButton(Landroid/view/View;)V"
)
)
}
}

// endregion
Expand Down Expand Up @@ -406,12 +390,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE_SCREEN: GENERAL",
"SETTINGS: TOOLBAR_COMPONENTS"
)
)
SettingsPatch.addPreference(settingArray)

SettingsPatch.updatePatchStatus(this)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.revanced.patches.youtube.general.toolbar.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.util.fingerprint.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

/**
* This fingerprint is compatible with YouTube v19.07.40+
*/
internal object ImageSearchButtonConfigFingerprint : LiteralValueFingerprint(
returnType = "Z",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
literalSupplier = { 45617544 }
)
Loading

0 comments on commit 457df98

Please sign in to comment.