Skip to content

Commit

Permalink
fixed issues 18 and 19
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrhak committed Jul 31, 2022
1 parent 4f8fd17 commit eac783c
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 60 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.words": [
"anydpi",
"appiconset",
"Carapacik",
"hdpi",
"Hexa",
"imageset",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.2
- Fixed generate playstore icon wrong location ([#19](https://github.com/mrrhak/icons_launcher/issues/19))
- Fixed android adaptive round icon not remove ([#18](https://github.com/mrrhak/icons_launcher/issues/18))

## 2.0.1
- Fixed bug with `adaptive_background_color` and `adaptive_round_image` on android thanks to [Carapacik](https://github.com/mrrhak/icons_launcher/pull/17)
- Improve config validation
Expand Down
53 changes: 1 addition & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,7 @@ Add your Icons Launcher configuration to your `pubspec.yaml` or create a new con

An example is shown below. More complex examples [here](https://github.com/mrrhak/icons_launcher/tree/master/example).

#### Method 1: use with pubspec.yaml

```yaml
dev_dependencies:
icons_launcher: ^2.0.1

icons_launcher:
image_path: 'assets/ic_logo_border.png'
platforms:
android:
enable: true
ios:
enable: true
```

#### Method 2: create icons_launcher.yaml at project root
#### Add config to `pubspec.yaml` or create a separate `icons_launcher.yaml`

```yaml
icons_launcher:
Expand Down Expand Up @@ -181,42 +166,6 @@ The configuration file format is the same.
---
## Example

### Use in pubspec.yaml

```yaml
dev_dependencies:
icons_launcher: ^2.0.1

icons_launcher:
image_path: 'assets/ic_logo_border.png'
platforms:
android:
enable: true
image_path: 'assets/ic_logo_border.png'
# adaptive_background_color: '#ffffff'
adaptive_background_image: 'assets/ic_background.png'
adaptive_foreground_image: 'assets/ic_foreground.png'
adaptive_round_image: 'assets/ic_logo_round.png'
ios:
enable: true
image_path: 'assets/ic_logo_rectangle.png'
web:
enable: true
image_path: 'assets/ic_logo_border.png'
favicon_path: 'assets/ic_logo_round.png'
macos:
enable: false
image_path: 'assets/ic_logo_border.png'
windows:
enable: false
image_path: 'assets/ic_logo_border.png'
linux:
enable: false
image_path: 'assets/ic_logo_border.png'
```

### Or use in custom yaml (icons_launcher.yaml)

```yaml
icons_launcher:
image_path: 'assets/ic_logo_border.png'
Expand Down
3 changes: 2 additions & 1 deletion example/flavor_app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.flavor_app">
<application android:label="@string/app_name" android:name="${applicationName}" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round">
<application android:label="@string/app_name" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round" >
<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
Expand Down
4 changes: 3 additions & 1 deletion example/simple_app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
android:label="simple_app"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round">
android:roundIcon="@mipmap/ic_launcher_round"

>
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Binary file not shown.
34 changes: 30 additions & 4 deletions lib/src/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void _saveImageAndroid(
/// Create the play store icon
void _createPlayStoreIcon(Icon image) {
final template = AndroidMipMapIconTemplate(
directoryName: _flavorHelper.androidResFolder,
directoryName: _flavorHelper.androidMainFolder,
size: 512,
);
image.saveResizedPng(template.size,
Expand Down Expand Up @@ -112,7 +112,7 @@ void _createAndroidAdaptiveIcon({
if (round != null) {
_createAdaptiveRound(androidIcons, round, isValidHexaCode(background));
} else {
_removeAndroidManifestIconLauncherRound();
_removeAdaptiveRound(androidIcons);
}
}

Expand Down Expand Up @@ -207,12 +207,27 @@ void _createAdaptiveRound(
ANDROID_ADAPTIVE_ROUND_ICON_FILE_NAME,
);
}
_createIcLauncherRoundMipMapXmlFile(backgroundIsColor);
_createAndroidManifestIconLauncherRound();
CliLogger.success(
'Generated adaptive round images',
level: CliLoggerLevel.two,
);
_createIcLauncherRoundMipMapXmlFile(backgroundIsColor);
_createAndroidManifestIconLauncherRound();
}

/// Remove the adaptive round
void _removeAdaptiveRound(List<AndroidMipMapIconTemplate> adaptiveIcons) {
for (final template in adaptiveIcons) {
final filePath =
'${_flavorHelper.androidResFolder}${template.directoryName}/$ANDROID_ADAPTIVE_ROUND_ICON_FILE_NAME';
deleteFile(filePath);
}
_removeAndroidManifestIconLauncherRound();
_removeIcLauncherRoundMipMapXmlFile();
CliLogger.success(
'Removed adaptive round images',
level: CliLoggerLevel.two,
);
}

/// Handle colors.xml file
Expand Down Expand Up @@ -325,6 +340,17 @@ void _createIcLauncherRoundMipMapXmlFile(bool backgroundIsColor) {
);
}

/// Remove ic_launcher_round.xml file
void _removeIcLauncherRoundMipMapXmlFile() {
final icRoundLauncherXmlPath =
'${_flavorHelper.androidResFolder}$ANDROID_ADAPTIVE_XML_DIR/$ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME';
deleteFile(icRoundLauncherXmlPath);
CliLogger.success(
'Removed `$ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME`',
level: CliLoggerLevel.two,
);
}

/// Create android manifest icon launcher round
void _createAndroidManifestIconLauncherRound() {
final androidManifestFile = File(ANDROID_MANIFEST_FILE);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/utils/flavor_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ part of icons_launcher_cli;
class _FlavorHelper {
_FlavorHelper(this._flavor) {
if (_flavor != null) {
_androidMainFolder = 'android/app/src/$_flavor/';
_androidResFolder = 'android/app/src/$_flavor/res/';
_iOSFlavorName = _flavor!.capitalize();
} else {
_androidMainFolder = 'android/app/src/main/';
_androidResFolder = 'android/app/src/main/res/';
_iOSFlavorName = '';
}
Expand All @@ -15,6 +17,7 @@ class _FlavorHelper {
// Android related path values
final String? _flavor;
late String _androidResFolder;
late String _androidMainFolder;

/// Get flavor name
String? get flavor {
Expand All @@ -26,6 +29,11 @@ class _FlavorHelper {
return _androidResFolder;
}

/// Get Android main folder
String get androidMainFolder {
return _androidMainFolder;
}

/// Get Android drawable folder
String get androidDrawableFolder {
return '${_androidResFolder}drawable/';
Expand Down
24 changes: 24 additions & 0 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:universal_io/io.dart';

/// Checks if the config file contains a `platform`
bool hasPlatformConfig(Map<String, dynamic> config) {
final bool isHasPlatforms = config.containsKey('platforms');
Expand Down Expand Up @@ -123,3 +125,25 @@ String getColorXmlContent(String color) {
</resources>
''';
}

/// Delete file
bool deleteFile(String filePath) {
try {
final file = File(filePath);
file.deleteSync(recursive: true);
return true;
} catch (e) {
return false;
}
}

/// Remove directory
bool removeDir(String dirPath) {
try {
final dir = Directory(dirPath);
dir.deleteSync(recursive: true);
return true;
} catch (_) {
return false;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A command-line tool that simplifies the task of updating your Flutt
maintainer: Mrr Hak
homepage: https://mrrhak.com
repository: https://github.com/mrrhak/icons_launcher
version: 2.0.1
version: 2.0.2

dependencies:
args: ^2.3.1
Expand Down

0 comments on commit eac783c

Please sign in to comment.