Skip to content

Commit

Permalink
feat: spotify-theme patch (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
bogadana committed Sep 24, 2022
1 parent 0e20a17 commit 726de15
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.",
)
)
}
}

0 comments on commit 726de15

Please sign in to comment.