Skip to content

Commit

Permalink
Adaptive icons working again
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkOSullivan94 committed Jun 19, 2018
1 parent 022c5e6 commit a49067d
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,47 @@ createAdaptiveIcons(config) {
// If not copy over empty template
colorsXml.exists().then((bool isExistingFile) {
if (!isExistingFile) {
print("Copying colors.xml template to project");
new File(android_colors_file).create(recursive: true).then((File colors_file) {
colors_file.writeAsString(XmlTemplate.colors_xml);
});
createNewColorsFile(background_color);
} else {
// Write foreground color
List<String> lines = colorsXml.readAsLinesSync();
bool foundExisting = false;
for (var x = 0; x < lines.length; x++) {
String line = lines[x];
if (line.contains("name=\"ic_launcher_background\"")) {
print("Found existing background color value");
foundExisting = true;
line = line.replaceAll(new RegExp('>(.*)<'), ">$background_color<");
lines[x] = line;
break;
}
}

// Add new line if we didn't find an existing value
if(!foundExisting){
print("Adding new background color value");
lines.insert(lines.length-1, "\t<color name=\"ic_launcher_background\">${background_color}</color>");
}

colorsXml.writeAsStringSync(lines.join("\n"));
updateColorsFile(colorsXml, background_color);
}
});
}

createNewColorsFile(String backgroundColor) {
print("Copying colors.xml template to project");
new File(android_colors_file).create(recursive: true).then((File colors_file) {
colors_file.writeAsString(XmlTemplate.colors_xml).then((File file) {
updateColorsFile(colors_file, backgroundColor);
});
});
}

updateColorsFile(File colorsFile, String backgroundColor) {

// Write foreground color
List<String> lines = colorsFile.readAsLinesSync();
bool foundExisting = false;
for (var x = 0; x < lines.length; x++) {
String line = lines[x];
if (line.contains("name=\"ic_launcher_background\"")) {
print("Found existing background color value");
foundExisting = true;
line = line.replaceAll(new RegExp('>(.*)<'), ">$backgroundColor<");
lines[x] = line;
break;
}
}

// Add new line if we didn't find an existing value
if(!foundExisting){
print("Adding new background color value");
lines.insert(lines.length-1, "\t<color name=\"ic_launcher_background\">${backgroundColor}</color>");
}

colorsFile.writeAsStringSync(lines.join("\n"));
}

/**
* Ensures the correct path is used for generating adaptive icons
*
Expand Down

0 comments on commit a49067d

Please sign in to comment.