Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
feat(twitter): app wide material theme (replaces dim)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndusAryan committed Jan 31, 2024
1 parent d843199 commit 6ef89ae
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package your.org.patches.example
package your.org.patches.twitter

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchException
Expand Down
71 changes: 71 additions & 0 deletions src/main/kotlin/your/org/patches/twitter/MaterialThemePatch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package your.org.patches.twitter

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import java.io.FileWriter
import java.nio.file.Files

@Patch(
name = "Full Monet Theme",
description = "Replaces the Twitter Bluish Dim theme with the user's Material You 3 neutral palette.",
compatiblePackages = [CompatiblePackage("com.twitter.android")]
)
@Suppress("unused")
object MaterialThemePatch : ResourcePatch() {

override fun execute(context: ResourceContext) {
val resDirectory = context["res"]
if (!resDirectory.isDirectory) throw PatchException("The res folder can not be found.")

val valuesNightV31Directory = resDirectory.resolve("values-night-v31")
if (!valuesNightV31Directory.isDirectory) Files.createDirectories(valuesNightV31Directory.toPath())

listOf(valuesNightV31Directory).forEach { it ->
val stylesXml = it.resolve("styles.xml")

if (!stylesXml.exists()) {
FileWriter(stylesXml).use {
it.write("<?xml version=\"1.0\" encoding=\"utf-8\"?><resources></resources>")
}
}
}

context.xmlEditor["res/values-night-v31/styles.xml"].use { editor ->
val document = editor.file

val newStyle = document.createElement("style")
newStyle.setAttribute("name", "PaletteDim")
newStyle.setAttribute("parent", "@style/HorizonColorPaletteDark")

val styleItems = mapOf(
"abstractColorCellBackground" to "@color/material_dynamic_neutral10",
"abstractColorCellBackgroundTranslucent" to "@color/material_dynamic_neutral10",
"abstractColorDeepGray" to "#ff8899a6",
"abstractColorDivider" to "#ff38444d",
"abstractColorFadedGray" to "@color/material_dynamic_neutral10",
"abstractColorFaintGray" to "@color/material_dynamic_neutral10",
"abstractColorHighlightBackground" to "@color/material_dynamic_neutral20",
"abstractColorLightGray" to "#ff3d5466",
"abstractColorLink" to "@color/twitter_blue",
"abstractColorMediumGray" to "#ff6b7d8c",
"abstractColorText" to "@color/white",
"abstractColorUnread" to "#ff163043",
"abstractElevatedBackground" to "#ff1c2c3c",
"abstractElevatedBackgroundShadow" to "#1a15202b"
)

styleItems.forEach { (k, v) ->
val styleElement = document.createElement("item")

styleElement.setAttribute("name", k)
styleElement.textContent = v
newStyle.appendChild(styleElement)
}

document.getElementsByTagName("resources").item(0).appendChild(newStyle)
}
}
}

0 comments on commit 6ef89ae

Please sign in to comment.