Add object for model and core module

This commit is contained in:
dab246
2021-08-18 17:43:22 +07:00
committed by Dat H. Pham
parent 063fd73fb0
commit 6b31252e7a
22 changed files with 306 additions and 26 deletions
+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M13 2H6C5.46957 2 4.96086 2.21071 4.58579 2.58579C4.21071 2.96086 4 3.46957 4 4V20C4 20.5304 4.21071 21.0391 4.58579 21.4142C4.96086 21.7893 5.46957 22 6 22H18C18.5304 22 19.0391 21.7893 19.4142 21.4142C19.7893 21.0391 20 20.5304 20 20V9L13 2Z" stroke="#3840F7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M13 2V9H20" stroke="#3840F7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 544 B

Before

Width:  |  Height:  |  Size: 293 B

After

Width:  |  Height:  |  Size: 293 B

+3
View File
@@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 1.99995L15.09 8.25995L22 9.26995L17 14.14L18.18 21.02L12 17.77L5.82 21.02L7 14.14L2 9.26995L8.91 8.25995L12 1.99995Z" fill="#FF8607" stroke="#FF8607" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 332 B

+3
View File
@@ -0,0 +1,3 @@
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4.5 9L7.5 6L4.5 3" stroke="#A2A8B5" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 217 B

+3
View File
@@ -0,0 +1,3 @@
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="6" cy="6" r="5" fill="#A2A8B5" stroke="white" stroke-width="2"/>
</svg>

After

Width:  |  Height:  |  Size: 180 B

+3
View File
@@ -0,0 +1,3 @@
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="7" cy="7" r="6" fill="#04AA11" stroke="white" stroke-width="2"/>
</svg>

After

Width:  |  Height:  |  Size: 180 B

