feat(YouTube/Hide layout components): add Hide voice search button settings

This commit is contained in:
inotia00 2024-04-26 01:00:36 +09:00
parent 9d3f035817
commit f909726e07
8 changed files with 118 additions and 36 deletions

View File

@ -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<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 = getTargetIndexWithMethodReferenceName(startIndex, "setOnClickListener")
val viewRegister = getInstruction<FiveRegisterInstruction>(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)

View File

@ -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" }
)

View File

@ -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 }
)

View File

@ -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 }
)

View File

@ -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)
}
}

View File

@ -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")
}

View File

@ -295,6 +295,9 @@ You tab > View channel > Menu > Settings."</string>
<string name="revanced_hide_trending_searches_title">Hide trending searches</string>
<string name="revanced_hide_trending_searches_summary_on">Trending searches are hidden.</string>
<string name="revanced_hide_trending_searches_summary_off">Trending searches are shown.</string>
<string name="revanced_hide_voice_search_button_title">Hide voice search button</string>
<string name="revanced_hide_voice_search_button_summary_on">Voice search button is hidden in search bar.</string>
<string name="revanced_hide_voice_search_button_summary_off">Voice search button is shown in search bar.</string>
<string name="revanced_remove_viewer_discretion_dialog_title">Remove viewer discretion dialog</string>
<string name="revanced_remove_viewer_discretion_dialog_summary">"Remove viewer discretion dialog.
This does not bypass the age restriction. It just accepts it automatically."</string>

View File

@ -153,6 +153,9 @@
<SwitchPreference android:title="@string/revanced_hide_toolbar_create_notification_button_title" android:key="revanced_hide_toolbar_create_notification_button" android:defaultValue="false" android:summaryOn="@string/revanced_hide_toolbar_create_notification_button_summary_on" android:summaryOff="@string/revanced_hide_toolbar_create_notification_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_trending_searches_title" android:key="revanced_hide_trending_searches" android:defaultValue="true" android:summaryOn="@string/revanced_hide_trending_searches_summary_on" android:summaryOff="@string/revanced_hide_trending_searches_summary_off" />SETTINGS: HIDE_LAYOUT_COMPONENTS -->
<!-- SETTINGS: HIDE_VOICE_SEARCH_BUTTON
<SwitchPreference android:title="@string/revanced_hide_voice_search_button_title" android:key="revanced_hide_voice_search_button" android:defaultValue="false" android:summaryOn="@string/revanced_hide_voice_search_button_summary_on" android:summaryOff="@string/revanced_hide_voice_search_button_summary_off" />SETTINGS: HIDE_VOICE_SEARCH_BUTTON -->
<!-- SETTINGS: REMOVE_VIEWER_DISCRETION_DIALOG
<SwitchPreference android:title="@string/revanced_remove_viewer_discretion_dialog_title" android:key="revanced_remove_viewer_discretion_dialog" android:defaultValue="false" android:summary="@string/revanced_remove_viewer_discretion_dialog_summary" />SETTINGS: REMOVE_VIEWER_DISCRETION_DIALOG -->