TF-3454 Add hide download feature to download all

This commit is contained in:
DatDang
2025-02-18 13:25:40 +07:00
committed by Dat H. Pham
parent e1795d1f5c
commit e91f1bbc6a
3 changed files with 20 additions and 10 deletions
@@ -1,16 +1,18 @@
import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dio/dio.dart';
import 'package:model/download/download_task_id.dart'; import 'package:model/download/download_task_id.dart';
import 'package:model/email/attachment.dart'; import 'package:model/email/attachment.dart';
class StartDownloadAllAttachmentsForWeb extends UIState { class StartDownloadAllAttachmentsForWeb extends UIState {
StartDownloadAllAttachmentsForWeb(this.taskId, this.attachment); StartDownloadAllAttachmentsForWeb(this.taskId, this.attachment, {this.cancelToken});
final DownloadTaskId taskId; final DownloadTaskId taskId;
final Attachment attachment; final Attachment attachment;
final CancelToken? cancelToken;
@override @override
List<Object> get props => [taskId, attachment]; List<Object?> get props => [taskId, attachment, cancelToken];
} }
class DownloadingAllAttachmentsForWeb extends LoadingState { class DownloadingAllAttachmentsForWeb extends LoadingState {
@@ -42,10 +44,11 @@ class DownloadAllAttachmentsForWebSuccess extends UIState {
} }
class DownloadAllAttachmentsForWebFailure extends FeatureFailure { class DownloadAllAttachmentsForWebFailure extends FeatureFailure {
DownloadAllAttachmentsForWebFailure({super.exception, required this.taskId}); DownloadAllAttachmentsForWebFailure({super.exception, required this.taskId, this.cancelToken});
final DownloadTaskId taskId; final DownloadTaskId taskId;
final CancelToken? cancelToken;
@override @override
List<Object> get props => [exception, taskId]; List<Object?> get props => [exception, taskId, cancelToken];
} }
@@ -49,6 +49,7 @@ class DownloadAllAttachmentsForWebInteractor {
onReceiveController.add(Right(StartDownloadAllAttachmentsForWeb( onReceiveController.add(Right(StartDownloadAllAttachmentsForWeb(
taskId, taskId,
attachment, attachment,
cancelToken: cancelToken,
))); )));
final currentAccount = await _accountRepository.getCurrentAccount(); final currentAccount = await _accountRepository.getCurrentAccount();
AccountRequest accountRequest; AccountRequest accountRequest;
@@ -77,7 +78,11 @@ class DownloadAllAttachmentsForWebInteractor {
yield Right(DownloadAllAttachmentsForWebSuccess(taskId: taskId)); yield Right(DownloadAllAttachmentsForWebSuccess(taskId: taskId));
} catch (e) { } catch (e) {
logError('DownloadAllAttachmentsForWebInteractor::execute():EXCEPTION: $e'); logError('DownloadAllAttachmentsForWebInteractor::execute():EXCEPTION: $e');
yield Left(DownloadAllAttachmentsForWebFailure(exception: e, taskId: taskId)); yield Left(DownloadAllAttachmentsForWebFailure(
exception: e,
taskId: taskId,
cancelToken: cancelToken,
));
} }
} }
} }
@@ -478,6 +478,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
DownloadTaskState( DownloadTaskState(
taskId: success.taskId, taskId: success.taskId,
attachment: success.attachment, attachment: success.attachment,
onCancel: () => success.cancelToken?.cancel(),
), ),
); );
@@ -1073,11 +1074,12 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
DownloadAllAttachmentsForWebFailure failure, DownloadAllAttachmentsForWebFailure failure,
) { ) {
mailboxDashBoardController.deleteDownloadTask(failure.taskId); mailboxDashBoardController.deleteDownloadTask(failure.taskId);
if (currentOverlayContext != null && currentContext != null) { if (currentOverlayContext == null || currentContext == null) return;
appToast.showToastErrorMessage( String message = AppLocalizations.of(currentContext!).attachment_download_failed;
currentOverlayContext!, if (failure.cancelToken?.isCancelled == true) {
AppLocalizations.of(currentContext!).attachment_download_failed); message = AppLocalizations.of(currentContext!).downloadAttachmentHasBeenCancelled;
} }
appToast.showToastErrorMessage(currentOverlayContext!, message);
} }
void _downloadAttachmentForWebSuccessAction(DownloadAttachmentForWebSuccess success) { void _downloadAttachmentForWebSuccessAction(DownloadAttachmentForWebSuccess success) {