Skip to content

Commit

Permalink
fix: Not creating values-night-v31 dir
Browse files Browse the repository at this point in the history
  • Loading branch information
crimera committed Apr 17, 2024
1 parent 8231c92 commit e3f3491
Showing 1 changed file with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,26 @@ import java.nio.file.Files
@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")
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"

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(
"<?xml version=\"1.0\" encoding=\"utf-8\"?><resources></resources>"
)
!colorsXml.exists() -> listOf(valuesV31Directory, valuesNightV31Directory).forEach { _ ->
FileWriter(colorsXml).write(
"<?xml version=\"1.0\" encoding=\"utf-8\"?><resources></resources>"
)
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[colorsDirectory].use { editor ->
context.xmlEditor["res/values-v31/colors.xml"].use { editor ->
val document = editor.file

mapOf(
Expand All @@ -64,7 +57,7 @@ object DynamicColorPatch : ResourcePatch() {
}
}

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

mapOf(
Expand All @@ -87,7 +80,7 @@ object DynamicColorPatch : ResourcePatch() {
/** 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 ->
context.xmlEditor["res/values-night-v31/colors.xml"].use { editor ->
val document = editor.file

val newStyle = document.createElement("style")
Expand Down

0 comments on commit e3f3491

Please sign in to comment.