diff --git a/src/main/kotlin/app/revanced/patches/music/general/voicesearch/VoiceSearchButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/voicesearch/VoiceSearchButtonPatch.kt new file mode 100644 index 000000000..588891417 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/general/voicesearch/VoiceSearchButtonPatch.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.music.general.voicesearch + +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.shared.patch.voicesearch.AbstractVoiceSearchButtonPatch + +@Patch( + name = "Hide voice search button", + description = "Hide voice search button in search bar.", + compatiblePackages = [CompatiblePackage("com.google.android.apps.youtube.music")], + use = false +) +@Suppress("unused") +object VoiceSearchButtonPatch : AbstractVoiceSearchButtonPatch( + arrayOf("search_toolbar_view.xml"), + arrayOf("height", "width") +) diff --git a/src/main/kotlin/app/revanced/patches/shared/patch/voicesearch/AbstractVoiceSearchButtonPatch.kt b/src/main/kotlin/app/revanced/patches/shared/patch/voicesearch/AbstractVoiceSearchButtonPatch.kt new file mode 100644 index 000000000..6e9549f92 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/patch/voicesearch/AbstractVoiceSearchButtonPatch.kt @@ -0,0 +1,41 @@ +package app.revanced.patches.shared.patch.voicesearch + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.ResourcePatch +import org.w3c.dom.Element +import kotlin.io.path.exists + +abstract class AbstractVoiceSearchButtonPatch( + private val paths: Array, + private val replacements: Array +) : ResourcePatch() { + private companion object { + const val IMAGE_VIEW_TAG = "android.support.v7.widget.AppCompatImageView" + const val VOICE_SEARCH_ID = "@id/voice_search" + } + + override fun execute(context: ResourceContext) { + val resDirectory = context["res"] + + paths.forEach { path -> + val targetXmlPath = resDirectory.resolve("layout").resolve(path).toPath() + + if (targetXmlPath.exists()) { + context.xmlEditor["res/layout/$path"].use { editor -> + val document = editor.file + val imageViewTags = document.getElementsByTagName(IMAGE_VIEW_TAG) + List(imageViewTags.length) { imageViewTags.item(it) as Element } + .filter { it.getAttribute("android:id").equals(VOICE_SEARCH_ID) } + .forEach { node -> + replacements.forEach replacement@{ replacement -> + node.getAttributeNode("android:layout_$replacement")?.let { attribute -> + attribute.textContent = "0.0dip" + } + } + } + } + } + } + + } +} 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 new file mode 100644 index 000000000..298df162e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/voicesearch/VoiceSearchButtonPatch.kt @@ -0,0 +1,60 @@ +package app.revanced.patches.youtube.layout.voicesearch + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.shared.patch.voicesearch.AbstractVoiceSearchButtonPatch +import app.revanced.patches.youtube.utils.settings.SettingsPatch + +@Patch( + name = "Hide voice search button", + description = "Hide voice search button in search bar.", + dependencies = [SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.25.40", + "18.27.36", + "18.29.38", + "18.30.37", + "18.31.40", + "18.32.39", + "18.33.40", + "18.34.38", + "18.35.36", + "18.36.39", + "18.37.36", + "18.38.44", + "18.39.41", + "18.40.34", + "18.41.39", + "18.42.41", + "18.43.45", + "18.44.41", + "18.45.43" + ] + ) + ], + use = false +) +@Suppress("unused") +object VoiceSearchButtonPatch : AbstractVoiceSearchButtonPatch( + 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", + "width" + ) +) { + override fun execute(context: ResourceContext) { + super.execute(context) + + SettingsPatch.updatePatchStatus("Hide voice search button") + } +} diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index c11812d96..43d4fc435 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -479,6 +479,7 @@ +