Fix attachments cannot be export multiple times in mobile
This commit is contained in:
@@ -320,7 +320,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
mailToClicked: openMailToLink,
|
mailToClicked: openMailToLink,
|
||||||
downloadAttachmentClicked: () {
|
downloadAttachmentClicked: () {
|
||||||
if (currentContext == null || attachments.isEmpty) return;
|
if (currentContext == null || attachments.isEmpty) return;
|
||||||
handleDownloadAttachmentAction(currentContext!, success.attachment);
|
handleDownloadAttachmentAction(success.attachment);
|
||||||
},
|
},
|
||||||
responsiveUtils: responsiveUtils,
|
responsiveUtils: responsiveUtils,
|
||||||
));
|
));
|
||||||
@@ -904,36 +904,53 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void exportAttachment(BuildContext context, Attachment attachment) {
|
void exportAttachment(Attachment attachment) {
|
||||||
final cancelToken = CancelToken();
|
final cancelToken = CancelToken();
|
||||||
_showDownloadingFileDialog(context, attachment.name ?? '', cancelToken: cancelToken);
|
_showDownloadingFileDialog(attachment.name ?? '', cancelToken: cancelToken);
|
||||||
_exportAttachmentAction(attachment, cancelToken);
|
_exportAttachmentAction(attachment, cancelToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showDownloadingFileDialog(BuildContext context, String attachmentName, {CancelToken? cancelToken}) {
|
void _showDownloadingFileDialog(String attachmentName, {CancelToken? cancelToken}) {
|
||||||
if (cancelToken != null) {
|
if (cancelToken != null) {
|
||||||
showCupertinoDialog(
|
Get.dialog(
|
||||||
context: context,
|
PointerInterceptor(
|
||||||
builder: (_) =>
|
child: Builder(
|
||||||
PointerInterceptor(child: (DownloadingFileDialogBuilder()
|
builder: (context) {
|
||||||
|
final appLocalizations = AppLocalizations.of(context);
|
||||||
|
return (DownloadingFileDialogBuilder()
|
||||||
..key(const Key('downloading_file_dialog'))
|
..key(const Key('downloading_file_dialog'))
|
||||||
..title(AppLocalizations.of(context).preparing_to_export)
|
..title(appLocalizations.preparing_to_export)
|
||||||
..content(AppLocalizations.of(context).downloading_file(attachmentName))
|
..content(appLocalizations.downloading_file(attachmentName))
|
||||||
..actionText(AppLocalizations.of(context).cancel)
|
..actionText(appLocalizations.cancel)
|
||||||
..addCancelDownloadActionClick(() {
|
..addCancelDownloadActionClick(() {
|
||||||
cancelToken.cancel([AppLocalizations.of(context).user_cancel_download_file]);
|
cancelToken.cancel([
|
||||||
|
appLocalizations.user_cancel_download_file,
|
||||||
|
]);
|
||||||
popBack();
|
popBack();
|
||||||
}))
|
}))
|
||||||
.build()));
|
.build();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
barrierDismissible: false,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
showCupertinoDialog(
|
Get.dialog(
|
||||||
context: context,
|
PointerInterceptor(
|
||||||
builder: (_) =>
|
child: Builder(
|
||||||
PointerInterceptor(child: (DownloadingFileDialogBuilder()
|
builder: (context) {
|
||||||
..key(const Key('downloading_file_for_web_dialog'))
|
final appLocalizations = AppLocalizations.of(context);
|
||||||
..title(AppLocalizations.of(context).preparing_to_save)
|
return (DownloadingFileDialogBuilder()
|
||||||
..content(AppLocalizations.of(context).downloading_file(attachmentName)))
|
..key(const Key('downloading_file_for_web_dialog'))
|
||||||
.build()));
|
..title(appLocalizations.preparing_to_save)
|
||||||
|
..content(
|
||||||
|
appLocalizations.downloading_file(attachmentName),
|
||||||
|
))
|
||||||
|
.build();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -956,9 +973,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void exportAllAttachments(BuildContext context, String outputFileName) {
|
void exportAllAttachments(String outputFileName) {
|
||||||
final cancelToken = CancelToken();
|
final cancelToken = CancelToken();
|
||||||
_showDownloadingFileDialog(context, outputFileName, cancelToken: cancelToken);
|
_showDownloadingFileDialog(outputFileName, cancelToken: cancelToken);
|
||||||
_exportAllAttachmentsAction(outputFileName, cancelToken);
|
_exportAllAttachmentsAction(outputFileName, cancelToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -988,7 +1005,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
|
|
||||||
void _exportAttachmentFailureAction(ExportAttachmentFailure failure) {
|
void _exportAttachmentFailureAction(ExportAttachmentFailure failure) {
|
||||||
if (failure.exception is! CancelDownloadFileException) {
|
if (failure.exception is! CancelDownloadFileException) {
|
||||||
popBack();
|
if (Get.isDialogOpen == true) {
|
||||||
|
popBack();
|
||||||
|
}
|
||||||
|
|
||||||
if (currentOverlayContext != null && currentContext != null) {
|
if (currentOverlayContext != null && currentContext != null) {
|
||||||
appToast.showToastErrorMessage(
|
appToast.showToastErrorMessage(
|
||||||
@@ -1164,9 +1183,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
onClose: () => Navigator.maybePop(context),
|
onClose: () => Navigator.maybePop(context),
|
||||||
onDownload: currentContext == null
|
onDownload: currentContext == null
|
||||||
? null
|
? null
|
||||||
: () => handleDownloadAttachmentAction(
|
: () => handleDownloadAttachmentAction(success.attachment),
|
||||||
currentContext!,
|
|
||||||
success.attachment),
|
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@@ -1186,9 +1203,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
onClose: () => Navigator.maybePop(context),
|
onClose: () => Navigator.maybePop(context),
|
||||||
onDownload: currentContext == null
|
onDownload: currentContext == null
|
||||||
? null
|
? null
|
||||||
: () => handleDownloadAttachmentAction(
|
: () => handleDownloadAttachmentAction(success.attachment),
|
||||||
currentContext!,
|
|
||||||
success.attachment),
|
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@@ -1756,7 +1771,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
if (responsiveUtils.isMobile(context)) {
|
if (responsiveUtils.isMobile(context)) {
|
||||||
(AttachmentListBottomSheetBuilder(context, attachments, imagePaths, _attachmentListScrollController, tag)
|
(AttachmentListBottomSheetBuilder(context, attachments, imagePaths, _attachmentListScrollController, tag)
|
||||||
..onCloseButtonAction(() => popBack())
|
..onCloseButtonAction(() => popBack())
|
||||||
..onDownloadAttachmentFileAction((attachment) => handleDownloadAttachmentAction(context, attachment))
|
..onDownloadAttachmentFileAction((attachment) => handleDownloadAttachmentAction(attachment))
|
||||||
..onViewAttachmentFileAction((attachment) => handleViewAttachmentAction(context, attachment))
|
..onViewAttachmentFileAction((attachment) => handleViewAttachmentAction(context, attachment))
|
||||||
..onDownloadAllButtonAction(isDownloadAllSupported()
|
..onDownloadAllButtonAction(isDownloadAllSupported()
|
||||||
? () => downloadAllAttachmentsForWeb('TwakeMail-${DateTime.now()}')
|
? () => downloadAllAttachmentsForWeb('TwakeMail-${DateTime.now()}')
|
||||||
@@ -1773,7 +1788,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
scrollController: _attachmentListScrollController,
|
scrollController: _attachmentListScrollController,
|
||||||
backgroundColor: Colors.black.withAlpha(24),
|
backgroundColor: Colors.black.withAlpha(24),
|
||||||
onCloseButtonAction: () => popBack(),
|
onCloseButtonAction: () => popBack(),
|
||||||
onDownloadAttachmentFileAction: (attachment) => handleDownloadAttachmentAction(context, attachment),
|
onDownloadAttachmentFileAction: (attachment) => handleDownloadAttachmentAction(attachment),
|
||||||
onViewAttachmentFileAction: (attachment) => handleViewAttachmentAction(context, attachment),
|
onViewAttachmentFileAction: (attachment) => handleViewAttachmentAction(context, attachment),
|
||||||
onDownloadAllButtonAction: isDownloadAllSupported()
|
onDownloadAllButtonAction: isDownloadAllSupported()
|
||||||
? () => downloadAllAttachmentsForWeb('TwakeMail-${DateTime.now()}')
|
? () => downloadAllAttachmentsForWeb('TwakeMail-${DateTime.now()}')
|
||||||
@@ -2014,27 +2029,23 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleDownloadAttachmentAction(
|
void handleDownloadAttachmentAction(
|
||||||
BuildContext context,
|
|
||||||
Attachment attachment,
|
Attachment attachment,
|
||||||
{bool previewerSupported = false}
|
{bool previewerSupported = false}
|
||||||
) {
|
) {
|
||||||
if (PlatformInfo.isWeb) {
|
if (PlatformInfo.isWeb) {
|
||||||
downloadAttachmentForWeb(attachment, previewerSupported: previewerSupported);
|
downloadAttachmentForWeb(attachment, previewerSupported: previewerSupported);
|
||||||
} else if (PlatformInfo.isMobile) {
|
} else if (PlatformInfo.isMobile) {
|
||||||
exportAttachment(context, attachment);
|
exportAttachment(attachment);
|
||||||
} else {
|
} else {
|
||||||
log('EmailView::handleDownloadAttachmentAction: THE PLATFORM IS SUPPORTED');
|
log('EmailView::handleDownloadAttachmentAction: THE PLATFORM IS SUPPORTED');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleDownloadAllAttachmentsAction(
|
void handleDownloadAllAttachmentsAction(String outputFileName) {
|
||||||
BuildContext context,
|
|
||||||
String outputFileName,
|
|
||||||
) {
|
|
||||||
if (PlatformInfo.isWeb) {
|
if (PlatformInfo.isWeb) {
|
||||||
downloadAllAttachmentsForWeb(outputFileName);
|
downloadAllAttachmentsForWeb(outputFileName);
|
||||||
} else if (PlatformInfo.isMobile) {
|
} else if (PlatformInfo.isMobile) {
|
||||||
exportAllAttachments(context, outputFileName);
|
exportAllAttachments(outputFileName);
|
||||||
} else {
|
} else {
|
||||||
log('EmailView::handleDownloadAllAttachmentsAction: THE PLATFORM IS SUPPORTED');
|
log('EmailView::handleDownloadAllAttachmentsAction: THE PLATFORM IS SUPPORTED');
|
||||||
}
|
}
|
||||||
@@ -2067,7 +2078,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
handleDownloadAttachmentAction(
|
handleDownloadAttachmentAction(
|
||||||
context,
|
|
||||||
attachment,
|
attachment,
|
||||||
previewerSupported: attachmentPreviewSupported(attachment),
|
previewerSupported: attachmentPreviewSupported(attachment),
|
||||||
);
|
);
|
||||||
@@ -2273,7 +2283,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
onMailtoDelegateAction: openMailToLink,
|
onMailtoDelegateAction: openMailToLink,
|
||||||
onPreviewEMLDelegateAction: (uri) => _openEMLPreviewer(context, uri),
|
onPreviewEMLDelegateAction: (uri) => _openEMLPreviewer(context, uri),
|
||||||
onDownloadAttachmentDelegateAction: (uri) =>
|
onDownloadAttachmentDelegateAction: (uri) =>
|
||||||
_downloadAttachmentInEMLPreview(context, uri),
|
_downloadAttachmentInEMLPreview(uri),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -2288,7 +2298,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
onMailtoDelegateAction: openMailToLink,
|
onMailtoDelegateAction: openMailToLink,
|
||||||
onPreviewEMLDelegateAction: (uri) => _openEMLPreviewer(context, uri),
|
onPreviewEMLDelegateAction: (uri) => _openEMLPreviewer(context, uri),
|
||||||
onDownloadAttachmentDelegateAction: (uri) =>
|
onDownloadAttachmentDelegateAction: (uri) =>
|
||||||
_downloadAttachmentInEMLPreview(context, uri),
|
_downloadAttachmentInEMLPreview(uri),
|
||||||
),
|
),
|
||||||
barrierColor: AppColor.colorDefaultCupertinoActionSheet,
|
barrierColor: AppColor.colorDefaultCupertinoActionSheet,
|
||||||
);
|
);
|
||||||
@@ -2305,14 +2315,14 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
previewEMLFileAction(Id(blobId), AppLocalizations.of(context));
|
previewEMLFileAction(Id(blobId), AppLocalizations.of(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _downloadAttachmentInEMLPreview(BuildContext context, Uri? uri) async {
|
Future<void> _downloadAttachmentInEMLPreview(Uri? uri) async {
|
||||||
log('SingleEmailController::_downloadAttachmentInEMLPreview:uri = $uri');
|
log('SingleEmailController::_downloadAttachmentInEMLPreview:uri = $uri');
|
||||||
if (uri == null) return;
|
if (uri == null) return;
|
||||||
|
|
||||||
final attachment = EmailUtils.parsingAttachmentByUri(uri);
|
final attachment = EmailUtils.parsingAttachmentByUri(uri);
|
||||||
if (attachment == null) return;
|
if (attachment == null) return;
|
||||||
|
|
||||||
handleDownloadAttachmentAction(context, attachment);
|
handleDownloadAttachmentAction(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMailToAttendees(CalendarOrganizer? organizer, List<CalendarAttendee>? attendees) {
|
void handleMailToAttendees(CalendarOrganizer? organizer, List<CalendarAttendee>? attendees) {
|
||||||
|
|||||||
@@ -447,10 +447,7 @@ class EmailView extends GetWidget<SingleEmailController> {
|
|||||||
.disableAttachmentDraggableApp();
|
.disableAttachmentDraggableApp();
|
||||||
},
|
},
|
||||||
downloadAttachmentAction: (attachment) =>
|
downloadAttachmentAction: (attachment) =>
|
||||||
controller.handleDownloadAttachmentAction(
|
controller.handleDownloadAttachmentAction(attachment),
|
||||||
context,
|
|
||||||
attachment,
|
|
||||||
),
|
|
||||||
viewAttachmentAction: (attachment) =>
|
viewAttachmentAction: (attachment) =>
|
||||||
controller.handleViewAttachmentAction(
|
controller.handleViewAttachmentAction(
|
||||||
context,
|
context,
|
||||||
@@ -464,7 +461,6 @@ class EmailView extends GetWidget<SingleEmailController> {
|
|||||||
controller.downloadAllButtonIsEnabled(),
|
controller.downloadAllButtonIsEnabled(),
|
||||||
onTapDownloadAllButton: () =>
|
onTapDownloadAllButton: () =>
|
||||||
controller.handleDownloadAllAttachmentsAction(
|
controller.handleDownloadAllAttachmentsAction(
|
||||||
context,
|
|
||||||
'TwakeMail-${DateTime.now()}',
|
'TwakeMail-${DateTime.now()}',
|
||||||
),
|
),
|
||||||
singleEmailControllerTag: tag,
|
singleEmailControllerTag: tag,
|
||||||
|
|||||||
Reference in New Issue
Block a user