feat: add amoled patch

This commit is contained in:
epicsampler 2022-05-22 14:31:17 +00:00 committed by GitHub
parent a173f6e5a7
commit d61bac4f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View File

@ -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

View File

@ -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()
}
}