Skip to content

Commit

Permalink
Unit tests added for android.dart. Fixed directory path for adaptive …
Browse files Browse the repository at this point in the history
…icons.
  • Loading branch information
MarkOSullivan94 committed Jun 19, 2018
1 parent 35d1843 commit 022c5e6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 0.5.2 (19th June 2018)

- Previous release didn't fix adaptive icons, just prevented the error message from appearing. This should hopefully fix it!

# 0.5.1 (18th June 2018)

- Fix for adaptive icons
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dev_dependencies:
flutter_test:
sdk: flutter

flutter_launcher_icons: "^0.5.1"
flutter_launcher_icons: "^0.5.2"
```
2. Within the same pubspec.yaml file, add flutter_icons config section.
Expand All @@ -35,7 +35,7 @@ dev_dependencies:
flutter_test:
sdk: flutter

flutter_launcher_icons: "^0.5.1"
flutter_launcher_icons: "^0.5.2"

flutter_icons:
android: true
Expand Down
41 changes: 29 additions & 12 deletions lib/android.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';
import 'package:xml/xml.dart';
import 'package:flutter_launcher_icons/xml_templates.dart' as XmlTemplate;
import 'package:image/image.dart';

Expand All @@ -9,7 +8,7 @@ const String android_manifest_file = "android/app/src/main/AndroidManifest.xml";
const String android_gradle_file = "android/app/build.gradle";
const String android_file_name = "ic_launcher.png";
const String android_adaptive_foreground_file_name = "ic_launcher_foreground.png";
const String android_adaptive_xml_folder = android_res_folder + "mipmap-v26/";
const String android_adaptive_xml_folder = android_res_folder + "mipmap-anydpi-v26/";
const String default_icon_name = "ic_launcher";

class AndroidIcon {
Expand Down Expand Up @@ -62,20 +61,23 @@ createAdaptiveIcons(config) {

// Create foreground images
adaptive_foreground_icons.forEach((AndroidIcon e) => overwriteExistingIcons(e, foreground_image, android_adaptive_foreground_file_name));

// Generate ic_launcher.xml
// If is using a string for android config, generate <file_name>.xml
// Otherwise use ic_launcher.xml
if (isCustomAndroidFile(config)) {
new File(android_adaptive_xml_folder + getNewIconName(config)
+ '.xml').create(recursive: true).then((File adaptive_icon) {
adaptive_icon.writeAsString(XmlTemplate.ic_launcher_xml);
});
if (isCorrectMipmapDirectoryForAdaptiveIcon(android_adaptive_xml_folder)) {
if (isCustomAndroidFile(config)) {
new File(android_adaptive_xml_folder + getNewIconName(config)
+ '.xml').create(recursive: true).then((File adaptive_icon) {
adaptive_icon.writeAsString(XmlTemplate.ic_launcher_xml);
});
} else {
new File(android_adaptive_xml_folder + default_icon_name + '.xml')
.create(recursive: true).then((File adaptive_icon) {
adaptive_icon.writeAsString(XmlTemplate.ic_launcher_xml);
});
}
} else {
new File(android_adaptive_xml_folder + default_icon_name + '.xml')
.create(recursive: true).then((File adaptive_icon) {
adaptive_icon.writeAsString(XmlTemplate.ic_launcher_xml);
});
print("Error: Unable to generate adaptive icon");
}

// Check if colors.xml exists in the project
Expand Down Expand Up @@ -113,6 +115,21 @@ createAdaptiveIcons(config) {
});
}

/**
* Ensures the correct path is used for generating adaptive icons
*
* "Next you must create alternative drawable resources in your app for use with
* Android 8.0 (API level 26) in res/mipmap-anydpi/ic_launcher.xml"
* Source: https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive
*/
bool isCorrectMipmapDirectoryForAdaptiveIcon(String path) {
if (path != "android/app/src/main/res/mipmap-anydpi-v26/") {
return false;
} else {
return true;
}
}

// Check to see if specified Android config is a string or bool
// String - Generate new launcher icon with the string specified
// bool - override the default flutter project icon
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_launcher_icons
description: A package which simplifies the task of updating your Flutter app's launcher icon. Fully flexible, allowing you to choose what platform you wish to update the launcher icon for and if you want, the option to keep your old launcher icon in case you want to revert back sometime in the future.
version: 0.5.1
version: 0.5.2
homepage: https://github.com/franzsilva/flutter_launcher_icons
authors:
- Franz Silva <[email protected]>
Expand Down
34 changes: 34 additions & 0 deletions test/android_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:test/test.dart';
import 'package:flutter_launcher_icons/android.dart' as Android;

/**
* Unit tests for android.dart
*/

void main() {
test('Adaptive icon mipmap path is correct', () {
String path1 = "android/app/src/main/res/";
String path2 = "mipmap-anydpi-v26/";
expect(Android.isCorrectMipmapDirectoryForAdaptiveIcon(path1), false);
expect(Android.isCorrectMipmapDirectoryForAdaptiveIcon(path2), false);
expect(Android.isCorrectMipmapDirectoryForAdaptiveIcon(Android.android_adaptive_xml_folder), true);
});

test('Correct number of adaptive foreground icons', () {
expect(Android.adaptive_foreground_icons.length, 5);
});

test('Correct number of android launcher icons', () {
expect(Android.android_icons.length, 5);
});

test('Config contains string for generating new launcher icons', () {
Map flutter_icons_config = {"image_path": "assets/images/icon-710x599.png",
"android": true, "ios": true};
expect(Android.isCustomAndroidFile(flutter_icons_config), false);

Map flutter_icons_new_icon_config = {"image_path": "assets/images/icon-710x599.png",
"android": "New Icon", "ios": true};
expect(Android.isCustomAndroidFile(flutter_icons_new_icon_config), true);
});
}
4 changes: 4 additions & 0 deletions test/flutter_icons_test.dart → test/main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import 'package:flutter_launcher_icons/ios.dart' as IOS;
import 'package:flutter_launcher_icons/android.dart' as Android;
import 'package:flutter_launcher_icons/main.dart' as Main;

/**
* Unit tests for main.dart
*/

void main() {
test('iOS icon list is correct size', () {
expect(IOS.ios_icons.length, 15);
Expand Down

0 comments on commit 022c5e6

Please sign in to comment.