TF-248 Change avatar of item list email
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
|
||||
@@ -26,6 +28,7 @@ class PresentationEmail with EquatableMixin {
|
||||
final Map<MailboxId, bool>? mailboxIds;
|
||||
final List<MailboxName?>? mailboxNames;
|
||||
final SelectMode selectMode;
|
||||
final List<Color>? avatarColors;
|
||||
|
||||
PresentationEmail(
|
||||
this.id,
|
||||
@@ -44,7 +47,8 @@ class PresentationEmail with EquatableMixin {
|
||||
this.replyTo,
|
||||
this.mailboxIds,
|
||||
this.mailboxNames,
|
||||
this.selectMode = SelectMode.INACTIVE
|
||||
this.selectMode = SelectMode.INACTIVE,
|
||||
this.avatarColors,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -52,9 +56,26 @@ class PresentationEmail with EquatableMixin {
|
||||
|
||||
String getAvatarText() {
|
||||
if (getSenderName().isNotEmpty) {
|
||||
final regexLetter = RegExp("([A-Za-z])");
|
||||
final firstLetter = regexLetter.firstMatch(getSenderName().trim())?.group(0);
|
||||
return firstLetter != null ? firstLetter.toUpperCase() : '';
|
||||
final listWord = getSenderName().split(' ');
|
||||
if (listWord.length > 1) {
|
||||
final regexLetter = RegExp("([A-Za-z])");
|
||||
final firstLetterOfFirstWord = regexLetter.firstMatch(listWord[0].trim())?.group(0);
|
||||
final firstLetterOfSecondWord = regexLetter.firstMatch(listWord[1].trim())?.group(0);
|
||||
|
||||
if (firstLetterOfFirstWord != null && firstLetterOfSecondWord != null) {
|
||||
return '${firstLetterOfFirstWord.toUpperCase()}${firstLetterOfSecondWord.toUpperCase()}';
|
||||
} else if (firstLetterOfFirstWord != null && firstLetterOfSecondWord == null) {
|
||||
return '${firstLetterOfFirstWord.toUpperCase()}${firstLetterOfFirstWord.toUpperCase()}';
|
||||
} else if (firstLetterOfFirstWord == null && firstLetterOfSecondWord != null) {
|
||||
return '${firstLetterOfSecondWord.toUpperCase()}${firstLetterOfSecondWord.toUpperCase()}';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
final regexLetter = RegExp("([A-Za-z])");
|
||||
final firstLetter = regexLetter.firstMatch(getSenderName().trim())?.group(0);
|
||||
return firstLetter != null ? '${firstLetter.toUpperCase()}${firstLetter.toUpperCase()}' : '';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
@@ -136,7 +138,32 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
replyTo: replyTo,
|
||||
mailboxIds: mailboxIds,
|
||||
mailboxNames: listMailboxName,
|
||||
selectMode: selectMode
|
||||
selectMode: selectMode,
|
||||
avatarColors: avatarColors
|
||||
);
|
||||
}
|
||||
|
||||
PresentationEmail asAvatarGradientColor(Random random) {
|
||||
final newAvatarColors = AppColor.mapGradientColor[random.nextInt(AppColor.mapGradientColor.length)];
|
||||
|
||||
return PresentationEmail(
|
||||
this.id,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
hasAttachment: hasAttachment,
|
||||
preview: preview,
|
||||
subject: subject,
|
||||
sentAt: sentAt,
|
||||
from: from,
|
||||
to: to,
|
||||
cc: cc,
|
||||
bcc: bcc,
|
||||
replyTo: replyTo,
|
||||
mailboxIds: mailboxIds,
|
||||
mailboxNames: mailboxNames,
|
||||
selectMode: selectMode,
|
||||
avatarColors: avatarColors ?? newAvatarColors,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user