From 6dfd88c75e5810271ed94d4f740ada11d3833a0a Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:51:43 +0900 Subject: [PATCH] feat(YouTube Music - Hide layout components): Add `Hide search button` setting https://github.com/inotia00/ReVanced_Extended/issues/2850 --- .../music/patches/general/GeneralPatch.java | 13 +++++++---- .../extension/music/settings/Settings.java | 1 + .../music/general/components/Fingerprints.kt | 12 ++++++++++ .../components/LayoutComponentsPatch.kt | 23 +++++++++++++++++++ .../utils/resourceid/SharedResourceIdPatch.kt | 6 +++++ .../music/settings/host/values/strings.xml | 2 ++ 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/extensions/shared/src/main/java/app/revanced/extension/music/patches/general/GeneralPatch.java b/extensions/shared/src/main/java/app/revanced/extension/music/patches/general/GeneralPatch.java index f22e9aff4..1f3311ad1 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/music/patches/general/GeneralPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/music/patches/general/GeneralPatch.java @@ -9,13 +9,11 @@ import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; +import android.widget.LinearLayout; import app.revanced.extension.music.settings.Settings; import app.revanced.extension.shared.utils.ResourceUtils; -/** - * @noinspection ALL - */ @SuppressWarnings("unused") public class GeneralPatch { @@ -79,6 +77,13 @@ public class GeneralPatch { } } + public static void hideSearchButton(View view) { + if (Settings.HIDE_SEARCH_BUTTON.get()) { + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, 0); + view.setLayoutParams(layoutParams); + } + } + public static boolean hideSoundSearchButton() { return Settings.HIDE_SOUND_SEARCH_BUTTON.get(); } @@ -123,7 +128,7 @@ public class GeneralPatch { *

