TF-1915 Updating correctly state sending email when work manager running

(cherry picked from commit 60b5683cddc2f8c026935528002c736f74018798)
This commit is contained in:
dab246
2023-06-09 19:32:31 +07:00
committed by Dat Vu
parent af73f90508
commit 8efc741090
11 changed files with 180 additions and 123 deletions
@@ -1,6 +1,7 @@
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/usecases/delete_multiple_sending_email_interactor.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/usecases/update_sending_email_interactor.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/sending_queue_controller.dart';
class SendingQueueBindings extends Bindings {
@@ -11,6 +12,9 @@ class SendingQueueBindings extends Bindings {
}
void _bindingsController() {
Get.put(SendingQueueController(Get.find<DeleteMultipleSendingEmailInteractor>()));
Get.put(SendingQueueController(
Get.find<DeleteMultipleSendingEmailInteractor>(),
Get.find<UpdateSendingEmailInteractor>(),
));
}
}
@@ -16,8 +16,4 @@ extension ListSendingEmailExtension on List<SendingEmail> {
bool isAllUnSelected() => every((sendingEmail) => !sendingEmail.isSelected);
List<SendingEmail> listSelected() => where((sendingEmail) => sendingEmail.isSelected).toList();
bool isAllNotReadySendingState() => every((sendingEmail) => !sendingEmail.isReady);
bool isAllNotDeliveringSendingState() => every((sendingEmail) => !sendingEmail.isDelivering);
}
@@ -13,11 +13,14 @@ import 'package:model/extensions/list_email_content_extension.dart';
import 'package:model/mailbox/select_mode.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_mixin.dart';
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
import 'package:tmail_ui_user/features/network_status_handle/presentation/network_connnection_controller.dart';
import 'package:tmail_ui_user/features/offline_mode/scheduler/worker_state.dart';
import 'package:tmail_ui_user/features/offline_mode/model/sending_state.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/model/sending_email.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/state/update_sending_email_state.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/usecases/update_sending_email_interactor.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/utils/sending_queue_isolate_manager.dart';
import 'package:tmail_ui_user/features/offline_mode/controller/work_scheduler_controller.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/state/delete_multiple_sending_email_state.dart';
@@ -30,6 +33,7 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
class SendingQueueController extends BaseController with MessageDialogActionMixin {
final DeleteMultipleSendingEmailInteractor _deleteMultipleSendingEmailInteractor;
final UpdateSendingEmailInteractor _updateSendingEmailInteractor;
final dashboardController = getBinding<MailboxDashBoardController>();
final _networkConnectionController = getBinding<NetworkConnectionController>();
@@ -41,7 +45,10 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
final selectionState = Rx<SelectMode>(SelectMode.INACTIVE);
SendingQueueController(this._deleteMultipleSendingEmailInteractor);
SendingQueueController(
this._deleteMultipleSendingEmailInteractor,
this._updateSendingEmailInteractor,
);
@override
void onInit() {
@@ -56,12 +63,36 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
void _handleSendingQueueEvent(Object? event) {
log('SendingQueueController::_handleSendingQueueEvent():event: $event');
if (event is String) {
final workState = WorkerState.values.firstWhereOrNull((state) => state.name == event);
log('SendingQueueController::_handleSendingQueueEvent():workState: $workState');
if (workState != null) {
refreshSendingQueue(needToReopen: true);
try {
if (event is String) {
final tupleKey = TupleKey.fromString(event);
final sendingId = tupleKey.parts[0];
final sendingState = SendingState.values.firstWhereOrNull((state) => state.name == tupleKey.parts[1]);
log('SendingQueueController::_handleSendingQueueEvent():sendingId: $sendingId | sendingState: $sendingState');
if (sendingState != null) {
switch(sendingState) {
case SendingState.waiting:
_handleSendingStateRunningEvent(sendingId);
break;
case SendingState.running:
case SendingState.success:
case SendingState.error:
refreshSendingQueue(needToReopen: true);
break;
}
}
}
} catch (e) {
logError('SendingQueueController::_handleSendingQueueEvent(): EXCEPTION: $e');
}
}
void _handleSendingStateRunningEvent(String sendingId) {
log('SendingQueueController::_handleSendingStateRunningEvent():sendingId: $sendingId');
final matchedSendingEmail = dashboardController!.listSendingEmails.firstWhereOrNull((sendingEmail) => sendingEmail.sendingId == sendingId);
if (matchedSendingEmail != null) {
_updateSendingEmailAction(matchedSendingEmail);
}
}
@@ -200,12 +231,27 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
selectionState.value = SelectMode.INACTIVE;
}
void _updateSendingEmailAction(SendingEmail newSendingEmail) {
final accountId = dashboardController!.accountId.value;
final session = dashboardController!.sessionCurrent;
if (accountId != null && session != null) {
consumeState(_updateSendingEmailInteractor.execute(
accountId,
session.username,
newSendingEmail,
needToReopen: true
));
}
}
@override
void handleSuccessViewState(Success success) {
super.handleSuccessViewState(success);
if (success is DeleteMultipleSendingEmailAllSuccess ||
success is DeleteMultipleSendingEmailHasSomeSuccess) {
_handleDeleteSendingEmailSuccess();
} else if (success is UpdateSendingEmailSuccess) {
refreshSendingQueue(needToReopen: true);
}
}
@@ -34,7 +34,7 @@ class SendingQueueView extends GetWidget<SendingQueueController> with AppLoaderM
}),
const Divider(color: AppColor.colorDividerComposer, height: 1),
Obx(() {
if (!controller.dashboardController!.listSendingEmails.isAllNotReadySendingState()) {
if (!controller.isConnectedNetwork) {
return const BannerMessageSendingQueueWidget();
} else {
return const SizedBox.shrink();
@@ -87,7 +87,7 @@ class SendingQueueView extends GetWidget<SendingQueueController> with AppLoaderM
onLongPressAction: controller.handleOnLongPressAction,
onSelectLeadingAction: controller.toggleSelectionSendingEmail,
onTapAction: (actionType, sendingEmail) {
if (!controller.isConnectedNetwork && sendingEmail.isReady) {
if (!controller.isConnectedNetwork && sendingEmail.isWaiting) {
controller.handleSendingEmailActionType(context, actionType, [sendingEmail]);
}
});
@@ -1,7 +1,6 @@
import 'package:core/core.dart';
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/model/sending_email.dart';
class SendingQueueUtils {
@@ -29,11 +28,11 @@ class SendingQueueUtils {
}
}
static EdgeInsets getPaddingDividerListViewByResponsiveSize(double width, SendingEmail sendingEmail) {
static EdgeInsets getPaddingDividerListViewByResponsiveSize(double width) {
if (ResponsiveUtils.isMatchedMobileWidth(width)) {
return EdgeInsets.only(left: 84, right: 8, top: sendingEmail.isReady ? 0 : 8);
return const EdgeInsets.only(left: 84, right: 8, top: 8);
} else {
return EdgeInsets.only(left: 100, right: 24, top: sendingEmail.isReady ? 0 : 8);
return const EdgeInsets.only(left: 100, right: 24, top: 8);
}
}
}
@@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/base/state/button_state.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/model/sending_email.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/extensions/list_sending_email_extension.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/model/sending_email_action_type.dart';
typedef OnHandleSendingEmailActionType = void Function(SendingEmailActionType, List<SendingEmail>);
@@ -54,15 +53,11 @@ class BottomBarSendingQueueWidget extends StatelessWidget {
).build()),
Expanded(child: (ButtonBuilder(imagePaths.icDeleteComposer)
..key(Key(SendingEmailActionType.delete.getButtonKey()))
..iconColor(SendingEmailActionType.delete.getButtonIconColor(_isCanBeDeleted ? ButtonState.enabled : ButtonState.disabled))
..iconColor(SendingEmailActionType.delete.getButtonIconColor(ButtonState.enabled))
..padding(const EdgeInsets.all(8))
..radiusSplash(8)
..textStyle(TextStyle(fontSize: 12, color: SendingEmailActionType.delete.getButtonTitleColor(_isCanBeDeleted ? ButtonState.enabled : ButtonState.disabled)))
..onPressActionClick(() {
if (_isCanBeDeleted) {
onHandleSendingEmailActionType?.call(SendingEmailActionType.delete, listSendingEmailSelected);
}
})
..textStyle(TextStyle(fontSize: 12, color: SendingEmailActionType.delete.getButtonTitleColor(ButtonState.enabled)))
..onPressActionClick(() => onHandleSendingEmailActionType?.call(SendingEmailActionType.delete, listSendingEmailSelected))
..text(SendingEmailActionType.delete.getButtonTitle(context), isVertical: true)
).build())
],
@@ -72,7 +67,5 @@ class BottomBarSendingQueueWidget extends StatelessWidget {
bool get _isEditable => !isConnectedNetwork &&
listSendingEmailSelected.length == 1 &&
listSendingEmailSelected.first.isReady;
bool get _isCanBeDeleted => listSendingEmailSelected.isAllNotDeliveringSendingState();
listSendingEmailSelected.first.isWaiting;
}
@@ -97,9 +97,7 @@ class SendingEmailTileWidget extends StatelessWidget {
maxLines: 1,
style: TextStyle(
fontSize: 15,
color: sendingEmail.isDelivering
? AppColor.colorDeliveringState
: Colors.black,
color: sendingEmail.sendingState.getTitleSendingEmailItemColor(),
fontWeight: FontWeight.w600
)
)),
@@ -122,14 +120,12 @@ class SendingEmailTileWidget extends StatelessWidget {
overflow: CommonTextStyle.defaultTextOverFlow,
style: TextStyle(
fontSize: 13,
color: sendingEmail.isDelivering
? AppColor.colorDeliveringState
: Colors.black,
color: sendingEmail.sendingState.getTitleSendingEmailItemColor(),
fontWeight: FontWeight.normal
)
)
),
if (!sendingEmail.isReady && !ResponsiveUtils.isMatchedMobileWidth(constraints.maxWidth))
if (!ResponsiveUtils.isMatchedMobileWidth(constraints.maxWidth))
Container(
margin: const EdgeInsets.only(left: 8),
width: 120,
@@ -153,13 +149,11 @@ class SendingEmailTileWidget extends StatelessWidget {
maxLines: 1,
style: TextStyle(
fontSize: 13,
color: sendingEmail.isDelivering
? AppColor.colorDeliveringState
: AppColor.colorTitleSendingItem,
color: sendingEmail.sendingState.getSubTitleSendingEmailItemColor(),
fontWeight: FontWeight.normal
)
),
if (!sendingEmail.isReady && ResponsiveUtils.isMatchedMobileWidth(constraints.maxWidth))
if (ResponsiveUtils.isMatchedMobileWidth(constraints.maxWidth))
Padding(
padding: const EdgeInsets.only(top: 8),
child: SendingStateWidget(sendingState: sendingEmail.sendingState))
@@ -168,7 +162,7 @@ class SendingEmailTileWidget extends StatelessWidget {
]),
),
Padding(
padding: SendingQueueUtils.getPaddingDividerListViewByResponsiveSize(constraints.maxWidth, sendingEmail),
padding: SendingQueueUtils.getPaddingDividerListViewByResponsiveSize(constraints.maxWidth),
child: const Divider(
color: AppColor.lineItemListColor,
height: 1,