Skip to content

Commit

Permalink
feat: add amoled patch
Browse files Browse the repository at this point in the history
  • Loading branch information
epicsampler committed May 22, 2022
1 parent a173f6e commit d61bac4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.revanced.patches.youtube.layout.amoled.annotations

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[Package(
"com.google.android.youtube", arrayOf("17.14.35", "17.17.34")
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class AmoledCompatibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package app.revanced.patches.youtube.layout.amoled.patch

import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.ResourceData
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.ResourcePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patches.youtube.layout.amoled.annotations.AmoledCompatibility
import org.w3c.dom.Element
import java.io.File

@Patch
@Name("amoled")
@Description("Enables black theme (amoled mode)")
@AmoledCompatibility
@Version("0.0.1")
class AmoledPatch : ResourcePatch() {
override fun execute(data: ResourceData): PatchResult {
data.getXmlEditor("res${File.separator}values${File.separator}colors.xml").use { editor ->
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element

for (i in 0..resourcesNode.childNodes.length) {
val node = resourcesNode.childNodes.item(i) as Element

node.nodeValue = when (node.getAttribute("name")) {
"yt_black1",
"yt_black1_opacity95",
"yt_black2",
"yt_black3",
"yt_black4",
"yt_status_bar_background_dark"
-> "@android:color/black"
"yt_selected_nav_label_dark"
-> "#ffdf0000"
else -> continue
}
}
}

return PatchResultSuccess()
}
}

0 comments on commit d61bac4

Please sign in to comment.