* The {@link AlertDialog#getButton(int)} method must be used after {@link AlertDialog#show()} is called. * Otherwise {@link AlertDialog#getButton(int)} method will always return null. - * https://stackoverflow.com/a/4604145 + * Reference *

* That's why {@link AlertDialog#show()} is absolutely necessary. * Instead, use two tricks to hide Alertdialog. diff --git a/extensions/shared/src/main/java/app/revanced/extension/music/settings/Settings.java b/extensions/shared/src/main/java/app/revanced/extension/music/settings/Settings.java index 3f74973f2..6222be5a9 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/music/settings/Settings.java +++ b/extensions/shared/src/main/java/app/revanced/extension/music/settings/Settings.java @@ -109,6 +109,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting HIDE_NOTIFICATION_BUTTON = new BooleanSetting("revanced_hide_notification_button", FALSE, true); public static final BooleanSetting HIDE_PLAYLIST_CARD_SHELF = new BooleanSetting("revanced_hide_playlist_card_shelf", FALSE, true); public static final BooleanSetting HIDE_SAMPLE_SHELF = new BooleanSetting("revanced_hide_samples_shelf", FALSE, true); + public static final BooleanSetting HIDE_SEARCH_BUTTON = new BooleanSetting("revanced_hide_search_button", FALSE, true); public static final BooleanSetting HIDE_SOUND_SEARCH_BUTTON = new BooleanSetting("revanced_hide_sound_search_button", FALSE, true); public static final BooleanSetting HIDE_TAP_TO_UPDATE_BUTTON = new BooleanSetting("revanced_hide_tap_to_update_button", FALSE, true); public static final BooleanSetting HIDE_VOICE_SEARCH_BUTTON = new BooleanSetting("revanced_hide_voice_search_button", FALSE, true); diff --git a/patches/src/main/kotlin/app/revanced/patches/music/general/components/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/general/components/Fingerprints.kt index 664966147..319724ff3 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/general/components/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/general/components/Fingerprints.kt @@ -5,6 +5,7 @@ import app.revanced.patches.music.utils.resourceid.historyMenuItem import app.revanced.patches.music.utils.resourceid.musicTasteBuilderShelf import app.revanced.patches.music.utils.resourceid.offlineSettingsMenuItem import app.revanced.patches.music.utils.resourceid.playerOverlayChip +import app.revanced.patches.music.utils.resourceid.searchButton import app.revanced.patches.music.utils.resourceid.toolTipContentView import app.revanced.patches.music.utils.resourceid.topBarMenuItemImageView import app.revanced.util.fingerprint.legacyFingerprint @@ -118,6 +119,17 @@ internal val preferenceScreenFingerprint = legacyFingerprint( } ) +internal val searchActionViewFingerprint = legacyFingerprint( + name = "searchActionViewFingerprint", + returnType = "Landroid/view/View;", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = emptyList(), + literals = listOf(searchButton), + customFingerprint = { _, classDef -> + classDef.type.endsWith("/SearchActionProvider;") + } +) + internal val searchBarFingerprint = legacyFingerprint( name = "searchBarFingerprint", returnType = "V", diff --git a/patches/src/main/kotlin/app/revanced/patches/music/general/components/LayoutComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/general/components/LayoutComponentsPatch.kt index 3154b1828..ad11402eb 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/general/components/LayoutComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/general/components/LayoutComponentsPatch.kt @@ -20,6 +20,7 @@ import app.revanced.patches.music.utils.playservice.is_8_05_or_greater import app.revanced.patches.music.utils.playservice.versionCheckPatch import app.revanced.patches.music.utils.resourceid.musicTasteBuilderShelf import app.revanced.patches.music.utils.resourceid.playerOverlayChip +import app.revanced.patches.music.utils.resourceid.searchButton import app.revanced.patches.music.utils.resourceid.sharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.topBarMenuItemImageView import app.revanced.patches.music.utils.settings.CategoryType @@ -198,6 +199,23 @@ val layoutComponentsPatch = bytecodePatch( // endregion + // region patch for hide search button + + searchActionViewFingerprint.methodOrThrow().apply { + val constIndex = + indexOfFirstLiteralInstructionOrThrow(searchButton) + val targetIndex = + indexOfFirstInstructionOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT) + val targetRegister = getInstruction(targetIndex).registerA + + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, $GENERAL_CLASS_DESCRIPTOR->hideSearchButton(Landroid/view/View;)V" + ) + } + + // endregion + // region patch for hide sound search button if (is_6_48_or_greater) { @@ -353,6 +371,11 @@ val layoutComponentsPatch = bytecodePatch( "revanced_hide_samples_shelf", "false" ) + addSwitchPreference( + CategoryType.GENERAL, + "revanced_hide_search_button", + "false" + ) if (is_6_48_or_greater) { addSwitchPreference( CategoryType.GENERAL, diff --git a/patches/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt index e1b1bce52..fd21eb157 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt @@ -83,6 +83,8 @@ var qualityAuto = -1L private set var remixGenericButtonSize = -1L private set +var searchButton = -1L + private set var slidingDialogAnimation = -1L private set var tapBloomView = -1L @@ -264,6 +266,10 @@ internal val sharedResourceIdPatch = resourcePatch( DIMEN, "remix_generic_button_size" ] + searchButton = resourceMappings[ + LAYOUT, + "search_button" + ] slidingDialogAnimation = resourceMappings[ STYLE, "SlidingDialogAnimation" diff --git a/patches/src/main/resources/music/settings/host/values/strings.xml b/patches/src/main/resources/music/settings/host/values/strings.xml index e7f6491dd..c4db3fb96 100644 --- a/patches/src/main/resources/music/settings/host/values/strings.xml +++ b/patches/src/main/resources/music/settings/host/values/strings.xml @@ -187,6 +187,8 @@ Limitations: Hides the playlist card shelf in the feed. Hide Samples shelf Hides the Samples shelf in the feed. + Hide search button + Hides the search button in the toolbar. Hide sound search button Hides the sound search button in the search bar. Hide Tap to update button