diff --git a/lib/features/base/mixin/mailbox_action_handler_mixin.dart b/lib/features/base/mixin/mailbox_action_handler_mixin.dart index f124709534..bf23a00edc 100644 --- a/lib/features/base/mixin/mailbox_action_handler_mixin.dart +++ b/lib/features/base/mixin/mailbox_action_handler_mixin.dart @@ -64,7 +64,10 @@ mixin MailboxActionHandlerMixin { ..onConfirmAction(AppLocalizations.of(context).delete, () { popBack(); if (mailbox.countTotalEmails > 0) { - dashboardController.emptyTrashFolderAction(trashFolderId: mailbox.id); + dashboardController.emptyTrashFolderAction( + trashFolderId: mailbox.id, + totalEmails: mailbox.countTotalEmails + ); } else { appToast.showToastWarningMessage( context, @@ -89,7 +92,10 @@ mixin MailboxActionHandlerMixin { ..onConfirmButtonAction(AppLocalizations.of(context).delete, () { popBack(); if (mailbox.countTotalEmails > 0) { - dashboardController.emptyTrashFolderAction(trashFolderId: mailbox.id); + dashboardController.emptyTrashFolderAction( + trashFolderId: mailbox.id, + totalEmails: mailbox.countTotalEmails, + ); } else { appToast.showToastWarningMessage( context, diff --git a/lib/features/mailbox/data/network/mailbox_isolate_worker.dart b/lib/features/mailbox/data/network/mailbox_isolate_worker.dart index 33b0146ebe..09468ccd09 100644 --- a/lib/features/mailbox/data/network/mailbox_isolate_worker.dart +++ b/lib/features/mailbox/data/network/mailbox_isolate_worker.dart @@ -8,9 +8,9 @@ import 'package:dartz/dartz.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/session/session.dart'; +import 'package:jmap_dart_client/jmap/core/sort/comparator.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/core/sort/comparator.dart'; import 'package:jmap_dart_client/jmap/mail/email/email.dart'; import 'package:jmap_dart_client/jmap/mail/email/email_comparator.dart'; import 'package:jmap_dart_client/jmap/mail/email/email_comparator_property.dart'; @@ -69,7 +69,7 @@ class MailboxIsolateWorker { ), fun1: _handleMarkAsMailboxReadAction, notification: (value) { - if (value is List) { + if (value is List) { log('MailboxIsolateWorker::markAsMailboxRead(): onUpdateProgress: PERCENT ${value.length / totalEmailUnread}'); onProgressController.add(Right(UpdatingMarkAsMailboxReadState( mailboxId: mailboxId, diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index 524f7d1a04..904068006a 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -1359,9 +1359,15 @@ class MailboxController extends BaseMailboxController void emptyMailboxAction(BuildContext context, PresentationMailbox presentationMailbox) { log('MailboxController::emptyMailboxAction:presentationMailbox: ${presentationMailbox.name}'); if (presentationMailbox.isTrash) { - mailboxDashBoardController.emptyTrashFolderAction(trashFolderId: presentationMailbox.id); + mailboxDashBoardController.emptyTrashFolderAction( + trashFolderId: presentationMailbox.id, + totalEmails: presentationMailbox.countTotalEmails + ); } else if (presentationMailbox.isSpam) { - mailboxDashBoardController.emptySpamFolderAction(spamFolderId: presentationMailbox.id); + mailboxDashBoardController.emptySpamFolderAction( + spamFolderId: presentationMailbox.id, + totalEmails: presentationMailbox.countTotalEmails + ); } } diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index b8f2bb98e7..3e6b323840 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -439,8 +439,11 @@ class MailboxDashBoardController extends ReloadableController _handleRestoreDeletedMessageFailed(); } else if (failure is GetRestoredDeletedMessageFailure) { _handleRestoreDeletedMessageFailed(); - } else if (failure is EmptySpamFolderFailure - || failure is MoveMultipleEmailToMailboxFailure) { + } else if (failure is EmptySpamFolderFailure) { + _handleEmptySpamFolderFailure(failure); + } else if (failure is EmptyTrashFolderFailure) { + _handleEmptyTrashFolderFailure(failure); + } else if (failure is MoveMultipleEmailToMailboxFailure) { toastManager.showMessageFailure(failure); } else if (failure is GetComposerCacheFailure) { _handleIdentityCache(); @@ -1385,12 +1388,22 @@ class MailboxDashBoardController extends ReloadableController } } - void emptyTrashFolderAction({Function? onCancelSelectionEmail, MailboxId? trashFolderId}) { + void emptyTrashFolderAction({ + Function? onCancelSelectionEmail, + MailboxId? trashFolderId, + int totalEmails = 0, + }) { onCancelSelectionEmail?.call(); final trashMailboxId = trashFolderId ?? mapDefaultMailboxIdByRole[PresentationMailbox.roleTrash]; if (sessionCurrent != null && accountId.value != null && trashMailboxId != null) { - consumeState(_emptyTrashFolderInteractor.execute(sessionCurrent!, accountId.value!, trashMailboxId)); + consumeState(_emptyTrashFolderInteractor.execute( + sessionCurrent!, + accountId.value!, + trashMailboxId, + totalEmails, + _progressStateController + )); } } @@ -2371,7 +2384,11 @@ class MailboxDashBoardController extends ReloadableController consumeState(_storeSessionInteractor.execute(session)); } - void emptySpamFolderAction({Function? onCancelSelectionEmail, MailboxId? spamFolderId}) { + void emptySpamFolderAction({ + Function? onCancelSelectionEmail, + MailboxId? spamFolderId, + int totalEmails = 0 + }) { onCancelSelectionEmail?.call(); spamFolderId ??= spamMailboxId; @@ -2389,7 +2406,9 @@ class MailboxDashBoardController extends ReloadableController consumeState(_emptySpamFolderInteractor.execute( sessionCurrent!, accountId.value!, - spamFolderId + spamFolderId, + totalEmails, + _progressStateController )); } diff --git a/lib/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart b/lib/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart index 52f65afc53..806a063cf3 100644 --- a/lib/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart +++ b/lib/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart'; import 'package:tmail_ui_user/features/mailbox/domain/state/mark_as_mailbox_read_state.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/styles/mark_mailbox_as_read_loading_banner_style.dart'; +import 'package:tmail_ui_user/features/thread/domain/state/empty_spam_folder_state.dart'; class MarkMailboxAsReadLoadingBanner extends StatelessWidget with AppLoaderMixin { final Either viewState; @@ -25,13 +26,21 @@ class MarkMailboxAsReadLoadingBanner extends StatelessWidget with AppLoaderMixin child: horizontalLoadingWidget); } else if (success is UpdatingMarkAsMailboxReadState) { final percent = success.countRead / success.totalUnread; - return Padding( - padding: MarkMailboxAsReadLoadingBannerStyle.bannerMargin, - child: horizontalPercentLoadingWidget(percent)); + return _buildProgressBanner(percent); + } else if (success is EmptyingFolderState) { + final percent = success.countEmailsDeleted / success.totalEmails; + return _buildProgressBanner(percent); } else { return const SizedBox.shrink(); } } ); } + + Padding _buildProgressBanner(double percent) { + return Padding( + padding: MarkMailboxAsReadLoadingBannerStyle.bannerMargin, + child: horizontalPercentLoadingWidget(percent) + ); + } } \ No newline at end of file diff --git a/lib/features/thread/presentation/thread_view.dart b/lib/features/thread/presentation/thread_view.dart index 0e06890400..21eb085388 100644 --- a/lib/features/thread/presentation/thread_view.dart +++ b/lib/features/thread/presentation/thread_view.dart @@ -18,6 +18,8 @@ import 'package:tmail_ui_user/features/manage_account/presentation/vacation/widg import 'package:tmail_ui_user/features/network_connection/presentation/network_connection_banner_widget.dart'; import 'package:tmail_ui_user/features/quotas/presentation/widget/quotas_banner_widget.dart'; import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.dart'; +import 'package:tmail_ui_user/features/thread/domain/state/empty_spam_folder_state.dart'; +import 'package:tmail_ui_user/features/thread/domain/state/empty_trash_folder_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/get_all_email_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/search_email_state.dart'; import 'package:tmail_ui_user/features/thread/presentation/model/delete_action_type.dart'; @@ -868,7 +870,10 @@ class ThreadView extends GetWidget return viewState.fold( (failure) => const SizedBox.shrink(), (success) { - if (success is MarkAsMailboxReadLoading) { + if (success is MarkAsMailboxReadLoading + || success is EmptySpamFolderLoading + || success is EmptyTrashFolderLoading + ) { return Padding( padding: EdgeInsets.only( top: controller.responsiveUtils.isDesktop(context) ? 16 : 0, @@ -878,16 +883,23 @@ class ThreadView extends GetWidget child: horizontalLoadingWidget); } else if (success is UpdatingMarkAsMailboxReadState) { final percent = success.countRead / success.totalUnread; - return Padding( - padding: EdgeInsets.only( - top: controller.responsiveUtils.isDesktop(context) ? 16 : 0, - left: 16, - right: 16, - bottom: controller.responsiveUtils.isDesktop(context) ? 0 : 16), - child: horizontalPercentLoadingWidget(percent)); + return _buildProgressBanner(context, percent); + } else if (success is EmptyingFolderState) { + final percent = success.countEmailsDeleted / success.totalEmails; + return _buildProgressBanner(context, percent); } return const SizedBox.shrink(); }); }); } + + Padding _buildProgressBanner(BuildContext context, double percent) { + return Padding( + padding: EdgeInsets.only( + top: controller.responsiveUtils.isDesktop(context) ? 16 : 0, + left: 16, + right: 16, + bottom: controller.responsiveUtils.isDesktop(context) ? 0 : 16), + child: horizontalPercentLoadingWidget(percent)); + } } \ No newline at end of file