From 95dfd0eea6b64b8437b0ee35b489bd2660da8a71 Mon Sep 17 00:00:00 2001 From: dab246 Date: Thu, 5 Oct 2023 13:56:22 +0700 Subject: [PATCH] TF-2187 Handle click system back button to back to Inbox --- .../presentation/mailbox_controller.dart | 4 +- .../mailbox_dashboard_controller.dart | 4 +- .../sending_queue_controller.dart | 74 ++++--- .../presentation/sending_queue_view.dart | 77 +++---- .../presentation/thread_controller.dart | 10 + .../thread/presentation/thread_view.dart | 207 +++++++++--------- .../presentation_mailbox_extension.dart | 2 + 7 files changed, 199 insertions(+), 179 deletions(-) diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index f1025c46fa..98b284174d 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -266,9 +266,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM ever(mailboxDashBoardController.mailboxUIAction, (action) { if (action is SelectMailboxDefaultAction) { - if (mailboxDashBoardController.selectedMailbox.value == null) { - _switchBackToMailboxDefault(); - } + _switchBackToMailboxDefault(); mailboxDashBoardController.clearMailboxUIAction(); } else if (action is RefreshChangeMailboxAction) { if (action.newState != currentMailboxState) { 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 b6a9470c60..d72aab821f 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -1927,11 +1927,11 @@ class MailboxDashBoardController extends ReloadableController { listSendingEmails.value = success.sendingEmails; if (listSendingEmails.isEmpty && dashboardRoute.value == DashboardRoutes.sendingQueue) { - _openDefaultMailbox(); + openDefaultMailbox(); } } - void _openDefaultMailbox() { + void openDefaultMailbox() { dispatchRoute(DashboardRoutes.thread); dispatchMailboxUIAction(SelectMailboxDefaultAction()); } diff --git a/lib/features/sending_queue/presentation/sending_queue_controller.dart b/lib/features/sending_queue/presentation/sending_queue_controller.dart index d1d3caf863..95e70b129b 100644 --- a/lib/features/sending_queue/presentation/sending_queue_controller.dart +++ b/lib/features/sending_queue/presentation/sending_queue_controller.dart @@ -4,6 +4,7 @@ import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/resources/image_paths.dart'; import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/utils/app_toast.dart'; +import 'package:core/utils/platform_info.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; @@ -47,11 +48,11 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi final DeleteSendingEmailInteractor _deleteSendingEmailInteractor; final GetStoredSendingEmailInteractor _getStoredSendingEmailInteractor; - final dashboardController = getBinding(); - final _networkConnectionController = getBinding(); + final dashboardController = Get.find(); + final _networkConnectionController = Get.find(); final _sendingQueueIsolateManager = getBinding(); - final _imagePaths = getBinding(); - final _appToast = getBinding(); + final _imagePaths = Get.find(); + final _appToast = Get.find(); final listSendingEmailController = ScrollController(); @@ -114,20 +115,18 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi switch(newState) { case SendingState.waiting: case SendingState.running: - if (dashboardController != null) { - final listSendingEmails = dashboardController!.listSendingEmails - .map((sendingEmail) => sendingEmail.sendingId == sendingId - ? sendingEmail.updatingSendingState(newState) - : sendingEmail) - .toList(); - - dashboardController!.listSendingEmails.value = listSendingEmails; - } + final listSendingEmails = dashboardController.listSendingEmails + .map((sendingEmail) => sendingEmail.sendingId == sendingId + ? sendingEmail.updatingSendingState(newState) + : sendingEmail) + .toList(); + + dashboardController.listSendingEmails.value = listSendingEmails; break; case SendingState.canceled: case SendingState.error: if (accountId != null && userName != null) { - final matchedSendingEmail = dashboardController?.listSendingEmails.firstWhereOrNull((sendingEmail) => sendingEmail.sendingId == sendingId); + final matchedSendingEmail = dashboardController.listSendingEmails.firstWhereOrNull((sendingEmail) => sendingEmail.sendingId == sendingId); if (matchedSendingEmail != null) { _updateSendingEmailAction( newSendingEmail: matchedSendingEmail.updatingSendingState(newState), @@ -148,8 +147,8 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi } void handleOnLongPressAction(SendingEmail sendingEmail) { - final newListSendingEmail = dashboardController!.listSendingEmails.toggleSelection(sendingEmailSelected: sendingEmail); - dashboardController!.listSendingEmails.value = newListSendingEmail; + final newListSendingEmail = dashboardController.listSendingEmails.toggleSelection(sendingEmailSelected: sendingEmail); + dashboardController.listSendingEmails.value = newListSendingEmail; selectionState.value = newListSendingEmail.isAllUnSelected() ? SelectMode.INACTIVE @@ -157,31 +156,29 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi } void toggleSelectionSendingEmail(SendingEmail sendingEmail) { - final newListSendingEmail = dashboardController!.listSendingEmails.toggleSelection(sendingEmailSelected: sendingEmail); - dashboardController!.listSendingEmails.value = newListSendingEmail; + final newListSendingEmail = dashboardController.listSendingEmails.toggleSelection(sendingEmailSelected: sendingEmail); + dashboardController.listSendingEmails.value = newListSendingEmail; selectionState.value = newListSendingEmail.isAllUnSelected() ? SelectMode.INACTIVE : SelectMode.ACTIVE; } - bool get isAllUnSelected => dashboardController!.listSendingEmails.isAllUnSelected(); + bool get isAllUnSelected => dashboardController.listSendingEmails.isAllUnSelected(); - bool get isConnectedNetwork => _networkConnectionController?.isNetworkConnectionAvailable() == true; + bool get isConnectedNetwork => _networkConnectionController.isNetworkConnectionAvailable() == true; void refreshSendingQueue() { - if (dashboardController != null) { - dashboardController!.getAllSendingEmails(); - } + dashboardController.getAllSendingEmails(); } void openMailboxMenu() { - dashboardController!.openMailboxMenuDrawer(); + dashboardController.openMailboxMenuDrawer(); } void disableSelectionMode() { - final newListSendingEmail = dashboardController!.listSendingEmails.unAllSelected(); - dashboardController!.listSendingEmails.value = newListSendingEmail; + final newListSendingEmail = dashboardController.listSendingEmails.unAllSelected(); + dashboardController.listSendingEmails.value = newListSendingEmail; selectionState.value = SelectMode.INACTIVE; } @@ -213,7 +210,7 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi AppLocalizations.of(context).messageDialogDeleteSendingEmail, AppLocalizations.of(currentContext!).delete, title: AppLocalizations.of(currentContext!).deleteOfflineEmail, - icon: SvgPicture.asset(_imagePaths!.icDeleteDialogRecipients), + icon: SvgPicture.asset(_imagePaths.icDeleteDialogRecipients), alignCenter: true, messageStyle: const TextStyle( color: AppColor.colorTitleSendingItem, @@ -243,8 +240,8 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi void _handleDeleteListSendingEmail(List listSendingEmails) async { disableSelectionMode(); - final accountId = dashboardController!.accountId.value; - final session = dashboardController!.sessionCurrent; + final accountId = dashboardController.accountId.value; + final session = dashboardController.sessionCurrent; if (accountId != null && session != null) { consumeState( _deleteMultipleSendingEmailInteractor.execute( @@ -260,7 +257,7 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi await Future.wait(success.sendingIds.map(WorkManagerController().cancelByUniqueId)); if (currentContext != null && currentOverlayContext != null) { - _appToast!.showToastSuccessMessage( + _appToast.showToastSuccessMessage( currentOverlayContext!, AppLocalizations.of(currentContext!).messageHaveBeenDeletedSuccessfully); } @@ -270,14 +267,14 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi void _editSendingEmailAction(SendingEmail sendingEmail) { disableSelectionMode(); - dashboardController?.goToComposer(ComposerArguments.fromSendingEmail(sendingEmail)); + dashboardController.goToComposer(ComposerArguments.fromSendingEmail(sendingEmail)); } void _resendSendingEmailAction(List listSendingEmails) async { disableSelectionMode(); - final accountId = dashboardController!.accountId.value; - final session = dashboardController!.sessionCurrent; + final accountId = dashboardController.accountId.value; + final session = dashboardController.sessionCurrent; if (accountId != null && session != null) { consumeState( @@ -293,11 +290,11 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi void _handleResendSendingEmailSuccess(List newListSendingEmails) async { await Future.forEach(newListSendingEmails, (sendingEmail) async { await WorkManagerController().cancelByUniqueId(sendingEmail.sendingId); - dashboardController!.addSendingEmailToSendingQueue(sendingEmail); + dashboardController.addSendingEmailToSendingQueue(sendingEmail); }); if (currentContext != null && currentOverlayContext != null) { - _appToast!.showToastSuccessMessage( + _appToast.showToastSuccessMessage( currentOverlayContext!, AppLocalizations.of(currentContext!).messagesHaveBeenResent); } @@ -337,6 +334,13 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi ); } + Future backButtonPressedCallbackAction(BuildContext context) async { + if (PlatformInfo.isMobile) { + dashboardController.openDefaultMailbox(); + } + return false; + } + @override void handleSuccessViewState(Success success) { super.handleSuccessViewState(success); diff --git a/lib/features/sending_queue/presentation/sending_queue_view.dart b/lib/features/sending_queue/presentation/sending_queue_view.dart index 81f19d1862..c34834b894 100644 --- a/lib/features/sending_queue/presentation/sending_queue_view.dart +++ b/lib/features/sending_queue/presentation/sending_queue_view.dart @@ -19,43 +19,46 @@ class SendingQueueView extends GetWidget with AppLoaderM @override Widget build(BuildContext context) { - return Scaffold( - backgroundColor: Colors.white, - body: SafeArea( - child: Column( - children: [ - Obx(() { - return AppBarSendingQueueWidget( - listSendingEmailSelected: controller.dashboardController!.listSendingEmails.listSelected(), - onOpenMailboxMenu: controller.openMailboxMenu, - onBackAction: controller.disableSelectionMode, - selectMode: controller.selectionState.value, - ); - }), - const Divider(color: AppColor.colorDividerComposer, height: 1), - Obx(() { - if (!controller.isConnectedNetwork) { - return const BannerMessageSendingQueueWidget(); - } else { - return const SizedBox.shrink(); - } - }), - Expanded(child: _buildListSendingEmails(context)), - Obx(() { - if (controller.isAllUnSelected) { - return const SizedBox.shrink(); - } else { - return BottomBarSendingQueueWidget( - listSendingEmailSelected: controller.dashboardController!.listSendingEmails.listSelected(), - isConnectedNetwork: controller.isConnectedNetwork, - onHandleSendingEmailActionType: (actionType, listSendingEmails) => controller.handleSendingEmailActionType(context, actionType, listSendingEmails), + return WillPopScope( + onWillPop: () => controller.backButtonPressedCallbackAction.call(context), + child: Scaffold( + backgroundColor: Colors.white, + body: SafeArea( + child: Column( + children: [ + Obx(() { + return AppBarSendingQueueWidget( + listSendingEmailSelected: controller.dashboardController.listSendingEmails.listSelected(), + onOpenMailboxMenu: controller.openMailboxMenu, + onBackAction: controller.disableSelectionMode, + selectMode: controller.selectionState.value, ); - } - }), - ] + }), + const Divider(color: AppColor.colorDividerComposer, height: 1), + Obx(() { + if (!controller.isConnectedNetwork) { + return const BannerMessageSendingQueueWidget(); + } else { + return const SizedBox.shrink(); + } + }), + Expanded(child: _buildListSendingEmails(context)), + Obx(() { + if (controller.isAllUnSelected) { + return const SizedBox.shrink(); + } else { + return BottomBarSendingQueueWidget( + listSendingEmailSelected: controller.dashboardController.listSendingEmails.listSelected(), + isConnectedNetwork: controller.isConnectedNetwork, + onHandleSendingEmailActionType: (actionType, listSendingEmails) => controller.handleSendingEmailActionType(context, actionType, listSendingEmails), + ); + } + }), + ] + ), ), + floatingActionButton: _buildFloatingButtonCompose(), ), - floatingActionButton: _buildFloatingButtonCompose(), ); } @@ -74,7 +77,7 @@ class SendingQueueView extends GetWidget with AppLoaderM Widget _buildListViewItemSendingEmails() { return Obx(() { - final listSendingEmails = controller.dashboardController!.listSendingEmails; + final listSendingEmails = controller.dashboardController.listSendingEmails; if (listSendingEmails.isNotEmpty) { return ListView.builder( controller: controller.listSendingEmailController, @@ -104,14 +107,14 @@ class SendingQueueView extends GetWidget with AppLoaderM if (controller.isAllUnSelected) { return ComposeFloatingButton( scrollController: controller.listSendingEmailController, - onTap: () => controller.dashboardController!.goToComposer(ComposerArguments()) + onTap: () => controller.dashboardController.goToComposer(ComposerArguments()) ); } else { return Container( padding: const EdgeInsets.only(bottom: 70), child: ComposeFloatingButton( scrollController: controller.listSendingEmailController, - onTap: () => controller.dashboardController!.goToComposer(ComposerArguments()) + onTap: () => controller.dashboardController.goToComposer(ComposerArguments()) ), ); } diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index b0ad26ce9e..ca96898a56 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -1086,4 +1086,14 @@ class ThreadController extends BaseController with EmailActionController { return DismissDirection.startToEnd; } + + Future backButtonPressedCallbackAction(BuildContext context) async { + if (PlatformInfo.isMobile && + mailboxDashBoardController.selectedMailbox.value?.isInbox == false) { + mailboxDashBoardController.openDefaultMailbox(); + return false; + } else { + return true; + } + } } \ 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 62c51c59e8..5a2ce26c49 100644 --- a/lib/features/thread/presentation/thread_view.dart +++ b/lib/features/thread/presentation/thread_view.dart @@ -49,113 +49,116 @@ class ThreadView extends GetWidget @override Widget build(BuildContext context) { - return GestureDetector( - onTap: () => FocusManager.instance.primaryFocus?.unfocus(), - child: Scaffold( - resizeToAvoidBottomInset: false, - backgroundColor: Colors.white, - body: Portal( - child: Row(children: [ - if (supportVerticalDivider(context)) - const VerticalDivider(color: AppColor.colorDividerVertical, width: 1), - Expanded(child: SafeArea( - right: _responsiveUtils.isLandscapeMobile(context), - left: _responsiveUtils.isLandscapeMobile(context), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (!_responsiveUtils.isWebDesktop(context)) - ... [ - Obx(() { - return AppBarThreadWidget( - mailboxSelected: controller.currentMailbox, - listEmailSelected: controller.mailboxDashBoardController.emailsInCurrentMailbox.listEmailSelected, - selectMode: controller.mailboxDashBoardController.currentSelectMode.value, - filterOption: controller.mailboxDashBoardController.filterMessageOption.value, - openMailboxAction: controller.openMailboxLeftMenu, - cancelEditThreadAction: controller.cancelSelectEmail, - editThreadAction: controller.enableSelectionEmail, - emailSelectionAction: (actionType, selectionEmail) { - return controller.pressEmailSelectionAction( - context, - actionType, - selectionEmail - ); - }, - onContextMenuFilterEmailAction: _responsiveUtils.isScreenWithShortestSide(context) - ? (filterOption) => controller.openContextMenuAction( - context, - _filterMessagesCupertinoActionTile(context, filterOption) - ) - : null, - onPopupMenuFilterEmailAction: !_responsiveUtils.isScreenWithShortestSide(context) - ? (filterOption, position) => controller.openPopupMenuAction( + return WillPopScope( + onWillPop: () => controller.backButtonPressedCallbackAction(context), + child: GestureDetector( + onTap: () => FocusManager.instance.primaryFocus?.unfocus(), + child: Scaffold( + resizeToAvoidBottomInset: false, + backgroundColor: Colors.white, + body: Portal( + child: Row(children: [ + if (supportVerticalDivider(context)) + const VerticalDivider(color: AppColor.colorDividerVertical, width: 1), + Expanded(child: SafeArea( + right: _responsiveUtils.isLandscapeMobile(context), + left: _responsiveUtils.isLandscapeMobile(context), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (!_responsiveUtils.isWebDesktop(context)) + ... [ + Obx(() { + return AppBarThreadWidget( + mailboxSelected: controller.currentMailbox, + listEmailSelected: controller.mailboxDashBoardController.emailsInCurrentMailbox.listEmailSelected, + selectMode: controller.mailboxDashBoardController.currentSelectMode.value, + filterOption: controller.mailboxDashBoardController.filterMessageOption.value, + openMailboxAction: controller.openMailboxLeftMenu, + cancelEditThreadAction: controller.cancelSelectEmail, + editThreadAction: controller.enableSelectionEmail, + emailSelectionAction: (actionType, selectionEmail) { + return controller.pressEmailSelectionAction( context, - position, - popupMenuFilterEmailActionTile( + actionType, + selectionEmail + ); + }, + onContextMenuFilterEmailAction: _responsiveUtils.isScreenWithShortestSide(context) + ? (filterOption) => controller.openContextMenuAction( context, - filterOption, - (option) => controller.filterMessagesAction(context, option) + _filterMessagesCupertinoActionTile(context, filterOption) ) - ) - : null - ); - }), - if (!PlatformInfo.isWeb) - Obx(() { - if (!controller.networkConnectionController.isNetworkConnectionAvailable()) { - return const Padding( - padding: EdgeInsetsDirectional.only(bottom: 8), - child: NetworkConnectionBannerWidget()); - } else { - return const SizedBox.shrink(); - } + : null, + onPopupMenuFilterEmailAction: !_responsiveUtils.isScreenWithShortestSide(context) + ? (filterOption, position) => controller.openPopupMenuAction( + context, + position, + popupMenuFilterEmailActionTile( + context, + filterOption, + (option) => controller.filterMessagesAction(context, option) + ) + ) + : null + ); }), - _buildSearchBarView(context), - const SpamReportBannerWidget(), - const QuotasBannerWidget(), - _buildVacationNotificationMessage(context), - ], - Obx(() { - if (controller.mailboxDashBoardController.isEmptyTrashBannerEnabledOnMobile(context)) { - return Padding( - padding: const EdgeInsetsDirectional.symmetric( - horizontal: BannerEmptyTrashStyles.mobileMargin - ), - child: BannerEmptyTrashWidget( - onTapAction: () => controller.deleteSelectionEmailsPermanently(context, DeleteActionType.all) - ), - ); - } else { - return const SizedBox.shrink(); - } - }), - Obx(() { - if (controller.mailboxDashBoardController.isEmptySpamBannerEnabledOnMobile(context)) { - return Padding( - padding: const EdgeInsetsDirectional.symmetric( - horizontal: BannerDeleteAllSpamEmailsStyles.mobileMargin - ), - child: BannerDeleteAllSpamEmailsWidget( - onTapAction: () => controller.mailboxDashBoardController.openDialogEmptySpamFolder(context) - ), - ); - } else { - return const SizedBox.shrink(); - } - }), - if (!_responsiveUtils.isDesktop(context)) - _buildMarkAsMailboxReadLoading(context), - Obx(() => ThreadViewLoadingBarWidget(viewState: controller.viewState.value)), - Expanded(child: _buildListEmail(context)), - Obx(() => ThreadViewBottomLoadingBarWidget(viewState: controller.viewState.value)), - _buildListButtonSelectionForMobile(context), - ] - ) - )) - ]), + if (!PlatformInfo.isWeb) + Obx(() { + if (!controller.networkConnectionController.isNetworkConnectionAvailable()) { + return const Padding( + padding: EdgeInsetsDirectional.only(bottom: 8), + child: NetworkConnectionBannerWidget()); + } else { + return const SizedBox.shrink(); + } + }), + _buildSearchBarView(context), + const SpamReportBannerWidget(), + const QuotasBannerWidget(), + _buildVacationNotificationMessage(context), + ], + Obx(() { + if (controller.mailboxDashBoardController.isEmptyTrashBannerEnabledOnMobile(context)) { + return Padding( + padding: const EdgeInsetsDirectional.symmetric( + horizontal: BannerEmptyTrashStyles.mobileMargin + ), + child: BannerEmptyTrashWidget( + onTapAction: () => controller.deleteSelectionEmailsPermanently(context, DeleteActionType.all) + ), + ); + } else { + return const SizedBox.shrink(); + } + }), + Obx(() { + if (controller.mailboxDashBoardController.isEmptySpamBannerEnabledOnMobile(context)) { + return Padding( + padding: const EdgeInsetsDirectional.symmetric( + horizontal: BannerDeleteAllSpamEmailsStyles.mobileMargin + ), + child: BannerDeleteAllSpamEmailsWidget( + onTapAction: () => controller.mailboxDashBoardController.openDialogEmptySpamFolder(context) + ), + ); + } else { + return const SizedBox.shrink(); + } + }), + if (!_responsiveUtils.isDesktop(context)) + _buildMarkAsMailboxReadLoading(context), + Obx(() => ThreadViewLoadingBarWidget(viewState: controller.viewState.value)), + Expanded(child: _buildListEmail(context)), + Obx(() => ThreadViewBottomLoadingBarWidget(viewState: controller.viewState.value)), + _buildListButtonSelectionForMobile(context), + ] + ) + )) + ]), + ), + floatingActionButton: _buildFloatingButtonCompose(context), ), - floatingActionButton: _buildFloatingButtonCompose(context), ), ); } diff --git a/model/lib/extensions/presentation_mailbox_extension.dart b/model/lib/extensions/presentation_mailbox_extension.dart index f409eb231d..9efa5d7140 100644 --- a/model/lib/extensions/presentation_mailbox_extension.dart +++ b/model/lib/extensions/presentation_mailbox_extension.dart @@ -29,6 +29,8 @@ extension PresentationMailboxExtension on PresentationMailbox { int get countTotalEmails => totalEmails?.value.value.toInt() ?? 0; + bool get isInbox => role == PresentationMailbox.roleInbox; + bool get isSpam => role == PresentationMailbox.roleSpam; bool get isTrash => role == PresentationMailbox.roleTrash;