Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[auth] Implemented custom icon widget

Aman Raj0e80508f6200
diff --git a/auth/lib/ui/utils/icon_utils.dart b/auth/lib/ui/utils/icon_utils.dart
index ffc41699a1..c8ea210ea6 100644
--- a/auth/lib/ui/utils/icon_utils.dart
+++ b/auth/lib/ui/utils/icon_utils.dart
@@ -23,6 +23,55 @@ class IconUtils {
await _loadJson();
}
+ Map<String, AllIconData> getAllIcons() {
+ final allIcons = <String, AllIconData>{};
+
+ final simpleIterator = _simpleIcons.entries.iterator;
+ final customIterator = _customIcons.entries.iterator;
+
+ var simpleEntry = simpleIterator.moveNext() ? simpleIterator.current : null;
+ var customEntry = customIterator.moveNext() ? customIterator.current : null;
+
+ while (simpleEntry != null && customEntry != null) {
+ if (simpleEntry.key.compareTo(customEntry.key) <= 0) {
+ allIcons[simpleEntry.key] = AllIconData(
+ title: simpleEntry.key,
+ type: IconType.simpleIcon,
+ color: simpleEntry.value,
+ );
+ simpleEntry = simpleIterator.moveNext() ? simpleIterator.current : null;
+ } else {
+ allIcons[customEntry.key] = AllIconData(
+ title: customEntry.key,
+ type: IconType.customIcon,
+ color: customEntry.value.color,
+ slug: customEntry.value.slug,
+ );
+ customEntry = customIterator.moveNext() ? customIterator.current : null;
+ }
+ }
+
+ while (simpleEntry != null) {
+ allIcons[simpleEntry.key] = AllIconData(
+ title: simpleEntry.key,
+ type: IconType.simpleIcon,
+ color: simpleEntry.value,
+ );
+ simpleEntry = simpleIterator.moveNext() ? simpleIterator.current : null;
+ }
+
+ while (customEntry != null) {
+ allIcons[customEntry.key] = AllIconData(
+ title: customEntry.key,
+ type: IconType.customIcon,
+ color: customEntry.value.color,
+ slug: customEntry.value.slug,
+ );
+ customEntry = customIterator.moveNext() ? customIterator.current : null;
+ }
+ return allIcons;
+ }
+
Widget getIcon(
BuildContext context,
String provider, {
@@ -30,10 +79,14 @@ class IconUtils {
}) {
final providerTitle = _getProviderTitle(provider);
final List<String> titlesList = [providerTitle];
- titlesList.addAll(_titleSplitCharacters.where((char) => providerTitle.contains(char)).map((char) => providerTitle.split(char)[0]));
- for(final title in titlesList){
+ titlesList.addAll(
+ _titleSplitCharacters
+ .where((char) => providerTitle.contains(char))
+ .map((char) => providerTitle.split(char)[0]),
+ );
+ for (final title in titlesList) {
if (_customIcons.containsKey(title)) {
- return _getSVGIcon(
+ return getSVGIcon(
"assets/custom-icons/icons/${_customIcons[title]!.slug ?? title}.svg",
title,
_customIcons[title]!.color,
@@ -41,7 +94,7 @@ class IconUtils {
context,
);
} else if (_simpleIcons.containsKey(title)) {
- return _getSVGIcon(
+ return getSVGIcon(
"assets/simple-icons/icons/$title.svg",
title,
_simpleIcons[title],
@@ -55,7 +108,8 @@ class IconUtils {
return CircleAvatar(
radius: width / 2,
backgroundColor: getEnteColorScheme(context).avatarColors[
- providerTitle.hashCode % getEnteColorScheme(context).avatarColors.length],
+ providerTitle.hashCode %
+ getEnteColorScheme(context).avatarColors.length],
child: Text(
providerTitle.toUpperCase()[0],
// fixed color
@@ -69,7 +123,7 @@ class IconUtils {
}
}
- Widget _getSVGIcon(
+ Widget getSVGIcon(
String path,
String title,
String? color,
@@ -137,9 +191,8 @@ class IconUtils {
);
if (icon["altNames"] != null) {
for (final name in icon["altNames"]) {
- _customIcons[name.toString()
- .replaceAll(' ', '')
- .toLowerCase()] = CustomIconData(
+ _customIcons[name.toString().replaceAll(' ', '').toLowerCase()] =
+ CustomIconData(
icon["slug"],
icon["hex"],
);
@@ -162,3 +215,19 @@ class CustomIconData {
CustomIconData(this.slug, this.color);
}
+
+enum IconType { simpleIcon, customIcon }
+
+class AllIconData {
+ final String title;
+ final IconType type;
+ final String? color;
+ final String? slug;
+
+ AllIconData({
+ required this.title,
+ required this.type,
+ required this.color,
+ this.slug,
+ });
+}