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
### Features

* **twitter:** app wide material theme (replaces dim) ([6ef89ae](6ef89ae))
  • Loading branch information
IndusAryan authored Jan 31, 2024
1 parent 9dfd3a4 commit b1446d2
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 1 deletion.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [1.0.0-dev.2](https://github.com/IndusAryan/twitter-patches/compare/v1.0.0-dev.1...v1.0.0-dev.2) (2024-01-31)


### Features

* **twitter:** app wide material theme (replaces dim) ([6ef89ae](https://github.com/IndusAryan/twitter-patches/commit/6ef89ae9c6a2aa48ea08fc61114ca249a1469e90))

# 1.0.0-dev.1 (2024-01-31)


### Bug Fixes

* **twitter:** more better description ([d843199](https://github.com/IndusAryan/twitter-patches/commit/d843199fd2d286760fb6420f471bdc73778c2650))

# 1.0.0 (2024-01-26)


Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.parallel = true
org.gradle.caching = true
kotlin.code.style = official
version = 1.0.0
version = 1.0.0-dev.2
80 changes: 80 additions & 0 deletions src/main/kotlin/your/org/patches/twitter/DynamicColorPatch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 = "Dynamic color",
description = "Replaces the default X (Twitter) Blue signature theme with the user's Material You palette.",
compatiblePackages = [CompatiblePackage("com.twitter.android")]
)
@Suppress("unused")
object DynamicColorPatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
val resDirectory = context["res"]
if (!resDirectory.isDirectory) throw PatchException("The res folder can not be found.")

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

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

listOf(valuesV31Directory, valuesNightV31Directory).forEach { it ->
val colorsXml = it.resolve("colors.xml")

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

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

mapOf(
"ps__twitter_blue" to "@color/twitter_blue",
"ps__twitter_blue_pressed" to "@color/twitter_blue_fill_pressed",
"twitter_blue" to "@android:color/system_accent1_400",
"twitter_blue_fill_pressed" to "@android:color/system_accent1_300",
"twitter_blue_opacity_30" to "@android:color/system_accent1_100",
"twitter_blue_opacity_50" to "@android:color/system_accent1_200",
"twitter_blue_opacity_58" to "@android:color/system_accent1_300",
"deep_transparent_twitter_blue" to "@android:color/system_accent1_200"
).forEach { (k, v) ->
val colorElement = document.createElement("color")

colorElement.setAttribute("name", k)
colorElement.textContent = v

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

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

mapOf(
"twitter_blue" to "@android:color/system_accent1_200",
"twitter_blue_fill_pressed" to "@android:color/system_accent1_300",
"twitter_blue_opacity_30" to "@android:color/system_accent1_50",
"twitter_blue_opacity_50" to "@android:color/system_accent1_100",
"twitter_blue_opacity_58" to "@android:color/system_accent1_200",
"deep_transparent_twitter_blue" to "@android:color/system_accent1_200"
).forEach { (k, v) ->
val colorElement = document.createElement("color")

colorElement.setAttribute("name", k)
colorElement.textContent = v

document.getElementsByTagName("resources").item(0).appendChild(colorElement)
}
}
}
}
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 b1446d2

Please sign in to comment.