TF-275 Fix bug reload changes colors
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
|
||||
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';
|
||||
@@ -28,7 +26,6 @@ class PresentationEmail with EquatableMixin {
|
||||
final Map<MailboxId, bool>? mailboxIds;
|
||||
final List<MailboxName?>? mailboxNames;
|
||||
final SelectMode selectMode;
|
||||
final List<Color>? avatarColors;
|
||||
|
||||
PresentationEmail(
|
||||
this.id,
|
||||
@@ -48,7 +45,6 @@ class PresentationEmail with EquatableMixin {
|
||||
this.mailboxIds,
|
||||
this.mailboxNames,
|
||||
this.selectMode = SelectMode.INACTIVE,
|
||||
this.avatarColors,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
@@ -45,7 +43,7 @@ extension EmailExtension on Email {
|
||||
);
|
||||
}
|
||||
|
||||
PresentationEmail toPresentationEmail({SelectMode selectMode = SelectMode.INACTIVE, List<Color>? avatarColors}) {
|
||||
PresentationEmail toPresentationEmail({SelectMode selectMode = SelectMode.INACTIVE}) {
|
||||
return PresentationEmail(
|
||||
id,
|
||||
keywords: keywords,
|
||||
@@ -62,7 +60,6 @@ extension EmailExtension on Email {
|
||||
replyTo: replyTo,
|
||||
mailboxIds: mailboxIds,
|
||||
selectMode: selectMode,
|
||||
avatarColors: avatarColors,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'dart:math';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
@@ -6,9 +6,26 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
extension PresentationEmailExtension on PresentationEmail {
|
||||
|
||||
List<Color> get avatarColors {
|
||||
return AppColor.mapGradientColor[_generateIndexFromSender()];
|
||||
}
|
||||
|
||||
int _generateIndexFromSender() {
|
||||
if (from != null && from?.isNotEmpty == true) {
|
||||
final codeUnits = from?.first.email?.codeUnits ?? List.empty();
|
||||
if (codeUnits.isNotEmpty) {
|
||||
final sumCodeUnits = codeUnits.sum;
|
||||
final index = sumCodeUnits % AppColor.mapGradientColor.length;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int numberOfAllEmailAddress() => to.numberEmailAddress() + cc.numberEmailAddress() + bcc.numberEmailAddress();
|
||||
|
||||
String getReceivedAt(String newLocale, {String? pattern}) {
|
||||
@@ -39,7 +56,6 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
mailboxIds: mailboxIds,
|
||||
mailboxNames: mailboxNames,
|
||||
selectMode: selectMode == SelectMode.INACTIVE ? SelectMode.ACTIVE : SelectMode.INACTIVE,
|
||||
avatarColors: avatarColors,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,7 +77,6 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
mailboxIds: mailboxIds,
|
||||
mailboxNames: mailboxNames,
|
||||
selectMode: selectMode,
|
||||
avatarColors: avatarColors,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -113,7 +128,7 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
}
|
||||
}
|
||||
|
||||
PresentationEmail toSearchPresentationEmail(Map<MailboxId, PresentationMailbox> mapMailboxes, Random random) {
|
||||
PresentationEmail toSearchPresentationEmail(Map<MailboxId, PresentationMailbox> mapMailboxes) {
|
||||
mailboxIds?.removeWhere((key, value) => !value);
|
||||
|
||||
final listMailboxId = mailboxIds?.entries
|
||||
@@ -126,8 +141,6 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
.where((mailboxName) => mailboxName != null)
|
||||
.toList();
|
||||
|
||||
final newAvatarColors = AppColor.mapGradientColor[random.nextInt(AppColor.mapGradientColor.length)];
|
||||
|
||||
return PresentationEmail(
|
||||
this.id,
|
||||
keywords: keywords,
|
||||
@@ -145,31 +158,6 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
mailboxIds: mailboxIds,
|
||||
mailboxNames: listMailboxName,
|
||||
selectMode: selectMode,
|
||||
avatarColors: avatarColors ?? newAvatarColors
|
||||
);
|
||||
}
|
||||
|
||||
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