This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
generated from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(twitter): app wide material theme (replaces dim)
- Loading branch information
1 parent
d843199
commit 6ef89ae
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../org/patches/example/DynamicColorPatch.kt → .../org/patches/twitter/DynamicColorPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/kotlin/your/org/patches/twitter/MaterialThemePatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |