mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 15:30:40 +00:00
[auth] Bugfix/auth icons with period (#3559)
## Description Previously it would check if the substring that precedes the first `.` or `(` of the lowercase spaceless provider title was a valid icon. Now: 1. Checks if lowercase spaceless provider title is valid icon 2. If the title contains a `(` it checks if the preceding part of the title is a valid icon 3. If the title contains a `.` it checks if the preceding part of the title is a valid icon | Provider Title | Previous Check | Now Checks | | -------- | ------- | ----------| | Login.gov | `login` ❌| `login.gov` ✅ | | GOV.UK (Brian) | `gov` ❌| `gov.uk(brian)`❌ then `gov.uk` ✅ | | PayPal.com (Visa) | `paypal` ✅ | `paypal.com(visa)` ❌ then `paypal.com` ❌ then `paypal` ✅| | Amazon.com | `amazon` ✅ | `amazon.com` ❌ then `amazon` ✅| This PR resolves issue #3473
This commit is contained in:
parent
607dfadb00
commit
6f5c1b8e3f
@ -17,6 +17,7 @@ class IconUtils {
|
|||||||
final Map<String, CustomIconData> _customIcons = {};
|
final Map<String, CustomIconData> _customIcons = {};
|
||||||
// Map of icon-color to its luminance
|
// Map of icon-color to its luminance
|
||||||
final Map<Color, double> _colorLuminance = {};
|
final Map<Color, double> _colorLuminance = {};
|
||||||
|
final List<String> _titleSplitCharacters = ['(', '.'];
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await _loadJson();
|
await _loadJson();
|
||||||
@ -27,31 +28,36 @@ class IconUtils {
|
|||||||
String provider, {
|
String provider, {
|
||||||
double width = 24,
|
double width = 24,
|
||||||
}) {
|
}) {
|
||||||
final title = _getProviderTitle(provider);
|
final providerTitle = _getProviderTitle(provider);
|
||||||
if (_customIcons.containsKey(title)) {
|
final List<String> titlesList = [providerTitle];
|
||||||
return _getSVGIcon(
|
titlesList.addAll(_titleSplitCharacters.where((char) => providerTitle.contains(char)).map((char) => providerTitle.split(char)[0]));
|
||||||
"assets/custom-icons/icons/${_customIcons[title]!.slug ?? title}.svg",
|
for(final title in titlesList){
|
||||||
title,
|
if (_customIcons.containsKey(title)) {
|
||||||
_customIcons[title]!.color,
|
return _getSVGIcon(
|
||||||
width,
|
"assets/custom-icons/icons/${_customIcons[title]!.slug ?? title}.svg",
|
||||||
context,
|
title,
|
||||||
);
|
_customIcons[title]!.color,
|
||||||
} else if (_simpleIcons.containsKey(title)) {
|
width,
|
||||||
return _getSVGIcon(
|
context,
|
||||||
"assets/simple-icons/icons/$title.svg",
|
);
|
||||||
title,
|
} else if (_simpleIcons.containsKey(title)) {
|
||||||
_simpleIcons[title],
|
return _getSVGIcon(
|
||||||
width,
|
"assets/simple-icons/icons/$title.svg",
|
||||||
context,
|
title,
|
||||||
);
|
_simpleIcons[title],
|
||||||
} else if (title.isNotEmpty) {
|
width,
|
||||||
|
context,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (providerTitle.isNotEmpty) {
|
||||||
bool showLargeIcon = width > 24;
|
bool showLargeIcon = width > 24;
|
||||||
return CircleAvatar(
|
return CircleAvatar(
|
||||||
radius: width / 2,
|
radius: width / 2,
|
||||||
backgroundColor: getEnteColorScheme(context).avatarColors[
|
backgroundColor: getEnteColorScheme(context).avatarColors[
|
||||||
title.hashCode % getEnteColorScheme(context).avatarColors.length],
|
providerTitle.hashCode % getEnteColorScheme(context).avatarColors.length],
|
||||||
child: Text(
|
child: Text(
|
||||||
title.toUpperCase()[0],
|
providerTitle.toUpperCase()[0],
|
||||||
// fixed color
|
// fixed color
|
||||||
style: showLargeIcon
|
style: showLargeIcon
|
||||||
? getEnteTextTheme(context).h3Bold.copyWith(color: Colors.white)
|
? getEnteTextTheme(context).h3Bold.copyWith(color: Colors.white)
|
||||||
@ -146,7 +152,7 @@ class IconUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _getProviderTitle(String provider) {
|
String _getProviderTitle(String provider) {
|
||||||
return provider.split(RegExp(r'[.(]'))[0].replaceAll(' ', '').toLowerCase();
|
return provider.replaceAll(' ', '').toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user