Skip to content

Commit

Permalink
TF-2187 Handle click system back button to back to Inbox
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 authored and hoangdat committed Oct 6, 2023
1 parent 47d1c2e commit 95dfd0e
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 179 deletions.
4 changes: 1 addition & 3 deletions lib/features/mailbox/presentation/mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -47,11 +48,11 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
final DeleteSendingEmailInteractor _deleteSendingEmailInteractor;
final GetStoredSendingEmailInteractor _getStoredSendingEmailInteractor;

final dashboardController = getBinding<MailboxDashBoardController>();
final _networkConnectionController = getBinding<NetworkConnectionController>();
final dashboardController = Get.find<MailboxDashBoardController>();
final _networkConnectionController = Get.find<NetworkConnectionController>();
final _sendingQueueIsolateManager = getBinding<SendingQueueIsolateManager>();
final _imagePaths = getBinding<ImagePaths>();
final _appToast = getBinding<AppToast>();
final _imagePaths = Get.find<ImagePaths>();
final _appToast = Get.find<AppToast>();

final listSendingEmailController = ScrollController();

Expand Down Expand Up @@ -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),
Expand All @@ -148,40 +147,38 @@ 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
: SelectMode.ACTIVE;
}

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;
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -243,8 +240,8 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
void _handleDeleteListSendingEmail(List<SendingEmail> 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(
Expand All @@ -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);
}
Expand All @@ -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<SendingEmail> 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(
Expand All @@ -293,11 +290,11 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
void _handleResendSendingEmailSuccess(List<SendingEmail> newListSendingEmails) async {
await Future.forEach<SendingEmail>(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);
}
Expand Down Expand Up @@ -337,6 +334,13 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
);
}

Future<bool> backButtonPressedCallbackAction(BuildContext context) async {
if (PlatformInfo.isMobile) {
dashboardController.openDefaultMailbox();
}
return false;
}

@override
void handleSuccessViewState(Success success) {
super.handleSuccessViewState(success);
Expand Down
77 changes: 40 additions & 37 deletions lib/features/sending_queue/presentation/sending_queue_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,46 @@ class SendingQueueView extends GetWidget<SendingQueueController> 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(),
);
}

Expand All @@ -74,7 +77,7 @@ class SendingQueueView extends GetWidget<SendingQueueController> 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,
Expand Down Expand Up @@ -104,14 +107,14 @@ class SendingQueueView extends GetWidget<SendingQueueController> 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())
),
);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/features/thread/presentation/thread_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1086,4 +1086,14 @@ class ThreadController extends BaseController with EmailActionController {

return DismissDirection.startToEnd;
}

Future<bool> backButtonPressedCallbackAction(BuildContext context) async {
if (PlatformInfo.isMobile &&
mailboxDashBoardController.selectedMailbox.value?.isInbox == false) {
mailboxDashBoardController.openDefaultMailbox();
return false;
} else {
return true;
}
}
}
Loading

0 comments on commit 95dfd0e

Please sign in to comment.