TF-2827 Only enable print button when email content loaded
This commit is contained in:
@@ -29,6 +29,7 @@ import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/base/state/button_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/email_action_type_extension.dart';
|
||||
import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
@@ -145,11 +146,11 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
final emailUnsubscribe = Rxn<EmailUnsubscribe>();
|
||||
final attachmentsViewState = RxMap<Id, Either<Failure, Success>>();
|
||||
final isEmailContentHidden = RxBool(false);
|
||||
final currentEmailLoaded = Rxn<EmailLoaded>();
|
||||
|
||||
EmailId? _currentEmailId;
|
||||
Identity? _identitySelected;
|
||||
EmailLoaded? _currentEmailLoaded;
|
||||
PrintEmailAction? _printEmailAction;
|
||||
ButtonState? _printEmailButtonState;
|
||||
|
||||
final StreamController<Either<Failure, Success>> _downloadProgressStateController =
|
||||
StreamController<Either<Failure, Success>>.broadcast();
|
||||
@@ -157,8 +158,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
PresentationEmail? get currentEmail => mailboxDashBoardController.selectedEmail.value;
|
||||
|
||||
EmailLoaded? get currentEmailLoaded => _currentEmailLoaded;
|
||||
|
||||
bool get calendarEventProcessing => viewState.value.fold(
|
||||
(failure) => false,
|
||||
(success) => success is CalendarEventReplying || success is StoreEventAttendanceStatusLoading);
|
||||
@@ -499,12 +498,12 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
}
|
||||
emailSupervisorController.popEmailQueue(success.emailCurrent?.id);
|
||||
|
||||
_currentEmailLoaded = EmailLoaded(
|
||||
currentEmailLoaded.value = EmailLoaded(
|
||||
htmlContent: success.htmlEmailContent,
|
||||
attachments: List.of(success.attachments),
|
||||
emailCurrent: success.emailCurrent,
|
||||
);
|
||||
emailSupervisorController.pushEmailQueue(_currentEmailLoaded!);
|
||||
emailSupervisorController.pushEmailQueue(currentEmailLoaded.value!);
|
||||
|
||||
if (success.emailCurrent?.id == currentEmail?.id) {
|
||||
attachments.value = success.attachments;
|
||||
@@ -543,12 +542,12 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
}
|
||||
emailSupervisorController.popEmailQueue(success.emailCurrent?.id);
|
||||
|
||||
_currentEmailLoaded = EmailLoaded(
|
||||
currentEmailLoaded.value = EmailLoaded(
|
||||
htmlContent: success.htmlEmailContent,
|
||||
attachments: List.of(success.attachments),
|
||||
emailCurrent: success.emailCurrent,
|
||||
);
|
||||
emailSupervisorController.pushEmailQueue(_currentEmailLoaded!);
|
||||
emailSupervisorController.pushEmailQueue(currentEmailLoaded.value!);
|
||||
|
||||
if (success.emailCurrent?.id == currentEmail?.id) {
|
||||
attachments.value = success.attachments;
|
||||
@@ -567,13 +566,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
emailContents.value = success.htmlEmailContent;
|
||||
}
|
||||
|
||||
if (_printEmailAction != null) {
|
||||
_handlePrintEmailWhenEmailContentLoaded(
|
||||
action: _printEmailAction!,
|
||||
emailLoaded: _currentEmailLoaded!
|
||||
);
|
||||
}
|
||||
|
||||
if (PlatformInfo.isMobile) {
|
||||
final detailedEmail = DetailedEmail(
|
||||
emailId: currentEmail!.id!,
|
||||
@@ -627,12 +619,11 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
void _resetToOriginalValue({bool isEmailClosing = false}) {
|
||||
emailContents.value = null;
|
||||
_currentEmailLoaded = null;
|
||||
currentEmailLoaded.value = null;
|
||||
attachments.clear();
|
||||
attachmentsViewState.value = {};
|
||||
blobCalendarEvent.value = null;
|
||||
emailUnsubscribe.value = null;
|
||||
_printEmailAction = null;
|
||||
_identitySelected = null;
|
||||
if (isEmailClosing) {
|
||||
emailLoadedViewState.value = Right(UIState.idle);
|
||||
@@ -1350,10 +1341,10 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
mailboxDashBoardController.goToComposer(
|
||||
ComposerArguments.replyEmail(
|
||||
presentationEmail: presentationEmail,
|
||||
content: _currentEmailLoaded?.htmlContent ?? '',
|
||||
content: currentEmailLoaded.value?.htmlContent ?? '',
|
||||
mailboxRole: presentationEmail.mailboxContain?.role,
|
||||
messageId: _currentEmailLoaded?.emailCurrent?.messageId,
|
||||
references: _currentEmailLoaded?.emailCurrent?.references,
|
||||
messageId: currentEmailLoaded.value?.emailCurrent?.messageId,
|
||||
references: currentEmailLoaded.value?.emailCurrent?.references,
|
||||
)
|
||||
);
|
||||
break;
|
||||
@@ -1361,10 +1352,10 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
mailboxDashBoardController.goToComposer(
|
||||
ComposerArguments.replyAllEmail(
|
||||
presentationEmail: presentationEmail,
|
||||
content: _currentEmailLoaded?.htmlContent ?? '',
|
||||
content: currentEmailLoaded.value?.htmlContent ?? '',
|
||||
mailboxRole: presentationEmail.mailboxContain?.role,
|
||||
messageId: _currentEmailLoaded?.emailCurrent?.messageId,
|
||||
references: _currentEmailLoaded?.emailCurrent?.references,
|
||||
messageId: currentEmailLoaded.value?.emailCurrent?.messageId,
|
||||
references: currentEmailLoaded.value?.emailCurrent?.references,
|
||||
)
|
||||
);
|
||||
break;
|
||||
@@ -1372,10 +1363,10 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
mailboxDashBoardController.goToComposer(
|
||||
ComposerArguments.forwardEmail(
|
||||
presentationEmail: presentationEmail,
|
||||
content: _currentEmailLoaded?.htmlContent ?? '',
|
||||
content: currentEmailLoaded.value?.htmlContent ?? '',
|
||||
attachments: attachments,
|
||||
messageId: _currentEmailLoaded?.emailCurrent?.messageId,
|
||||
references: _currentEmailLoaded?.emailCurrent?.references,
|
||||
messageId: currentEmailLoaded.value?.emailCurrent?.messageId,
|
||||
references: currentEmailLoaded.value?.emailCurrent?.references,
|
||||
)
|
||||
);
|
||||
break;
|
||||
@@ -1478,7 +1469,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
void _handleParseCalendarEventFailure(ParseCalendarEventFailure failure) {
|
||||
emailLoadedViewState.value = Left<Failure, Success>(failure);
|
||||
emailContents.value = _currentEmailLoaded?.htmlContent;
|
||||
emailContents.value = currentEmailLoaded.value?.htmlContent;
|
||||
}
|
||||
|
||||
void _enableScrollPageView() {
|
||||
@@ -1595,26 +1586,34 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
}
|
||||
|
||||
void _printEmail(BuildContext context, PresentationEmail email) {
|
||||
if (_printEmailAction != null) {
|
||||
if (_printEmailButtonState == ButtonState.disabled) {
|
||||
log('SingleEmailController::_printEmail: Print email started');
|
||||
return;
|
||||
}
|
||||
|
||||
_printEmailAction = PrintEmailAction(
|
||||
context: context,
|
||||
userEmail: mailboxDashBoardController.userEmail,
|
||||
email: email
|
||||
);
|
||||
consumeState(Stream.value(Right(PrintEmailLoading())));
|
||||
_printEmailButtonState = ButtonState.disabled;
|
||||
|
||||
if (_currentEmailLoaded == null) {
|
||||
log('SingleEmailController::_printEmail: Email content loading');
|
||||
return;
|
||||
}
|
||||
|
||||
_handlePrintEmailWhenEmailContentLoaded(
|
||||
action: _printEmailAction!,
|
||||
emailLoaded: _currentEmailLoaded!
|
||||
consumeState(
|
||||
_printEmailInteractor.execute(
|
||||
EmailPrint(
|
||||
appName: AppLocalizations.of(context).app_name,
|
||||
userName: mailboxDashBoardController.userEmail,
|
||||
emailInformation: email.toEmail(),
|
||||
attachments: currentEmailLoaded.value!.attachments,
|
||||
emailContent: currentEmailLoaded.value!.htmlContent,
|
||||
locale: Localizations.localeOf(context).toLanguageTag(),
|
||||
fromPrefix: AppLocalizations.of(context).from_email_address_prefix,
|
||||
toPrefix: AppLocalizations.of(context).to_email_address_prefix,
|
||||
ccPrefix: AppLocalizations.of(context).cc_email_address_prefix,
|
||||
bccPrefix: AppLocalizations.of(context).bcc_email_address_prefix,
|
||||
replyToPrefix: AppLocalizations.of(context).replyToEmailAddressPrefix,
|
||||
titleAttachment: AppLocalizations.of(context).attachments.toLowerCase(),
|
||||
toAddress: email.to?.listEmailAddressToString(isFullEmailAddress: true),
|
||||
ccAddress: email.cc?.listEmailAddressToString(isFullEmailAddress: true),
|
||||
bccAddress: email.bcc?.listEmailAddressToString(isFullEmailAddress: true),
|
||||
replyToAddress: email.replyTo?.listEmailAddressToString(isFullEmailAddress: true),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1629,11 +1628,11 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
}
|
||||
|
||||
void _handlePrintEmailSuccess(PrintEmailSuccess success) {
|
||||
_printEmailAction = null;
|
||||
_printEmailButtonState = ButtonState.enabled;
|
||||
}
|
||||
|
||||
void _showMessageWhenEmailPrintingFailed(PrintEmailFailure failure) {
|
||||
_printEmailAction = null;
|
||||
_printEmailButtonState = ButtonState.enabled;
|
||||
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastErrorMessage(
|
||||
@@ -1642,23 +1641,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePrintEmailWhenEmailContentLoaded({
|
||||
required PrintEmailAction action,
|
||||
required EmailLoaded emailLoaded
|
||||
}) {
|
||||
if (action.email.id != emailLoaded.emailCurrent?.id) {
|
||||
log('SingleEmailController::_handlePrintEmailInQueue: Print email action NOT matched email id');
|
||||
_printEmailAction = null;
|
||||
return;
|
||||
}
|
||||
|
||||
consumeState(
|
||||
_printEmailInteractor.execute(
|
||||
EmailPrint.generate(printEmailAction: action, emailLoaded: emailLoaded)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void onCalendarEventReplyAction(EventActionType eventActionType, EmailId emailId) {
|
||||
switch (eventActionType) {
|
||||
case EventActionType.yes:
|
||||
|
||||
Reference in New Issue
Block a user