mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-09 11:04:36 +02:00
feat(YouTube/Toolbar components): add Hide image search button
settings https://github.com/inotia00/ReVanced_Extended/issues/2188
This commit is contained in:
parent
4194b5f409
commit
a481c922cf
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
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"
|
||||
)
|
||||
}
|
||||
replaceInstruction(
|
||||
setVisibilityIndex,
|
||||
"invoke-static {v${setVisibilityInstruction.registerC}, v${setVisibilityInstruction.registerD}}, " +
|
||||
"$GENERAL_CLASS_DESCRIPTOR->hideVoiceSearchButton(Landroid/widget/ImageView;I)V"
|
||||
)
|
||||
}
|
||||
voiceSearchButtonIncluded = true
|
||||
}
|
||||
|
||||
// endregion
|
||||
@ -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"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,8 @@ 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
|
||||
@ -19,6 +17,7 @@ import app.revanced.patches.youtube.general.toolbar.fingerprints.CreateButtonDra
|
||||
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
|
||||
@ -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
|
||||
@ -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.
|
||||
@ -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"
|
||||
if (SettingsPatch.upward1923) {
|
||||
ImageSearchButtonConfigFingerprint.literalInstructionBooleanHook(
|
||||
45617544,
|
||||
"$GENERAL_CLASS_DESCRIPTOR->hideImageSearchButton(Z)Z"
|
||||
)
|
||||
|
||||
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"
|
||||
)
|
||||
)
|
||||
} else {
|
||||
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
|
||||
@ -406,12 +390,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
|
||||
/**
|
||||
* Add settings
|
||||
*/
|
||||
SettingsPatch.addPreference(
|
||||
arrayOf(
|
||||
"PREFERENCE_SCREEN: GENERAL",
|
||||
"SETTINGS: TOOLBAR_COMPONENTS"
|
||||
)
|
||||
)
|
||||
SettingsPatch.addPreference(settingArray)
|
||||
|
||||
SettingsPatch.updatePatchStatus(this)
|
||||
}
|
||||
|
@ -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 }
|
||||
)
|
@ -477,6 +477,9 @@ You tab → View channel → Menu → Settings"</string>
|
||||
<string name="revanced_hide_search_term_thumbnail_title">Hide search term thumbnails</string>
|
||||
<string name="revanced_hide_search_term_thumbnail_summary_on">Thumbnails in the search term history are hidden.</string>
|
||||
<string name="revanced_hide_search_term_thumbnail_summary_off">Thumbnails in the search term history are shown.</string>
|
||||
<string name="revanced_hide_image_search_button_title">Hide image search button</string>
|
||||
<string name="revanced_hide_image_search_button_summary_on">Image search button is hidden.</string>
|
||||
<string name="revanced_hide_image_search_button_summary_off">Image search button is 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.</string>
|
||||
<string name="revanced_hide_voice_search_button_summary_off">Voice search button is shown.</string>
|
||||
|
@ -174,10 +174,11 @@
|
||||
<SwitchPreference android:title="@string/revanced_hide_toolbar_notification_button_title" android:key="revanced_hide_toolbar_notification_button" android:summaryOn="@string/revanced_hide_toolbar_notification_button_summary_on" android:summaryOff="@string/revanced_hide_toolbar_notification_button_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_hide_search_term_thumbnail_title" android:key="revanced_hide_search_term_thumbnail" android:summaryOn="@string/revanced_hide_search_term_thumbnail_summary_on" android:summaryOff="@string/revanced_hide_search_term_thumbnail_summary_off" />SETTINGS: TOOLBAR_COMPONENTS -->
|
||||
|
||||
<!-- SETTINGS: HIDE_VOICE_SEARCH_BUTTON
|
||||
<SwitchPreference android:title="@string/revanced_hide_voice_search_button_title" android:key="revanced_hide_voice_search_button" 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: HIDE_IMAGE_SEARCH_BUTTON
|
||||
<SwitchPreference android:title="@string/revanced_hide_image_search_button_title" android:key="revanced_hide_image_search_button" android:summaryOn="@string/revanced_hide_image_search_button_summary_on" android:summaryOff="@string/revanced_hide_image_search_button_summary_off" />SETTINGS: HIDE_IMAGE_SEARCH_BUTTON -->
|
||||
|
||||
<!-- SETTINGS: TOOLBAR_COMPONENTS
|
||||
<SwitchPreference android:title="@string/revanced_hide_voice_search_button_title" android:key="revanced_hide_voice_search_button" android:summaryOn="@string/revanced_hide_voice_search_button_summary_on" android:summaryOff="@string/revanced_hide_voice_search_button_summary_off" />
|
||||
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>
|
||||
<SwitchPreference android:title="@string/revanced_replace_toolbar_create_button_title" android:key="revanced_replace_toolbar_create_button" android:summary="@string/revanced_replace_toolbar_create_button_summary" />
|
||||
<SwitchPreference android:title="@string/revanced_replace_toolbar_create_button_type_title" android:key="revanced_replace_toolbar_create_button_type" android:summaryOn="@string/revanced_replace_toolbar_create_button_type_summary_on" android:summaryOff="@string/revanced_replace_toolbar_create_button_type_summary_off" android:dependency="revanced_replace_toolbar_create_button" />SETTINGS: TOOLBAR_COMPONENTS -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user