feat(YouTube Music - Hide layout components): Add Hide search button setting https://github.com/inotia00/ReVanced_Extended/issues/2850

This commit is contained in:
inotia00 2025-03-24 20:51:43 +09:00
parent 98f2e99061
commit 6dfd88c75e
6 changed files with 53 additions and 4 deletions

View File

@ -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 {
* <p>
* 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
* <a href="https://stackoverflow.com/a/4604145">Reference</a>
* <p>
* That's why {@link AlertDialog#show()} is absolutely necessary.
* Instead, use two tricks to hide Alertdialog.

View File

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

View File

@ -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",

View File

@ -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<OneRegisterInstruction>(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,

View File

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

View File

@ -187,6 +187,8 @@ Limitations:
<string name="revanced_hide_playlist_card_shelf_summary">Hides the playlist card shelf in the feed.</string>
<string name="revanced_hide_samples_shelf_title">Hide Samples shelf</string>
<string name="revanced_hide_samples_shelf_summary">Hides the Samples shelf in the feed.</string>
<string name="revanced_hide_search_button_title">Hide search button</string>
<string name="revanced_hide_search_button_summary">Hides the search button in the toolbar.</string>
<string name="revanced_hide_sound_search_button_title">Hide sound search button</string>
<string name="revanced_hide_sound_search_button_summary">Hides the sound search button in the search bar.</string>
<string name="revanced_hide_tap_to_update_button_title">Hide Tap to update button</string>