From 5ffed2d9348557896a41ffae6f1f6ef4894910c5 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 2 Apr 2023 18:49:00 +0900 Subject: [PATCH] refactor(wide-searchbar): add some left margin --- .../bytecode/patch/WideSearchbarPatch.kt | 4 ++- .../patch/WideSearchbarResourcePatch.kt | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/resource/patch/WideSearchbarResourcePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/bytecode/patch/WideSearchbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/bytecode/patch/WideSearchbarPatch.kt index 75cd09346..cf4303692 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/bytecode/patch/WideSearchbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/bytecode/patch/WideSearchbarPatch.kt @@ -16,6 +16,7 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.layout.general.widesearchbar.bytecode.fingerprints.* +import app.revanced.patches.youtube.layout.general.widesearchbar.resource.patch.WideSearchbarResourcePatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.GENERAL @@ -24,7 +25,8 @@ import app.revanced.util.integrations.Constants.GENERAL @Description("Replaces the search icon with a wide search bar. This will hide the YouTube logo when active.") @DependsOn( [ - SettingsPatch::class + SettingsPatch::class, + WideSearchbarResourcePatch::class ] ) @YouTubeCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/resource/patch/WideSearchbarResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/resource/patch/WideSearchbarResourcePatch.kt new file mode 100644 index 000000000..3a0b669d1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/resource/patch/WideSearchbarResourcePatch.kt @@ -0,0 +1,35 @@ +package app.revanced.patches.youtube.layout.general.widesearchbar.resource.patch + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patches.shared.annotation.YouTubeCompatibility + +@Name("enable-wide-searchbar-resource-patch") +@YouTubeCompatibility +@Version("0.0.1") +class WideSearchbarResourcePatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + context.xmlEditor["res/layout/action_bar_ringo_background.xml"].use { editor -> + val document = editor.file + + with(document.getElementsByTagName("RelativeLayout").item(0)) { + if (attributes.getNamedItem(FLAG) != null) return@with + + document.createAttribute(FLAG) + .apply { value = "8.0dip" } + .let(attributes::setNamedItem) + + } + } + + return PatchResultSuccess() + } + + private companion object { + const val FLAG = "android:paddingStart" + } +}