+5
View File
@@ -3,6 +3,9 @@ library core;
// Extensions
export 'presentation/extensions/color_extension.dart';
export 'presentation/extensions/url_extension.dart';
export 'presentation/extensions/capitalize_extension.dart';
export 'presentation/extensions/list_extensions.dart';
export 'domain/extensions/datetime_extension.dart';
// Utils
export 'presentation/utils/theme_utils.dart';
@@ -19,6 +22,8 @@ export 'presentation/views/text/text_builder.dart';
export 'presentation/views/responsive/responsive_widget.dart';
export 'presentation/views/list/tree_view.dart';
export 'presentation/views/button/button_builder.dart';
export 'presentation/views/image/avatar_builder.dart';
export 'presentation/views/list/sliver_grid_delegate_fixed_height.dart';
// Resources
export 'presentation/resources/assets_paths.dart';
@@ -0,0 +1,18 @@
extension DateTimeExtension on DateTime {
bool isToday() {
final now = DateTime.now();
return now.day == this.day && now.month == this.month && now.year == this.year;
}
bool isYesterday() {
final yesterday = DateTime.now().subtract(Duration(days: 1));
return yesterday.day == this.day && yesterday.month == this.month && yesterday.year == this.year;
}
bool isThisYear() {
final now = DateTime.now();
return now.year == this.year;
}
}
@@ -0,0 +1,6 @@
extension CapitalizeExtension on String {
String get inCaps => this.length > 0 ?'${this[0].toUpperCase()}${this.substring(1)}':'';
String get allInCaps => this.toUpperCase();
String get capitalizeFirstEach => this.replaceAll(RegExp(' +'), ' ').split(" ").map((str) => str.inCaps).join(" ");
}
@@ -39,4 +39,11 @@ extension AppColor on Color {
static const bgMailboxListMail = Color(0xFFFBFBFF);
static const bgMessenger = Color(0xFFF2F2F5);
static const textButtonColor = Color(0xFF182952);
static const attachmentFileBorderColor = Color(0xFFEAEAEA);
static const attachmentFileNameColor = Color(0xFF182952);
static const attachmentFileSizeColor = Color(0xFF7E869B);
static const avatarColor = Color(0xFFE6E5FF);
static const avatarTextColor = Color(0xFF3840F7);
static const sentTimeTextColorUnRead = Color(0xFF182952);
static const subjectEmailTextColorUnRead = Color(0xFF3840F7);
}
@@ -22,10 +22,15 @@ class ImagePaths {
String get icForward => _getImagePath('ic_forward.svg');
String get icReply => _getImagePath('ic_reply.svg');
String get icReplyAll => _getImagePath('ic_reply_all.svg');
String get icStar => _getImagePath('ic_star.svg');
String get icFlag => _getImagePath('ic_flag.svg');
String get icTrash => _getImagePath('ic_trash.svg');
String get icCalendar => _getImagePath('ic_calendar.svg');
String get icShare => _getImagePath('ic_share.svg');
String get icAttachmentFile => _getImagePath('ic_attachment_file.svg');
String get icOnline => _getImagePath('ic_online.svg');
String get icOffline => _getImagePath('ic_offline.svg');
String get icFlagged => _getImagePath('ic_flagged.svg');
String get icMoreReceiver => _getImagePath('ic_more_receiver.svg');
String _getImagePath(String imageName) {
return AssetsPaths.images + imageName;
@@ -13,6 +13,7 @@ class ButtonBuilder {
String? _icon;
String? _text;
double? _size;
double? _padding;
bool? _isVertical;
Key? _key;
@@ -26,6 +27,11 @@ class ButtonBuilder {
return this;
}
ButtonBuilder padding(double padding) {
_padding = padding;
return this;
}
ButtonBuilder text(String text, {required bool isVertical}) {
_text = text;
_isVertical = isVertical;
@@ -66,7 +72,6 @@ class ButtonBuilder {
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildIcon(),
SizedBox(height: 8),
_buildText(),
])
: Row(
@@ -74,7 +79,6 @@ class ButtonBuilder {
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildIcon(),
SizedBox(width: 8),
_buildText(),
]);
} else {
@@ -82,7 +86,9 @@ class ButtonBuilder {
}
}
Widget _buildIcon() => SvgPicture.asset(_icon ?? '', width: _size ?? 24, height: _size ?? 24, fit: BoxFit.fill);
Widget _buildIcon() => Padding(
padding: EdgeInsets.all(_padding ?? 10),
child: SvgPicture.asset(_icon ?? '', width: _size ?? 24, height: _size ?? 24, fit: BoxFit.fill));
Widget _buildText() {
return Text(
@@ -0,0 +1,64 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class AvatarBuilder {
Key? _key;
String? _text;
double? _size;
String? _iconStatus;
Color? _bgColor;
AvatarBuilder key(Key key) {
_key = key;
return this;
}
AvatarBuilder size(double size) {
_size = size;
return this;
}
AvatarBuilder text(String text) {
_text = text;
return this;
}
AvatarBuilder iconStatus(String iconStatus) {
_iconStatus = iconStatus;
return this;
}
AvatarBuilder backgroundColor(Color bgColor) {
_bgColor = bgColor;
return this;
}
Widget build() {
return Container(
key: _key,
width: _size ?? 40,
height: _size ?? 40,
alignment: Alignment.center,
child: Stack(
children: [
Container(
width: _size ?? 40,
height: _size ?? 40,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular((_size ?? 40) / 2),
border: Border.all(color: Colors.white),
color: _bgColor ?? AppColor.avatarColor),
child: Text(
'${_text ?? ''}',
style: TextStyle(fontSize: 20, color: AppColor.avatarTextColor, fontWeight: FontWeight.w500))),
if (_iconStatus != null && _iconStatus!.isNotEmpty)
Align(
child: SvgPicture.asset(_iconStatus!, width: 12, height: 12, fit: BoxFit.fill),
alignment: Alignment.bottomRight)
],
)
);
}
}
@@ -0,0 +1,64 @@
import 'package:flutter/rendering.dart';
class SliverGridDelegateFixedHeight
extends SliverGridDelegate {
/// Creates a delegate that makes grid layouts with a fixed number of tiles in
/// the cross axis.
///
/// All of the arguments must not be null. The `mainAxisSpacing` and
/// `crossAxisSpacing` arguments must not be negative. The `crossAxisCount`
/// and `childAspectRatio` arguments must be greater than zero.
const SliverGridDelegateFixedHeight({
required this.crossAxisCount,
this.mainAxisSpacing = 0.0,
this.crossAxisSpacing = 0.0,
this.height = 56.0,
}) : assert(crossAxisCount > 0),
assert(mainAxisSpacing >= 0),
assert(crossAxisSpacing >= 0),
assert(height > 0);
/// The number of children in the cross axis.
final int crossAxisCount;
/// The number of logical pixels between each child along the main axis.
final double mainAxisSpacing;
/// The number of logical pixels between each child along the cross axis.
final double crossAxisSpacing;
/// The height of the crossAxis.
final double height;
bool _debugAssertIsValid() {
assert(crossAxisCount > 0);
assert(mainAxisSpacing >= 0.0);
assert(crossAxisSpacing >= 0.0);
assert(height > 0.0);
return true;
}
@override
SliverGridLayout getLayout(SliverConstraints constraints) {
assert(_debugAssertIsValid());
final double usableCrossAxisExtent = constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1);
final double childCrossAxisExtent = usableCrossAxisExtent / crossAxisCount;
final double childMainAxisExtent = height;
return SliverGridRegularTileLayout(
crossAxisCount: crossAxisCount,
mainAxisStride: childMainAxisExtent + mainAxisSpacing,
crossAxisStride: childCrossAxisExtent + crossAxisSpacing,
childMainAxisExtent: childMainAxisExtent,
childCrossAxisExtent: childCrossAxisExtent,
reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection),
);
}
@override
bool shouldRelayout(SliverGridDelegateFixedHeight oldDelegate) {
return oldDelegate.crossAxisCount != crossAxisCount ||
oldDelegate.mainAxisSpacing != mainAxisSpacing ||
oldDelegate.crossAxisSpacing != crossAxisSpacing ||
oldDelegate.height != height;
}
}
+30
View File
@@ -0,0 +1,30 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_body_value.dart';
class EmailContent with EquatableMixin {
final EmailId id;
final Set<EmailBodyPart>? htmlBody;
final Set<EmailBodyPart>? attachments;
final Map<PartId, EmailBodyValue>? bodyValues;
EmailContent(
this.id,
{
this.htmlBody,
this.attachments,
this.bodyValues
}
);
@override
List<Object?> get props => [
id,
htmlBody,
attachments,
bodyValues
];
}
+9 -10
View File
@@ -1,7 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:intl/intl.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
@@ -12,8 +10,6 @@ import 'package:model/extensions/email_address_extension.dart';
class PresentationEmail with EquatableMixin {
static PresentationEmail presentationEmailEmpty = PresentationEmail(EmailId(Id('empty')));
final EmailId id;
final Map<KeyWordIdentifier, bool>? keywords;
final UnsignedInt? size;
@@ -55,17 +51,20 @@ class PresentationEmail with EquatableMixin {
return '';
}
String getAvatarText() {
if (getSenderName().isNotEmpty) {
return getSenderName().substring(0, 1).toUpperCase();
}
return '';
}
String getEmailTitle() => subject != null ? subject! : '';
String getPartialContent() => preview != null ? preview! : '';
String getTimeForToday() => receivedAt != null ? DateFormat('h:mm a').format(receivedAt!.value) : '';
bool isUnReadEmail() => !(keywords?.containsKey(KeyWordIdentifier.emailSeen) == true);
String getTimeForYesterday() => receivedAt != null ? DateFormat('EEE').format(receivedAt!.value) : '';
String getTimeThisYear() => receivedAt != null ? DateFormat('MMMd').format(receivedAt!.value) : '';
String getTimeOtherYear() => receivedAt != null ? DateFormat('yMMMd').format(receivedAt!.value) : '';
bool isFlaggedEmail() => keywords?.containsKey(KeyWordIdentifier.emailFlagged) == true;
@override
List<Object?> get props => [
@@ -0,0 +1,24 @@
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/mailbox/expand_mode.dart';
import 'package:model/extensions/email_address_extension.dart';
extension ListEmailAddressExtension on Set<EmailAddress>? {
List<String> getListEmailAddress({ExpandMode expandMode = ExpandMode.EXPAND, int limitAddress = 1}) {
if (this != null) {
if (expandMode == ExpandMode.EXPAND) {
return this!.map((emailAddress) => emailAddress.asString()).toList();
} else {
final address = this!.map((emailAddress) => emailAddress.asString()).toList();
return address.length > limitAddress ? address.sublist(0, limitAddress) : address;
}
}
return [];
}
String listEmailAddressToString({ExpandMode expandMode = ExpandMode.EXPAND, int limitAddress = 1}) {
return getListEmailAddress(expandMode: expandMode, limitAddress: limitAddress).join(', ');
}
int numberEmailAddress() => this != null ? this!.length : 0;
}
@@ -0,0 +1,16 @@
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:uri/uri.dart';
extension SessionExtension on Session {
String getDownloadUrl(String accountId, String blobId, String name, String type) {
final downloadUriTemplate = UriTemplate('${downloadUrl.origin}');
return downloadUriTemplate.expand({
'accountId' : '$accountId',
'blobId' : '$blobId',
'name' : '$name',
'type' : '$type',
});
}
}
+10 -11
View File
@@ -1,12 +1,13 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_rights.dart';
import 'package:model/mailbox/select_mode.dart';
class PresentationMailbox with EquatableMixin {
static PresentationMailbox presentationMailboxEmpty = PresentationMailbox(MailboxId(Id('empty')));
static final roleTrash = Role('trash');
static final roleSent = Role('sent');
static final roleTemplates = Role('templates');
final MailboxId id;
final MailboxName? name;
@@ -43,17 +44,15 @@ class PresentationMailbox with EquatableMixin {
bool hasRole() => role != null && role!.value.isNotEmpty;
String getCountUnReadEmails() {
if (unreadEmails == null) {
if (role == roleTrash || role == roleSent || role == roleTemplates) {
return '';
} else {
if (unreadEmails!.value.value <= 0) {
return '';
} else {
return unreadEmails!.value.value <= 999
? '${unreadEmails!.value.value}'
: '999+';
}
}
if (unreadEmails == null || unreadEmails!.value.value <= 0) {
return '';
}
return unreadEmails!.value.value <= 999 ? '${unreadEmails!.value.value}' : '999+';
}
@override
+4 -1
View File
@@ -15,6 +15,9 @@ export 'mailbox/expand_mode.dart';
// Email
export 'email/presentation_email.dart';
export 'email/email_content.dart';
// Extensions
export 'extensions/email_address_extension.dart';
export 'extensions/email_address_extension.dart';
export 'extensions/list_email_address_extension.dart';
export 'extensions/session_extension.dart';
+3
View File
@@ -43,6 +43,9 @@ dependencies:
url: git://github.com/linagora/jmap-dart-client.git
ref: master
# uri
uri: 1.0.0
dev_dependencies:
flutter_test:
sdk: flutter
+15
View File
@@ -80,6 +80,21 @@ dependencies:
url: git://github.com/linagora/jmap-dart-client.git
ref: master
# http_parser
http_parser: 4.0.0
# file_size
filesize: 2.0.1
# flutter_widget_from_html
flutter_widget_from_html: 0.6.2
# photo_view
photo_view: 0.12.0
# url_launcher
url_launcher: 6.0.9
dev_dependencies:
flutter_test:
sdk: flutter