diff --git a/src/main/kotlin/app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch.kt b/src/main/kotlin/app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch.kt index 35764195..b9cdd13b 100644 --- a/src/main/kotlin/app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch.kt +++ b/src/main/kotlin/app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch.kt @@ -9,33 +9,40 @@ import java.io.FileWriter import java.nio.file.Files @Patch( - name = "Dynamic color", - description = "Replaces the default X (Formerly Twitter) Blue with the user's Material You palette.", + name = "Dynamic color - Monet", + description = "Replaces the default Blue accent with the user's Material You palette and Dim Theme with Full Material Design.", compatiblePackages = [CompatiblePackage("com.twitter.android")], ) @Suppress("unused") object DynamicColorPatch : ResourcePatch() { override fun execute(context: ResourceContext) { + // directories 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") + val colorsXml = resDirectory.resolve("colors.xml") + val colorsDirectory = "res/values-v31/colors.xml" + val colorsNightV31Directory = "res/values-night-v31/colors.xml" + val stylesXml = resDirectory.resolve("styles.xml") + val stylesNightV31Directory = "res/values-night-v31/styles.xml" - if (!colorsXml.exists()) { - FileWriter(colorsXml).use { - it.write("") - } + when { + !resDirectory.isDirectory -> throw PatchException("The res folder can not be found.") + !valuesV31Directory.isDirectory -> Files.createDirectories(valuesV31Directory.toPath()) + !valuesNightV31Directory.isDirectory -> Files.createDirectories( + valuesNightV31Directory.toPath() + ) + !stylesXml.exists() -> FileWriter(stylesXml).write( + "" + ) + !colorsXml.exists() -> listOf(valuesV31Directory, valuesNightV31Directory).forEach { _ -> + FileWriter(colorsXml).write( + "" + ) } } - context.xmlEditor["res/values-v31/colors.xml"].use { editor -> + context.xmlEditor[colorsDirectory].use { editor -> val document = editor.file mapOf( @@ -57,7 +64,7 @@ object DynamicColorPatch : ResourcePatch() { } } - context.xmlEditor["res/values-night-v31/colors.xml"].use { editor -> + context.xmlEditor[colorsNightV31Directory].use { editor -> val document = editor.file mapOf( @@ -76,5 +83,43 @@ object DynamicColorPatch : ResourcePatch() { document.getElementsByTagName("resources").item(0).appendChild(colorElement) } } + + /** fun fullMaterialDesign() { **/ + // backward compatible, creates style into v31 res dir (A12+) + // replace parts of DimTheme with user's material 3 neutral palette + context.xmlEditor[stylesNightV31Directory].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) + } } }