TF-3488 Add hide download taskbar feature
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
|
||||
@@ -10,11 +11,12 @@ class StartDownloadAttachmentForWeb extends UIState {
|
||||
|
||||
final DownloadTaskId taskId;
|
||||
final Attachment attachment;
|
||||
final CancelToken? cancelToken;
|
||||
|
||||
StartDownloadAttachmentForWeb(this.taskId, this.attachment);
|
||||
StartDownloadAttachmentForWeb(this.taskId, this.attachment, [this.cancelToken]);
|
||||
|
||||
@override
|
||||
List<Object> get props => [taskId, attachment];
|
||||
List<Object?> get props => [taskId, attachment, cancelToken];
|
||||
}
|
||||
|
||||
class DownloadingAttachmentForWeb extends UIState {
|
||||
@@ -59,13 +61,15 @@ class DownloadAttachmentForWebFailure extends FeatureFailure {
|
||||
|
||||
final DownloadTaskId? taskId;
|
||||
final Attachment? attachment;
|
||||
final CancelToken? cancelToken;
|
||||
|
||||
DownloadAttachmentForWebFailure({
|
||||
this.attachment,
|
||||
this.taskId,
|
||||
dynamic exception
|
||||
}) : super(exception: exception);
|
||||
this.cancelToken,
|
||||
super.exception
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [attachment, taskId, ...super.props];
|
||||
List<Object?> get props => [attachment, taskId, cancelToken, ...super.props];
|
||||
}
|
||||
@@ -38,8 +38,8 @@ class DownloadAttachmentForWebInteractor {
|
||||
{CancelToken? cancelToken}
|
||||
) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StartDownloadAttachmentForWeb(taskId, attachment));
|
||||
onReceiveController.add(Right(StartDownloadAttachmentForWeb(taskId, attachment)));
|
||||
yield Right<Failure, Success>(StartDownloadAttachmentForWeb(taskId, attachment, cancelToken));
|
||||
onReceiveController.add(Right(StartDownloadAttachmentForWeb(taskId, attachment, cancelToken)));
|
||||
|
||||
final currentAccount = await _accountRepository.getCurrentAccount();
|
||||
AccountRequest? accountRequest;
|
||||
@@ -77,7 +77,8 @@ class DownloadAttachmentForWebInteractor {
|
||||
DownloadAttachmentForWebFailure(
|
||||
attachment: attachment,
|
||||
taskId: taskId,
|
||||
exception: exception
|
||||
exception: exception,
|
||||
cancelToken: cancelToken,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -426,9 +426,12 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
(success) {
|
||||
if (success is StartDownloadAttachmentForWeb) {
|
||||
emailSupervisorController.mailboxDashBoardController.addDownloadTask(
|
||||
DownloadTaskState(
|
||||
taskId: success.taskId,
|
||||
attachment: success.attachment));
|
||||
DownloadTaskState(
|
||||
taskId: success.taskId,
|
||||
attachment: success.attachment,
|
||||
onCancel: () => success.cancelToken?.cancel(),
|
||||
),
|
||||
);
|
||||
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastMessage(
|
||||
@@ -896,12 +899,15 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
final baseDownloadUrl = session!.getDownloadUrl(
|
||||
jmapUrl: dynamicUrlInterceptors.jmapUrl,
|
||||
);
|
||||
final cancelToken = CancelToken();
|
||||
consumeState(_downloadAttachmentForWebInteractor.execute(
|
||||
generateTaskId,
|
||||
attachment,
|
||||
accountId!,
|
||||
baseDownloadUrl,
|
||||
_downloadProgressStateController));
|
||||
generateTaskId,
|
||||
attachment,
|
||||
accountId!,
|
||||
baseDownloadUrl,
|
||||
_downloadProgressStateController,
|
||||
cancelToken: cancelToken,
|
||||
));
|
||||
} catch (e) {
|
||||
logError('SingleEmailController::downloadAttachmentForWeb(): $e');
|
||||
consumeState(Stream.value(Left(DownloadAttachmentForWebFailure(attachment: attachment, taskId: generateTaskId, exception: e))));
|
||||
@@ -944,14 +950,17 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
if (failure.attachment != null) {
|
||||
_updateAttachmentsViewState(failure.attachment?.blobId, Left(failure));
|
||||
}
|
||||
|
||||
if (currentOverlayContext == null || currentContext == null) return;
|
||||
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastErrorMessage(
|
||||
currentOverlayContext!,
|
||||
failure.attachment is EMLAttachment
|
||||
? AppLocalizations.of(currentContext!).downloadMessageAsEMLFailed
|
||||
: AppLocalizations.of(currentContext!).attachment_download_failed);
|
||||
String message = AppLocalizations.of(currentContext!).attachment_download_failed;
|
||||
if (failure.attachment is EMLAttachment) {
|
||||
message = AppLocalizations.of(currentContext!).downloadMessageAsEMLFailed;
|
||||
} else if (failure.cancelToken?.isCancelled == true) {
|
||||
message = AppLocalizations.of(currentContext!).downloadAttachmentHasBeenCancelled;
|
||||
}
|
||||
|
||||
appToast.showToastErrorMessage(currentOverlayContext!, message);
|
||||
}
|
||||
|
||||
void _updateAttachmentsViewState(
|
||||
|
||||
Reference in New Issue
Block a user