TF-2628 Integrate view attachment feature with UI

This commit is contained in:
DatDang
2024-02-27 10:08:32 +07:00
committed by Dat H. Pham
parent 31fbda6c0c
commit ef305229f6
8 changed files with 39 additions and 6 deletions
@@ -1453,7 +1453,14 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
} else { } else {
exportAttachment(context, attachment); exportAttachment(context, attachment);
} }
} },
onViewAttachmentFileAction: (attachment) {
if (PlatformInfo.isWeb) {
viewAttachmentForWeb(attachment);
} else {
exportAttachment(context, attachment);
}
},
) )
), ),
barrierColor: AppColor.colorDefaultCupertinoActionSheet, barrierColor: AppColor.colorDefaultCupertinoActionSheet,
@@ -345,7 +345,14 @@ class EmailView extends GetWidget<SingleEmailController> {
}, },
downloadAttachmentAction: (attachment) { downloadAttachmentAction: (attachment) {
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
controller.downloadAttachmentForWeb(context, attachment); controller.downloadAttachmentForWeb(attachment);
} else {
controller.exportAttachment(context, attachment);
}
},
viewAttachmentAction: (attachment) {
if (PlatformInfo.isWeb) {
controller.viewAttachmentForWeb(attachment);
} else { } else {
controller.exportAttachment(context, attachment); controller.exportAttachment(context, attachment);
} }
@@ -12,11 +12,13 @@ import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_
import 'package:tmail_ui_user/features/email/presentation/styles/attachment/attachment_item_widget_style.dart'; import 'package:tmail_ui_user/features/email/presentation/styles/attachment/attachment_item_widget_style.dart';
typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment); typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment);
typedef OnViewAttachmentFileActionClick = void Function(Attachment attachment);
class AttachmentItemWidget extends StatelessWidget { class AttachmentItemWidget extends StatelessWidget {
final Attachment attachment; final Attachment attachment;
final OnDownloadAttachmentFileActionClick? downloadAttachmentAction; final OnDownloadAttachmentFileActionClick? downloadAttachmentAction;
final OnViewAttachmentFileActionClick? viewAttachmentAction;
final _imagePaths = Get.find<ImagePaths>(); final _imagePaths = Get.find<ImagePaths>();
final _responsiveUtils = Get.find<ResponsiveUtils>(); final _responsiveUtils = Get.find<ResponsiveUtils>();
@@ -25,6 +27,7 @@ class AttachmentItemWidget extends StatelessWidget {
Key? key, Key? key,
required this.attachment, required this.attachment,
this.downloadAttachmentAction, this.downloadAttachmentAction,
this.viewAttachmentAction,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -32,7 +35,7 @@ class AttachmentItemWidget extends StatelessWidget {
return Material( return Material(
color: Colors.transparent, color: Colors.transparent,
child: InkWell( child: InkWell(
onTap: () => downloadAttachmentAction?.call(attachment), onTap: () => viewAttachmentAction?.call(attachment),
customBorder: const RoundedRectangleBorder( customBorder: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(AttachmentItemWidgetStyle.radius)) borderRadius: BorderRadius.all(Radius.circular(AttachmentItemWidgetStyle.radius))
), ),
@@ -17,6 +17,7 @@ class AttachmentListDialogBodyBuilder extends StatelessWidget {
final double? heightDialog; final double? heightDialog;
final OnDownloadAllButtonAction? onDownloadAllButtonAction; final OnDownloadAllButtonAction? onDownloadAllButtonAction;
final OnDownloadAttachmentFileAction? onDownloadAttachmentFileAction; final OnDownloadAttachmentFileAction? onDownloadAttachmentFileAction;
final OnViewAttachmentFileAction? onViewAttachmentFileAction;
final OnCancelButtonAction? onCancelButtonAction; final OnCancelButtonAction? onCancelButtonAction;
final OnCloseButtonAction? onCloseButtonAction; final OnCloseButtonAction? onCloseButtonAction;
@@ -30,6 +31,7 @@ class AttachmentListDialogBodyBuilder extends StatelessWidget {
this.heightDialog, this.heightDialog,
this.onDownloadAllButtonAction, this.onDownloadAllButtonAction,
this.onDownloadAttachmentFileAction, this.onDownloadAttachmentFileAction,
this.onViewAttachmentFileAction,
this.onCancelButtonAction, this.onCancelButtonAction,
this.onCloseButtonAction this.onCloseButtonAction
}); });
@@ -108,6 +110,7 @@ class AttachmentListDialogBodyBuilder extends StatelessWidget {
return AttachmentListItemWidget( return AttachmentListItemWidget(
attachment: attachments[index], attachment: attachments[index],
downloadAttachmentAction: onDownloadAttachmentFileAction, downloadAttachmentAction: onDownloadAttachmentFileAction,
viewAttachmentAction: onViewAttachmentFileAction,
); );
}, },
separatorBuilder: (context, index) { separatorBuilder: (context, index) {
@@ -6,6 +6,7 @@ import 'package:tmail_ui_user/features/email/presentation/styles/attachment/atta
import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_list/attachment_list_dialog_body_builder.dart'; import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_list/attachment_list_dialog_body_builder.dart';
typedef OnDownloadAttachmentFileAction = void Function(Attachment attachment); typedef OnDownloadAttachmentFileAction = void Function(Attachment attachment);
typedef OnViewAttachmentFileAction = void Function(Attachment attachment);
typedef OnDownloadAllButtonAction = void Function(); typedef OnDownloadAllButtonAction = void Function();
typedef OnCancelButtonAction = void Function(); typedef OnCancelButtonAction = void Function();
typedef OnCloseButtonAction = void Function(); typedef OnCloseButtonAction = void Function();
@@ -22,6 +23,7 @@ class AttachmentListDialogBuilder extends StatelessWidget {
final double? heightDialog; final double? heightDialog;
final OnDownloadAllButtonAction? onDownloadAllButtonAction; final OnDownloadAllButtonAction? onDownloadAllButtonAction;
final OnDownloadAttachmentFileAction? onDownloadAttachmentFileAction; final OnDownloadAttachmentFileAction? onDownloadAttachmentFileAction;
final OnViewAttachmentFileAction? onViewAttachmentFileAction;
final OnCancelButtonAction? onCancelButtonAction; final OnCancelButtonAction? onCancelButtonAction;
final OnCloseButtonAction? onCloseButtonAction; final OnCloseButtonAction? onCloseButtonAction;
@@ -36,6 +38,7 @@ class AttachmentListDialogBuilder extends StatelessWidget {
this.heightDialog, this.heightDialog,
this.onDownloadAllButtonAction, this.onDownloadAllButtonAction,
this.onDownloadAttachmentFileAction, this.onDownloadAttachmentFileAction,
this.onViewAttachmentFileAction,
this.onCancelButtonAction, this.onCancelButtonAction,
this.onCloseButtonAction, this.onCloseButtonAction,
}) : super(key: key); }) : super(key: key);
@@ -59,6 +62,7 @@ class AttachmentListDialogBuilder extends StatelessWidget {
scrollController: scrollController, scrollController: scrollController,
onDownloadAllButtonAction: onDownloadAllButtonAction, onDownloadAllButtonAction: onDownloadAllButtonAction,
onDownloadAttachmentFileAction: onDownloadAttachmentFileAction, onDownloadAttachmentFileAction: onDownloadAttachmentFileAction,
onViewAttachmentFileAction: onViewAttachmentFileAction,
onCancelButtonAction: onCancelButtonAction, onCancelButtonAction: onCancelButtonAction,
onCloseButtonAction: onCloseButtonAction, onCloseButtonAction: onCloseButtonAction,
), ),
@@ -10,6 +10,7 @@ import 'package:get/get.dart';
import 'package:model/email/attachment.dart'; import 'package:model/email/attachment.dart';
import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart'; import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart';
import 'package:tmail_ui_user/features/email/presentation/styles/attachment/attachment_list_item_widget_styles.dart'; import 'package:tmail_ui_user/features/email/presentation/styles/attachment/attachment_list_item_widget_styles.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_item_widget.dart';
typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment); typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment);
@@ -17,6 +18,7 @@ class AttachmentListItemWidget extends StatelessWidget {
final Attachment attachment; final Attachment attachment;
final OnDownloadAttachmentFileActionClick? downloadAttachmentAction; final OnDownloadAttachmentFileActionClick? downloadAttachmentAction;
final OnViewAttachmentFileActionClick? viewAttachmentAction;
final _imagePaths = Get.find<ImagePaths>(); final _imagePaths = Get.find<ImagePaths>();
@@ -24,6 +26,7 @@ class AttachmentListItemWidget extends StatelessWidget {
Key? key, Key? key,
required this.attachment, required this.attachment,
this.downloadAttachmentAction, this.downloadAttachmentAction,
this.viewAttachmentAction,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -31,7 +34,7 @@ class AttachmentListItemWidget extends StatelessWidget {
return Material( return Material(
type: MaterialType.transparency, type: MaterialType.transparency,
child: InkWell( child: InkWell(
onTap: () => downloadAttachmentAction?.call(attachment), onTap: () => viewAttachmentAction?.call(attachment),
child: Padding( child: Padding(
padding: AttachmentListItemWidgetStyle.contentPadding, padding: AttachmentListItemWidgetStyle.contentPadding,
child: Row( child: Row(
@@ -13,6 +13,7 @@ class DraggableAttachmentItemWidget extends StatelessWidget{
final OnDragAttachmentStarted? onDragStarted; final OnDragAttachmentStarted? onDragStarted;
final OnDragAttachmentEnd? onDragEnd; final OnDragAttachmentEnd? onDragEnd;
final OnDownloadAttachmentFileActionClick? downloadAttachmentAction; final OnDownloadAttachmentFileActionClick? downloadAttachmentAction;
final OnViewAttachmentFileActionClick? viewAttachmentAction;
const DraggableAttachmentItemWidget({ const DraggableAttachmentItemWidget({
Key? key, Key? key,
@@ -20,6 +21,7 @@ class DraggableAttachmentItemWidget extends StatelessWidget{
this.onDragStarted, this.onDragStarted,
this.onDragEnd, this.onDragEnd,
this.downloadAttachmentAction, this.downloadAttachmentAction,
this.viewAttachmentAction,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -31,7 +33,8 @@ class DraggableAttachmentItemWidget extends StatelessWidget{
onDragEnd: onDragEnd, onDragEnd: onDragEnd,
child: AttachmentItemWidget( child: AttachmentItemWidget(
attachment: attachment, attachment: attachment,
downloadAttachmentAction: downloadAttachmentAction downloadAttachmentAction: downloadAttachmentAction,
viewAttachmentAction: viewAttachmentAction,
), ),
); );
} }
@@ -20,6 +20,7 @@ class EmailAttachmentsWidget extends StatelessWidget {
final OnDragAttachmentStarted? onDragStarted; final OnDragAttachmentStarted? onDragStarted;
final OnDragAttachmentEnd? onDragEnd; final OnDragAttachmentEnd? onDragEnd;
final OnDownloadAttachmentFileActionClick? downloadAttachmentAction; final OnDownloadAttachmentFileActionClick? downloadAttachmentAction;
final OnViewAttachmentFileActionClick? viewAttachmentAction;
final ResponsiveUtils responsiveUtils; final ResponsiveUtils responsiveUtils;
final ImagePaths imagePaths; final ImagePaths imagePaths;
final OnTapActionCallback? onTapShowAllAttachmentFile; final OnTapActionCallback? onTapShowAllAttachmentFile;
@@ -32,6 +33,7 @@ class EmailAttachmentsWidget extends StatelessWidget {
this.onDragStarted, this.onDragStarted,
this.onDragEnd, this.onDragEnd,
this.downloadAttachmentAction, this.downloadAttachmentAction,
this.viewAttachmentAction,
this.onTapShowAllAttachmentFile, this.onTapShowAllAttachmentFile,
}); });
@@ -106,7 +108,8 @@ class EmailAttachmentsWidget extends StatelessWidget {
attachment: attachment, attachment: attachment,
onDragStarted: onDragStarted, onDragStarted: onDragStarted,
onDragEnd: onDragEnd, onDragEnd: onDragEnd,
downloadAttachmentAction: downloadAttachmentAction downloadAttachmentAction: downloadAttachmentAction,
viewAttachmentAction: viewAttachmentAction,
); );
} else { } else {
return AttachmentItemWidget( return AttachmentItemWidget(