diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/components/LayoutComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/components/LayoutComponentsPatch.kt index 7fcd0333c..78b4cf287 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/components/LayoutComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/components/LayoutComponentsPatch.kt @@ -6,9 +6,12 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels 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.smali.ExternalLabel import app.revanced.patches.shared.litho.LithoFilterPatch +import app.revanced.patches.shared.voicesearch.VoiceSearchUtils.patchXml import app.revanced.patches.youtube.general.components.fingerprints.AccountListFingerprint import app.revanced.patches.youtube.general.components.fingerprints.AccountListParentFingerprint import app.revanced.patches.youtube.general.components.fingerprints.AccountMenuFingerprint @@ -17,12 +20,16 @@ import app.revanced.patches.youtube.general.components.fingerprints.BottomUiCont import app.revanced.patches.youtube.general.components.fingerprints.CreateSearchSuggestionsFingerprint import app.revanced.patches.youtube.general.components.fingerprints.FloatingMicrophoneFingerprint import app.revanced.patches.youtube.general.components.fingerprints.TrendingSearchConfigFingerprint +import app.revanced.patches.youtube.general.components.fingerprints.SearchBarFingerprint +import app.revanced.patches.youtube.general.components.fingerprints.SearchBarParentFingerprint +import app.revanced.patches.youtube.general.components.fingerprints.SearchResultFingerprint import app.revanced.patches.youtube.utils.fingerprints.AccountMenuParentFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AccountSwitcherAccessibility +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.VoiceSearch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.toolbar.ToolBarHookPatch import app.revanced.patches.youtube.utils.viewgroup.ViewGroupMarginLayoutParamsHookPatch @@ -58,6 +65,8 @@ object LayoutComponentsPatch : BaseBytecodePatch( BottomUiContainerFingerprint, CreateSearchSuggestionsFingerprint, FloatingMicrophoneFingerprint, + SearchBarParentFingerprint, + SearchResultFingerprint, TrendingSearchConfigFingerprint ) ) { @@ -66,6 +75,13 @@ 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 = "Hide voice search button with legacy method, button will always be hidden" + ) + override fun execute(context: BytecodeContext) { // region patch for hide account menu @@ -227,6 +243,64 @@ object LayoutComponentsPatch : BaseBytecodePatch( // endregion + // region patch for hide voice search button + + if (ForceHideVoiceSearchButton == true) { + SettingsPatch.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) + + SearchBarFingerprint.resultOrThrow().let { + it.mutableMethod.apply { + val startIndex = it.scanResult.patternScanResult!!.startIndex + val setVisibilityIndex = getTargetIndexWithMethodReferenceName(startIndex, "setVisibility") + val setVisibilityInstruction = getInstruction(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 = getTargetIndexWithMethodReferenceName(startIndex, "setOnClickListener") + val viewRegister = getInstruction(setOnClickListenerIndex).registerC + + addInstruction( + setOnClickListenerIndex + 1, + "invoke-static {v$viewRegister}, $GENERAL_CLASS_DESCRIPTOR->hideVoiceSearchButton(Landroid/view/View;)V" + ) + } + } + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "SETTINGS: HIDE_VOICE_SEARCH_BUTTON" + ) + ) + } + + // endregion LithoFilterPatch.addFilter(CUSTOM_FILTER_CLASS_DESCRIPTOR) LithoFilterPatch.addFilter(LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchBarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchBarFingerprint.kt new file mode 100644 index 000000000..eb0c70423 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchBarFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.general.components.fingerprints + +import app.revanced.util.fingerprint.MethodReferenceNameFingerprint +import com.android.tools.smali.dexlib2.Opcode + +object SearchBarFingerprint : MethodReferenceNameFingerprint( + returnType = "V", + parameters = listOf("Ljava/lang/String;"), + opcodes = listOf( + Opcode.IGET_OBJECT, + Opcode.IF_EQZ, + Opcode.IGET_BOOLEAN, + Opcode.IF_EQZ + ), + reference = { "isEmpty" } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchBarParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchBarParentFingerprint.kt new file mode 100644 index 000000000..5895627f8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchBarParentFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.youtube.general.components.fingerprints + +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.VoiceSearch +import app.revanced.util.fingerprint.LiteralValueFingerprint + +object SearchBarParentFingerprint : LiteralValueFingerprint( + returnType = "Landroid/view/View;", + strings = listOf("voz-target-id"), + literalSupplier = { VoiceSearch } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchResultFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchResultFingerprint.kt new file mode 100644 index 000000000..dda92905a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SearchResultFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.youtube.general.components.fingerprints + +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.VoiceSearch +import app.revanced.util.fingerprint.LiteralValueFingerprint + +object SearchResultFingerprint : LiteralValueFingerprint( + returnType = "Landroid/view/View;", + strings = listOf("search_filter_chip_applied", "search_original_chip_query"), + literalSupplier = { VoiceSearch } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/voicesearch/VoiceSearchButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/voicesearch/VoiceSearchButtonPatch.kt deleted file mode 100644 index b57732ed7..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/voicesearch/VoiceSearchButtonPatch.kt +++ /dev/null @@ -1,36 +0,0 @@ -package app.revanced.patches.youtube.layout.voicesearch - -import app.revanced.patcher.data.ResourceContext -import app.revanced.patches.shared.voicesearch.VoiceSearchUtils.patchXml -import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE -import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.patch.BaseResourcePatch - -@Suppress("unused") -object VoiceSearchButtonPatch : BaseResourcePatch( - name = "Hide voice search button", - description = "Hides the voice search button in the search bar.", - dependencies = setOf(SettingsPatch::class), - compatiblePackages = COMPATIBLE_PACKAGE, - use = false -) { - override fun execute(context: ResourceContext) { - - context.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" - ) - ) - - SettingsPatch.updatePatchStatus(this) - } -} diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index 6dc2eb2fd..a7b7a1997 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -85,6 +85,7 @@ object SharedResourceIdPatch : ResourcePatch() { var ToolTipContentView = -1L var TotalTime = -1L var VideoQualityBottomSheet = -1L + var VoiceSearch = -1L var YouTubeControlsOverlaySubtitleButton = -1L override fun execute(context: ResourceContext) { @@ -160,6 +161,7 @@ object SharedResourceIdPatch : ResourcePatch() { ToolTipContentView = getId(LAYOUT, "tooltip_content_view") TotalTime = getId(STRING, "total_time") VideoQualityBottomSheet = getId(LAYOUT, "video_quality_bottom_sheet_list_fragment_title") + VoiceSearch = getId(ID, "voice_search") YouTubeControlsOverlaySubtitleButton = getId(LAYOUT, "youtube_controls_overlay_subtitle_button") } diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 5ee662d55..220a1b1de 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -295,6 +295,9 @@ You tab > View channel > Menu > Settings." Hide trending searches Trending searches are hidden. Trending searches are shown. + Hide voice search button + Voice search button is hidden in search bar. + Voice search button is shown in search bar. Remove viewer discretion dialog "Remove viewer discretion dialog. This does not bypass the age restriction. It just accepts it automatically." diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 9085efdd8..84630a7d0 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -153,6 +153,9 @@ SETTINGS: HIDE_LAYOUT_COMPONENTS --> + +