From c833cc3fdfa1f99d44ea6489abcd5cc4550254ad Mon Sep 17 00:00:00 2001 From: inotia00 Date: Thu, 11 May 2023 19:06:28 +0900 Subject: [PATCH] feat(youtube/custom-seekbar-color): remove patch options, integrate into settings --- .../resource/patch/SeekbarColorPatch.kt | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/resource/patch/SeekbarColorPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/resource/patch/SeekbarColorPatch.kt index 2da402916..bf346f218 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/resource/patch/SeekbarColorPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/resource/patch/SeekbarColorPatch.kt @@ -1,11 +1,13 @@ package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.resource.patch -import app.revanced.extensions.doRecursively import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.ResourceContext -import app.revanced.patcher.patch.* +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultError +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.annotation.YouTubeCompatibility @@ -28,19 +30,19 @@ class ThemePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { context.xmlEditor["res/drawable/resume_playback_progressbar_drawable.xml"].use { - it.file.doRecursively { - arrayOf("color").forEach replacement@{ replacement -> - if (it !is Element) return@replacement - - it.getAttributeNode("android:$replacement")?.let { attribute -> - if (attribute.textContent.startsWith("@color/")) - attribute.textContent = resumedProgressBarColor - } - } + val layerList = it.file.getElementsByTagName("layer-list").item(0) as Element + val progressNode = layerList.getElementsByTagName("item").item(1) as Element + if (!progressNode.getAttributeNode("android:id").value.endsWith("progress")) { + return PatchResultError("Could not find progress bar") } + val scaleNode = progressNode.getElementsByTagName("scale").item(0) as Element + val shapeNode = scaleNode.getElementsByTagName("shape").item(0) as Element + val replacementNode = it.file.createElement( + "app.revanced.integrations.patches.utils.ProgressBarDrawable") + scaleNode.replaceChild(replacementNode, shapeNode) } - /* + /** * Add settings */ SettingsPatch.addPreference( @@ -54,15 +56,4 @@ class ThemePatch : ResourcePatch { return PatchResultSuccess() } - - companion object : OptionsContainer() { - var resumedProgressBarColor: String? by option( - PatchOption.StringOption( - key = "resumedProgressBarColor", - default = "#ffff0000", - title = "Resumed progressbar color", - description = "Resumed progressbar color in playlists and history. Can be a hex color or a resource reference." - ) - ) - } }