mirror of
https://github.com/revanced/revanced-patches
synced 2024-09-01 03:55:37 +02:00
feat: spotify-theme
patch (#608)
This commit is contained in:
parent
52185fbac2
commit
7ee1b78e80
@ -0,0 +1,9 @@
|
||||
package app.revanced.patches.spotify.layout.theme.annotations
|
||||
|
||||
import app.revanced.patcher.annotation.Compatibility
|
||||
import app.revanced.patcher.annotation.Package
|
||||
|
||||
@Compatibility([Package("com.spotify.music")])
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
internal annotation class ThemeCompatibility
|
@ -0,0 +1,70 @@
|
||||
package app.revanced.patches.spotify.layout.theme.patch
|
||||
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.impl.ResourceData
|
||||
import app.revanced.patcher.patch.OptionsContainer
|
||||
import app.revanced.patcher.patch.PatchOption
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patcher.patch.impl.ResourcePatch
|
||||
import app.revanced.patches.spotify.layout.theme.annotations.ThemeCompatibility
|
||||
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
||||
import org.w3c.dom.Element
|
||||
|
||||
@Patch
|
||||
@DependsOn([FixLocaleConfigErrorPatch::class])
|
||||
@Name("spotify-theme")
|
||||
@Description("Applies a custom theme.")
|
||||
@ThemeCompatibility
|
||||
@Version("0.0.1")
|
||||
class ThemePatch : ResourcePatch() {
|
||||
override fun execute(data: ResourceData): PatchResult {
|
||||
data.xmlEditor["res/values/colors.xml"].use { editor ->
|
||||
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
|
||||
|
||||
for (i in 0 until resourcesNode.childNodes.length) {
|
||||
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
|
||||
|
||||
node.textContent = when (node.getAttribute("name")) {
|
||||
"gray_7" -> backgroundColor!!
|
||||
"dark_brightaccent_background_base", "dark_base_text_brightaccent", "green_light" -> accentColor!!
|
||||
"dark_brightaccent_background_press" -> accentPressedColor!!
|
||||
else -> continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
companion object : OptionsContainer() {
|
||||
var backgroundColor: String? by option(
|
||||
PatchOption.StringOption(
|
||||
key = "backgroundColor",
|
||||
default = "@android:color/black",
|
||||
title = "Background color",
|
||||
description = "The background color. Can be a hex color or a resource reference.",
|
||||
)
|
||||
)
|
||||
var accentColor: String? by option(
|
||||
PatchOption.StringOption(
|
||||
key = "accentColor",
|
||||
default = "#ff1ed760",
|
||||
title = "Accent color",
|
||||
description = "The accent color ('spotify green' by default). Can be a hex color or a resource reference.",
|
||||
)
|
||||
)
|
||||
var accentPressedColor: String? by option(
|
||||
PatchOption.StringOption(
|
||||
key = "accentPressedColor",
|
||||
default = "#ff169c46",
|
||||
title = "Pressed accent for the dark theme",
|
||||
description = "The color when accented buttons are pressed, by default slightly darker than accent. Can be a hex color or a resource reference.",
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user