feat: add Hide voice search button patch

This commit is contained in:
inotia00
2023-12-02 11:51:31 +09:00
parent 894b60cbe9
commit 2b6f809ee8
4 changed files with 119 additions and 0 deletions

View File

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

View File

@ -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<String>,
private val replacements: Array<String>
) : 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"
}
}
}
}
}
}
}
}

View File

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