From 950a0363bf26f633dcb9f1237eb365c3368223a1 Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 25 Oct 2022 02:44:19 +0700 Subject: [PATCH] TF-1074 Handle go to path `/identity_creator` --- .../mixin/view_as_dialog_action_mixin.dart | 33 +++ .../contact/presentation/contact_view.dart | 1 - .../presentation/destination_picker_view.dart | 1 - .../identity_creator_bindings.dart | 4 + .../identity_creator_controller.dart | 198 ++++++++++-------- .../presentation/identity_creator_view.dart | 55 +++-- .../identity_drop_list_field_builder.dart | 6 +- ...ty_input_with_drop_list_field_builder.dart | 2 +- .../mailbox_creator_controller.dart | 1 + .../presentation/mailbox_creator_view.dart | 1 - .../manage_account_dashboard_controller.dart | 1 - .../manage_account_dashboard_view.dart | 3 - .../identities/identities_controller.dart | 81 ++++--- .../profiles/identities/identities_view.dart | 15 +- lib/main/pages/app_pages.dart | 11 +- lib/main/routes/app_routes.dart | 2 +- 16 files changed, 255 insertions(+), 160 deletions(-) diff --git a/lib/features/base/mixin/view_as_dialog_action_mixin.dart b/lib/features/base/mixin/view_as_dialog_action_mixin.dart index bdde6e72c..b7e87d79e 100644 --- a/lib/features/base/mixin/view_as_dialog_action_mixin.dart +++ b/lib/features/base/mixin/view_as_dialog_action_mixin.dart @@ -1,4 +1,5 @@ +import 'package:core/utils/app_logger.dart'; import 'package:flutter/material.dart'; import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; import 'package:model/mailbox/presentation_mailbox.dart'; @@ -8,6 +9,9 @@ import 'package:tmail_ui_user/features/contact/presentation/model/contact_argume import 'package:tmail_ui_user/features/destination_picker/presentation/destination_picker_bindings.dart'; import 'package:tmail_ui_user/features/destination_picker/presentation/destination_picker_view.dart'; import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart'; +import 'package:tmail_ui_user/features/identity_creator/presentation/identity_creator_bindings.dart'; +import 'package:tmail_ui_user/features/identity_creator/presentation/identity_creator_view.dart'; +import 'package:tmail_ui_user/features/identity_creator/presentation/model/identity_creator_arguments.dart'; import 'package:tmail_ui_user/features/mailbox_creator/presentation/mailbox_creator_bindings.dart'; import 'package:tmail_ui_user/features/mailbox_creator/presentation/mailbox_creator_view.dart'; import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart'; @@ -103,4 +107,33 @@ mixin ViewAsDialogActionMixin { }); }); } + + void showDialogIdentityCreator({ + required BuildContext context, + required IdentityCreatorArguments arguments, + required Function(dynamic) onCreatedIdentity + }) { + log('ViewAsDialogActionMixin::showDialogIdentityCreator(): '); + IdentityCreatorBindings().dependencies(); + + showGeneralDialog( + context: context, + barrierDismissible: true, + barrierLabel: '', + barrierColor: Colors.black.withAlpha(24), + pageBuilder: (context, animation, secondaryAnimation) { + return IdentityCreatorView.fromArguments( + arguments, + onDismissCallback: () { + IdentityCreatorBindings().dispose(); + popBack(); + }, + onCreatedIdentityCallback: (args) { + IdentityCreatorBindings().dispose(); + popBack(); + + onCreatedIdentity.call(args); + }); + }); + } } \ No newline at end of file diff --git a/lib/features/contact/presentation/contact_view.dart b/lib/features/contact/presentation/contact_view.dart index 672fea1f3..5b2df0dc6 100644 --- a/lib/features/contact/presentation/contact_view.dart +++ b/lib/features/contact/presentation/contact_view.dart @@ -36,7 +36,6 @@ class ContactView extends GetWidget { controller.arguments = arguments; controller.onSelectedContactCallback = onSelectedContactCallback; controller.onDismissContactView = onDismissCallback; - controller.onInit(); } @override diff --git a/lib/features/destination_picker/presentation/destination_picker_view.dart b/lib/features/destination_picker/presentation/destination_picker_view.dart index b0c4016a4..ef0fdcfef 100644 --- a/lib/features/destination_picker/presentation/destination_picker_view.dart +++ b/lib/features/destination_picker/presentation/destination_picker_view.dart @@ -51,7 +51,6 @@ class DestinationPickerView extends GetWidget controller.arguments = arguments; controller.onSelectedMailboxCallback = onSelectedMailboxCallback; controller.onDismissDestinationPicker = onDismissCallback; - controller.onInit(); } @override diff --git a/lib/features/identity_creator/presentation/identity_creator_bindings.dart b/lib/features/identity_creator/presentation/identity_creator_bindings.dart index c13ff3ce9..cfb41761f 100644 --- a/lib/features/identity_creator/presentation/identity_creator_bindings.dart +++ b/lib/features/identity_creator/presentation/identity_creator_bindings.dart @@ -16,4 +16,8 @@ class IdentityCreatorBindings extends Bindings { Get.find(), )); } + + void dispose() { + Get.delete(); + } } \ No newline at end of file diff --git a/lib/features/identity_creator/presentation/identity_creator_controller.dart b/lib/features/identity_creator/presentation/identity_creator_controller.dart index dba255eaf..41877befd 100644 --- a/lib/features/identity_creator/presentation/identity_creator_controller.dart +++ b/lib/features/identity_creator/presentation/identity_creator_controller.dart @@ -1,8 +1,8 @@ -import 'package:core/core.dart'; +import 'package:core/utils/app_logger.dart'; +import 'package:core/utils/build_utils.dart'; import 'package:enough_html_editor/enough_html_editor.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; import 'package:get/get.dart'; import 'package:html_editor_enhanced/html_editor.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; @@ -10,9 +10,12 @@ import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/identities/identity.dart'; import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; -import 'package:model/model.dart'; +import 'package:model/extensions/email_address_extension.dart'; +import 'package:model/extensions/identity_extension.dart'; +import 'package:model/user/user_profile.dart'; import 'package:rich_text_composer/richtext_controller.dart'; import 'package:tmail_ui_user/features/base/base_controller.dart'; +import 'package:tmail_ui_user/features/identity_creator/presentation/model/identity_creator_arguments.dart'; import 'package:tmail_ui_user/features/identity_creator/presentation/model/signature_type.dart'; import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/email_address_validator.dart'; import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/empty_name_validator.dart'; @@ -23,17 +26,19 @@ import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_id import 'package:tmail_ui_user/features/manage_account/domain/model/edit_identity_request.dart'; import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_identities_state.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_identities_interactor.dart'; -import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/identity_action_type.dart'; -import 'package:tmail_ui_user/features/manage_account/presentation/profiles/identities/identities_controller.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart'; import 'package:uuid/uuid.dart'; +typedef OnCreatedIdentityCallback = Function(dynamic arguments); + class IdentityCreatorController extends BaseController { final VerifyNameInteractor _verifyNameInteractor; final GetAllIdentitiesInteractor _getAllIdentitiesInteractor; + final _uuid = Get.find(); + final noneEmailAddress = EmailAddress(null, 'None'); final signatureType = SignatureType.plainText.obs; final listEmailAddressDefault = [].obs; @@ -43,29 +48,26 @@ class IdentityCreatorController extends BaseController { final emailOfIdentity = Rxn(); final replyToOfIdentity = Rxn(); final bccOfIdentity = Rxn(); - final _uuid = Get.find(); - final _identitiesController = Get.find(); - final _accountDashBoardController = Get.find(); + final actionType = IdentityActionType.create.obs; - final RichTextController keyboardRichTextController = RichTextController(); - - final HtmlEditorController signatureHtmlEditorController = HtmlEditorController(processNewLineAsBr: true); - final TextEditingController signaturePlainEditorController = TextEditingController(); - final TextEditingController inputNameIdentityController = TextEditingController(); - final TextEditingController inputBccIdentityController = TextEditingController(); - final FocusNode inputNameIdentityFocusNode = FocusNode(); - - late Worker identityCreatorIsActiveWorker; + late RichTextController keyboardRichTextController; + late HtmlEditorController signatureHtmlEditorController; + TextEditingController? signaturePlainEditorController; + TextEditingController? inputNameIdentityController; + TextEditingController? inputBccIdentityController; + FocusNode? inputNameIdentityFocusNode; HtmlEditorApi? signatureHtmlEditorMobileController; - AccountId? get accountId => _identitiesController.identityCreatorArguments.value!.accountId; - UserProfile? get userProfile => _identitiesController.identityCreatorArguments.value!.userProfile; - Identity? get identity => _identitiesController.identityCreatorArguments.value!.identity; - IdentityActionType get actionType => _identitiesController.identityCreatorArguments.value!.actionType; String? _nameIdentity; String? _contentHtmlEditor; + AccountId? accountId; + UserProfile? userProfile; + Identity? identity; + IdentityCreatorArguments? arguments; + OnCreatedIdentityCallback? onCreatedIdentityCallback; + VoidCallback? onDismissIdentityCreator; + ScrollController? scrollController; - final ScrollController scrollController = ScrollController(); final GlobalKey htmlKey = GlobalKey(); void updateNameIdentity(BuildContext context, String? value) { @@ -83,33 +85,34 @@ class IdentityCreatorController extends BaseController { ); @override - void onReady() { - _setUpValueFromIdentity(); - _getAllIdentities(); - _initWorker(); - super.onReady(); + void onInit() { + super.onInit(); + keyboardRichTextController = RichTextController(); + signatureHtmlEditorController = HtmlEditorController(processNewLineAsBr: true); + signaturePlainEditorController = TextEditingController(); + inputNameIdentityController = TextEditingController(); + inputBccIdentityController = TextEditingController(); + inputNameIdentityFocusNode = FocusNode(); + scrollController = ScrollController(); } - void _initWorker() { - identityCreatorIsActiveWorker = ever(_accountDashBoardController.identityCreatorIsActive, (identityCreatorIsActive) { - if (identityCreatorIsActive == true) { - if (actionType == IdentityActionType.edit && identity != null) { - _setUpValueFromIdentity(); - _setUpAllFieldEmailAddress(); - } - } - }); + @override + void onReady() { + super.onReady(); + if (arguments != null) { + accountId = arguments!.accountId; + userProfile = arguments!.userProfile; + identity = arguments!.identity; + actionType.value = arguments!.actionType; + _setUpValueFromIdentity(); + _getAllIdentities(); + } } @override void onClose() { - signaturePlainEditorController.dispose(); - inputNameIdentityFocusNode.dispose(); - inputNameIdentityController.dispose(); - inputBccIdentityController.dispose(); - identityCreatorIsActiveWorker.dispose(); keyboardRichTextController.dispose(); - scrollController.dispose(); + _disposeWidget(); super.onClose(); } @@ -134,10 +137,10 @@ class IdentityCreatorController extends BaseController { void _setUpValueFromIdentity() { _nameIdentity = identity?.name ?? ''; - inputNameIdentityController.text = identity?.name ?? ''; + inputNameIdentityController?.text = identity?.name ?? ''; if (identity?.textSignature?.value.isNotEmpty == true) { - signaturePlainEditorController.text = identity?.textSignature?.value ?? ''; + signaturePlainEditorController?.text = identity?.textSignature?.value ?? ''; } if (identity?.htmlSignature?.value.isNotEmpty == true) { @@ -147,6 +150,7 @@ class IdentityCreatorController extends BaseController { } void _getAllIdentities() { + log('IdentityCreatorController::_getAllIdentities() '); if (accountId != null) { consumeState(_getAllIdentitiesInteractor.execute( accountId!, @@ -164,8 +168,6 @@ class IdentityCreatorController extends BaseController { listEmailAddressOfReplyTo.add(noneEmailAddress); listEmailAddressOfReplyTo.addAll(listEmailAddressDefault); - log('IdentityCreatorController::_getALlIdentitiesSuccess(): listEmailAddressOfReplyTo: ${listEmailAddressOfReplyTo.toJson()}'); - _setUpAllFieldEmailAddress(); } else { _setDefaultEmailAddressList(); @@ -189,7 +191,10 @@ class IdentityCreatorController extends BaseController { } void _setUpAllFieldEmailAddress() { - if (actionType == IdentityActionType.edit && identity != null) { + listEmailAddressOfReplyTo.value = listEmailAddressOfReplyTo.toSet().toList(); + listEmailAddressDefault.value = listEmailAddressDefault.toSet().toList(); + + if (actionType.value == IdentityActionType.edit && identity != null) { if (identity?.replyTo?.isNotEmpty == true) { try { replyToOfIdentity.value = listEmailAddressOfReplyTo @@ -200,17 +205,14 @@ class IdentityCreatorController extends BaseController { } else { replyToOfIdentity.value = noneEmailAddress; } - log('IdentityCreatorController::_setUpAllFieldEmailAddress(): replyToOfIdentity: ${replyToOfIdentity.value}'); if (identity?.bcc?.isNotEmpty == true) { bccOfIdentity.value = identity?.bcc!.first; - inputBccIdentityController.text = identity?.bcc!.first.emailAddress ?? ''; + inputBccIdentityController?.text = identity?.bcc!.first.emailAddress ?? ''; } else { bccOfIdentity.value = null; } - log('IdentityCreatorController::_setUpAllFieldEmailAddress(): bccOfIdentity: ${bccOfIdentity.value}'); - if (identity?.email?.isNotEmpty == true) { try { emailOfIdentity.value = listEmailAddressDefault @@ -235,7 +237,6 @@ class IdentityCreatorController extends BaseController { void selectSignatureType(BuildContext context, SignatureType newSignatureType) async { if (newSignatureType == SignatureType.plainText && !BuildUtils.isWeb) { final signatureText = await _getSignatureHtmlText(); - log('IdentityCreatorController::selectSignatureType(): signatureText: $signatureText'); updateContentHtmlEditor(signatureText); } clearFocusEditor(context); @@ -267,19 +268,17 @@ class IdentityCreatorController extends BaseController { final error = _getErrorInputNameString(context); if (error?.isNotEmpty == true) { - log('IdentityCreatorController::createNewIdentity(): error: $error'); errorNameIdentity.value = error; return; } final errorBcc = _getErrorInputAddressString(context); if (errorBcc?.isNotEmpty == true) { - log('IdentityCreatorController::createNewIdentity(): errorBcc: $errorBcc'); errorBccIdentity.value = errorBcc; return; } - final signaturePlainText = signaturePlainEditorController.text; + final signaturePlainText = signaturePlainEditorController?.text ?? ''; final signatureHtmlText = BuildUtils.isWeb ? contentHtmlEditor : await _getSignatureHtmlText(); @@ -290,11 +289,6 @@ class IdentityCreatorController extends BaseController { ? {replyToOfIdentity.value!} : {}; - log('IdentityCreatorController::createNewIdentity(): bccAddress: $bccAddress'); - log('IdentityCreatorController::createNewIdentity(): replyToAddress: $replyToAddress'); - log('IdentityCreatorController::createNewIdentity(): signaturePlainText: $signaturePlainText'); - log('IdentityCreatorController::createNewIdentity(): signatureHtmlText: $signatureHtmlText'); - final newIdentity = Identity( name: _nameIdentity, email: emailOfIdentity.value?.email, @@ -303,29 +297,29 @@ class IdentityCreatorController extends BaseController { textSignature: Signature(signaturePlainText), htmlSignature: Signature(signatureHtmlText ?? '')); - log('IdentityCreatorController::createNewIdentity(): $newIdentity'); - final generateCreateId = Id(_uuid.v1()); - if(actionType == IdentityActionType.create) { - _identitiesController.createNewIdentityAction( - accountId!, - CreateNewIdentityRequest(generateCreateId, newIdentity), - ); - } else { - _identitiesController.editIdentityAction( - accountId!, - EditIdentityRequest( - identityId: identity!.id!, - identityRequest: newIdentity.toIdentityRequest(), - ) - ); - } + if (actionType.value == IdentityActionType.create) { + final identityRequest = CreateNewIdentityRequest(generateCreateId, newIdentity); + + if (BuildUtils.isWeb) { + _disposeWidget(); + onCreatedIdentityCallback?.call(identityRequest); + } else { + popBack(result: identityRequest); + } - if(kIsWeb) { - _accountDashBoardController.identityCreatorIsActive.toggle(); } else { - popBack(); + final identityRequest = EditIdentityRequest( + identityId: identity!.id!, + identityRequest: newIdentity.toIdentityRequest()); + + if (BuildUtils.isWeb) { + _disposeWidget(); + onCreatedIdentityCallback?.call(identityRequest); + } else { + popBack(result: identityRequest); + } } } @@ -346,7 +340,7 @@ class IdentityCreatorController extends BaseController { } String? _getErrorInputAddressString(BuildContext context, {String? value}) { - final emailAddress = value ?? inputBccIdentityController.text; + final emailAddress = value ?? inputBccIdentityController?.text ?? ''; if (emailAddress.trim().isEmpty) { return null; } @@ -374,9 +368,9 @@ class IdentityCreatorController extends BaseController { } void _clearAll() { - signaturePlainEditorController.clear(); - inputNameIdentityController.clear(); - inputBccIdentityController.clear(); + signaturePlainEditorController?.clear(); + inputNameIdentityController?.clear(); + inputBccIdentityController?.clear(); } List getSuggestionEmailAddress(String? pattern) { @@ -398,28 +392,46 @@ class IdentityCreatorController extends BaseController { void closeView(BuildContext context) { _clearAll(); clearFocusEditor(context); - if(kIsWeb) { - _accountDashBoardController.identityCreatorIsActive.toggle(); + + if (BuildUtils.isWeb) { + _disposeWidget(); + onDismissIdentityCreator?.call(); } else { popBack(); } } + void _disposeWidget() { + signaturePlainEditorController?.dispose(); + signaturePlainEditorController = null; + inputNameIdentityFocusNode?.dispose(); + inputNameIdentityFocusNode = null; + inputNameIdentityController?.dispose(); + inputNameIdentityController = null; + inputBccIdentityController?.dispose(); + inputBccIdentityController = null; + scrollController?.dispose(); + scrollController = null; + } + void onFocusHTMLEditor() async { await Scrollable.ensureVisible(htmlKey.currentContext!); await Future.delayed(const Duration(milliseconds: 500), () { - scrollController.animateTo( - scrollController.position.pixels + defaultKeyboardToolbarHeight, - duration: const Duration(milliseconds: 1), - curve: Curves.linear, - ); + if (scrollController != null) { + scrollController!.animateTo( + scrollController!.position.pixels + defaultKeyboardToolbarHeight, + duration: const Duration(milliseconds: 1), + curve: Curves.linear, + ); + } }); } void onEnterKeyDown() { - if(scrollController.position.pixels < scrollController.position.maxScrollExtent) { - scrollController.animateTo( - scrollController.position.pixels + 20, + if(scrollController != null && + scrollController!.position.pixels < scrollController!.position.maxScrollExtent) { + scrollController!.animateTo( + scrollController!.position.pixels + 20, duration: const Duration(milliseconds: 1), curve: Curves.linear, ); diff --git a/lib/features/identity_creator/presentation/identity_creator_view.dart b/lib/features/identity_creator/presentation/identity_creator_view.dart index f8d642ef0..f110683a2 100644 --- a/lib/features/identity_creator/presentation/identity_creator_view.dart +++ b/lib/features/identity_creator/presentation/identity_creator_view.dart @@ -8,6 +8,7 @@ import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; import 'package:rich_text_composer/views/keyboard_richtext.dart'; import 'package:rich_text_composer/views/widgets/rich_text_keyboard_toolbar.dart'; import 'package:tmail_ui_user/features/identity_creator/presentation/identity_creator_controller.dart'; +import 'package:tmail_ui_user/features/identity_creator/presentation/model/identity_creator_arguments.dart'; import 'package:tmail_ui_user/features/identity_creator/presentation/model/signature_type.dart'; import 'package:tmail_ui_user/features/identity_creator/presentation/widgets/identity_drop_list_field_builder.dart'; import 'package:tmail_ui_user/features/identity_creator/presentation/widgets/identity_field_no_editable_builder.dart'; @@ -21,7 +22,23 @@ class IdentityCreatorView extends GetWidget { final _imagePaths = Get.find(); final _responsiveUtils = Get.find(); - IdentityCreatorView({Key? key}) : super(key: key); + @override + final controller = Get.find(); + + IdentityCreatorView({Key? key}) : super(key: key) { + controller.arguments = Get.arguments; + } + + IdentityCreatorView.fromArguments( + IdentityCreatorArguments arguments, { + Key? key, + OnCreatedIdentityCallback? onCreatedIdentityCallback, + VoidCallback? onDismissCallback + }) : super(key: key) { + controller.arguments = arguments; + controller.onCreatedIdentityCallback = onCreatedIdentityCallback; + controller.onDismissIdentityCreator = onDismissCallback; + } @override Widget build(BuildContext context) { @@ -52,7 +69,7 @@ class IdentityCreatorView extends GetWidget { ) ), tablet: Scaffold( - backgroundColor: Colors.black38, + backgroundColor: Colors.black.withAlpha(24), body: GestureDetector( onTap: () => controller.clearFocusEditor(context), child: KeyboardRichText( @@ -66,7 +83,7 @@ class IdentityCreatorView extends GetWidget { titleFormatBottomSheet: AppLocalizations.of(context).titleFormat, titleBack: AppLocalizations.of(context).format, ), - child: Align(alignment: Alignment.center, child: Card( + child: Center(child: Card( color: Colors.transparent, shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))), child: Container( @@ -85,7 +102,7 @@ class IdentityCreatorView extends GetWidget { ), ), tabletLarge: Scaffold( - backgroundColor: Colors.black38, + backgroundColor: Colors.black.withAlpha(24), body: GestureDetector( onTap: () => controller.clearFocusEditor(context), child: KeyboardRichText( @@ -99,7 +116,7 @@ class IdentityCreatorView extends GetWidget { titleFormatBottomSheet: AppLocalizations.of(context).titleFormat, titleBack: AppLocalizations.of(context).format, ), - child: Align(alignment: Alignment.center, child: Card( + child: Center(child: Card( color: Colors.transparent, shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))), child: Container( @@ -118,10 +135,10 @@ class IdentityCreatorView extends GetWidget { ) ), desktop: Scaffold( - backgroundColor: Colors.black38, + backgroundColor: Colors.black.withAlpha(24), body: GestureDetector( onTap: () => controller.clearFocusEditor(context), - child: Align(alignment: Alignment.center, child: Card( + child: Center(child: Card( color: Colors.transparent, shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))), child: Container( @@ -135,8 +152,7 @@ class IdentityCreatorView extends GetWidget { child: _buildBodyDesktop(context) ) ) - ) - ), + )), ) ) ); @@ -148,7 +164,7 @@ class IdentityCreatorView extends GetWidget { Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.only(left: 24, top: 24), - child: Obx(() => Text(controller.actionType == IdentityActionType.create + child: Obx(() => Text(controller.actionType.value == IdentityActionType.create ? AppLocalizations.of(context).new_identity.inCaps : AppLocalizations.of(context).edit_identity.inCaps, style: const TextStyle( @@ -173,7 +189,7 @@ class IdentityCreatorView extends GetWidget { .build())), const SizedBox(width: 24), Expanded(child: Obx(() { - if (controller.actionType == IdentityActionType.create) { + if (controller.actionType.value == IdentityActionType.create) { return (IdentityDropListFieldBuilder( _imagePaths, AppLocalizations.of(context).email.inCaps, @@ -206,7 +222,7 @@ class IdentityCreatorView extends GetWidget { controller.errorBccIdentity.value, controller.inputBccIdentityController) ..addOnSelectedSuggestionAction((newEmailAddress) { - controller.inputBccIdentityController.text = newEmailAddress?.email ?? ''; + controller.inputBccIdentityController?.text = newEmailAddress?.email ?? ''; controller.updateBccOfIdentity(newEmailAddress); }) ..addOnChangeInputSuggestionAction((pattern) { @@ -273,7 +289,7 @@ class IdentityCreatorView extends GetWidget { onTap: () => controller.closeView(context)), const SizedBox(width: 12), Obx(() => buildTextButton( - controller.actionType == IdentityActionType.create + controller.actionType.value == IdentityActionType.create ? AppLocalizations.of(context).create : AppLocalizations.of(context).save, width: 128, @@ -299,7 +315,7 @@ class IdentityCreatorView extends GetWidget { Column(children: [ Padding( padding: const EdgeInsets.only(top: 16), - child: Text(controller.actionType == IdentityActionType.create + child: Text(controller.actionType.value == IdentityActionType.create ? AppLocalizations.of(context).new_identity.inCaps : AppLocalizations.of(context).edit_identity.inCaps, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 21, color: Colors.black))), @@ -321,7 +337,7 @@ class IdentityCreatorView extends GetWidget { .build()), const SizedBox(height: 24), Obx(() { - if (controller.actionType == IdentityActionType.create) { + if (controller.actionType.value == IdentityActionType.create) { return (IdentityDropListFieldBuilder( _imagePaths, AppLocalizations.of(context).email.inCaps, @@ -352,7 +368,7 @@ class IdentityCreatorView extends GetWidget { controller.errorBccIdentity.value, controller.inputBccIdentityController) ..addOnSelectedSuggestionAction((newEmailAddress) { - controller.inputBccIdentityController.text = newEmailAddress?.email ?? ''; + controller.inputBccIdentityController?.text = newEmailAddress?.email ?? ''; controller.updateBccOfIdentity(newEmailAddress); }) ..addOnChangeInputSuggestionAction((pattern) { @@ -422,7 +438,7 @@ class IdentityCreatorView extends GetWidget { const SizedBox(width: 12), Expanded( child: Obx(() => buildTextButton( - controller.actionType == IdentityActionType.create + controller.actionType.value == IdentityActionType.create ? AppLocalizations.of(context).create : AppLocalizations.of(context).save, width: 128, @@ -459,7 +475,7 @@ class IdentityCreatorView extends GetWidget { } Widget _buildSignatureButton(BuildContext context, SignatureType signatureType) { - return buildTextButton( + return buildButtonWrapText( signatureType.getTitle(context), textStyle: TextStyle( fontWeight: FontWeight.w500, @@ -467,10 +483,9 @@ class IdentityCreatorView extends GetWidget { color: controller.signatureType.value == signatureType ? AppColor.colorContentEmail : AppColor.colorHintSearchBar), - backgroundColor: controller.signatureType.value == signatureType + bgColor: controller.signatureType.value == signatureType ? AppColor.emailAddressChipColor : Colors.transparent, - width: signatureType == SignatureType.plainText ? 85 : 110, height: 30, radius: 10, onTap: () => controller.selectSignatureType(context, signatureType)); diff --git a/lib/features/identity_creator/presentation/widgets/identity_drop_list_field_builder.dart b/lib/features/identity_creator/presentation/widgets/identity_drop_list_field_builder.dart index df85ea51b..0464a8dd3 100644 --- a/lib/features/identity_creator/presentation/widgets/identity_drop_list_field_builder.dart +++ b/lib/features/identity_creator/presentation/widgets/identity_drop_list_field_builder.dart @@ -43,7 +43,8 @@ class IdentityDropListFieldBuilder { _emailAddressSelected?.email ?? '', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.normal, color: Colors.black), maxLines: 1, - overflow: BuildUtils.isWeb ? null : TextOverflow.ellipsis, + overflow: CommonTextStyle.defaultTextOverFlow, + softWrap: CommonTextStyle.defaultSoftWrap, )), ], ), @@ -53,7 +54,8 @@ class IdentityDropListFieldBuilder { item.email ?? '', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.normal, color: Colors.black), maxLines: 1, - overflow: BuildUtils.isWeb ? null : TextOverflow.ellipsis, + overflow: CommonTextStyle.defaultTextOverFlow, + softWrap: CommonTextStyle.defaultSoftWrap, ), )).toList(), value: _emailAddressSelected, diff --git a/lib/features/identity_creator/presentation/widgets/identity_input_with_drop_list_field_builder.dart b/lib/features/identity_creator/presentation/widgets/identity_input_with_drop_list_field_builder.dart index e52a0240c..e597f26c6 100644 --- a/lib/features/identity_creator/presentation/widgets/identity_input_with_drop_list_field_builder.dart +++ b/lib/features/identity_creator/presentation/widgets/identity_input_with_drop_list_field_builder.dart @@ -13,7 +13,7 @@ class IdentityInputWithDropListFieldBuilder { final String _label; final String? _error; - final TextEditingController editingController; + final TextEditingController? editingController; OnSelectedSuggestionAction? _onSelectedSuggestionAction; OnSuggestionCallbackAction? _onSuggestionCallbackAction; diff --git a/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart b/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart index dc9c2d172..c2a324fe5 100644 --- a/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart +++ b/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart @@ -53,6 +53,7 @@ class MailboxCreatorController extends BaseController { @override void onReady() { super.onReady(); + log('MailboxCreatorController::onReady(): '); if (arguments != null) { folderMailboxTree = arguments!.folderMailboxTree; defaultMailboxTree = arguments!.defaultMailboxTree; diff --git a/lib/features/mailbox_creator/presentation/mailbox_creator_view.dart b/lib/features/mailbox_creator/presentation/mailbox_creator_view.dart index 07b27cdba..e90bbddd8 100644 --- a/lib/features/mailbox_creator/presentation/mailbox_creator_view.dart +++ b/lib/features/mailbox_creator/presentation/mailbox_creator_view.dart @@ -37,7 +37,6 @@ class MailboxCreatorView extends GetWidget { controller.arguments = arguments; controller.onCreatedMailboxCallback = onCreatedMailboxCallback; controller.onDismissMailboxCreator = onDismissCallback; - controller.onInit(); } @override diff --git a/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart b/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart index 124b06018..d7d86127a 100644 --- a/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart +++ b/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart @@ -54,7 +54,6 @@ class ManageAccountDashBoardController extends ReloadableController { final emailsForwardCreatorIsActive = false.obs; final rulesFilterCreatorIsActive = false.obs; - final identityCreatorIsActive = false.obs; ManageAccountDashBoardController( LogoutOidcInteractor logoutOidcInteractor, diff --git a/lib/features/manage_account/presentation/manage_account_dashboard_view.dart b/lib/features/manage_account/presentation/manage_account_dashboard_view.dart index daa22ac7d..543bb91a8 100644 --- a/lib/features/manage_account/presentation/manage_account_dashboard_view.dart +++ b/lib/features/manage_account/presentation/manage_account_dashboard_view.dart @@ -3,7 +3,6 @@ import 'package:core/core.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:tmail_ui_user/features/emails_forward_creator/presentation/emails_forward_creator_view.dart'; -import 'package:tmail_ui_user/features/identity_creator/presentation/identity_creator_view.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/mixin/user_setting_popup_menu_mixin.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/extensions/vacation_response_extension.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/vacation/widgets/vacation_notification_message_widget.dart'; @@ -131,8 +130,6 @@ class ManageAccountDashBoardView extends GetWidget(); - late Worker accountIdWorker; IdentitiesController( @@ -118,7 +121,6 @@ class IdentitiesController extends BaseController { } void _getAllIdentities(AccountId accountId) { - log('IdentitiesController::_getAllIdentities(): $accountId'); consumeState(_getAllIdentitiesInteractor.execute(accountId)); } @@ -141,11 +143,6 @@ class IdentitiesController extends BaseController { } } - void _openIdentityCreatorOverlay() { - IdentityCreatorBindings().dependencies(); - _accountDashBoardController.identityCreatorIsActive.toggle(); - } - void selectIdentity(Identity? newIdentity) { identitySelected.value = newIdentity; if (newIdentity != null) { @@ -161,20 +158,38 @@ class IdentitiesController extends BaseController { } } - void goToCreateNewIdentity() async { + void goToCreateNewIdentity(BuildContext context) async { final accountId = _accountDashBoardController.accountId.value; final userProfile = _accountDashBoardController.userProfile.value; if (accountId != null && userProfile != null) { - identityCreatorArguments.value = IdentityCreatorArguments(accountId, userProfile); - if (kIsWeb) { - _openIdentityCreatorOverlay(); + final arguments = IdentityCreatorArguments(accountId, userProfile); + + if (BuildUtils.isWeb) { + showDialogIdentityCreator( + context: context, + arguments: arguments, + onCreatedIdentity: (arguments) { + if (arguments is CreateNewIdentityRequest) { + _createNewIdentityAction(accountId, arguments); + } else if (arguments is EditIdentityRequest) { + _editIdentityAction(accountId, arguments); + } + }); } else { - push(AppRoutes.identityCreator); + final newIdentityArguments = await push( + AppRoutes.identityCreator, + arguments: arguments); + + if (newIdentityArguments is CreateNewIdentityRequest) { + _createNewIdentityAction(accountId, newIdentityArguments); + } else if (newIdentityArguments is EditIdentityRequest) { + _editIdentityAction(accountId, newIdentityArguments); + } } } } - void createNewIdentityAction(AccountId accountId, CreateNewIdentityRequest identityRequest) async { + void _createNewIdentityAction(AccountId accountId, CreateNewIdentityRequest identityRequest) async { consumeState(_createNewIdentityInteractor.execute(accountId, identityRequest)); } @@ -281,32 +296,48 @@ class IdentitiesController extends BaseController { } } - void goToEditIdentity(Identity identity) async { + void goToEditIdentity(BuildContext context, Identity identity) async { popBack(); final accountId = _accountDashBoardController.accountId.value; final userProfile = _accountDashBoardController.userProfile.value; if (accountId != null && userProfile != null) { - identityCreatorArguments.value = IdentityCreatorArguments( + final arguments = IdentityCreatorArguments( accountId, userProfile, identity: identity, actionType: IdentityActionType.edit); - if (kIsWeb) { - _openIdentityCreatorOverlay(); + + if (BuildUtils.isWeb) { + showDialogIdentityCreator( + context: context, + arguments: arguments, + onCreatedIdentity: (arguments) { + if (arguments is CreateNewIdentityRequest) { + _createNewIdentityAction(accountId, arguments); + } else if (arguments is EditIdentityRequest) { + _editIdentityAction(accountId, arguments); + } + }); } else { - push(AppRoutes.identityCreator); + final newIdentityArguments = await push( + AppRoutes.identityCreator, + arguments: arguments); + + if (newIdentityArguments is CreateNewIdentityRequest) { + _createNewIdentityAction(accountId, newIdentityArguments); + } else if (newIdentityArguments is EditIdentityRequest) { + _editIdentityAction(accountId, newIdentityArguments); + } } } } - void editIdentityAction(AccountId accountId, EditIdentityRequest editIdentityRequest) async { - log('IdentitiesController::_editIdentityAction(): $editIdentityRequest'); + void _editIdentityAction(AccountId accountId, EditIdentityRequest editIdentityRequest) async { consumeState(_editIdentityInteractor.execute(accountId, editIdentityRequest)); } void _editIdentitySuccess(EditIdentitySuccess success) { - log('IdentitiesController::_editIdentitySuccess(): $success'); if (currentOverlayContext != null && currentContext != null) { _appToast.showToastWithIcon( currentOverlayContext!, diff --git a/lib/features/manage_account/presentation/profiles/identities/identities_view.dart b/lib/features/manage_account/presentation/profiles/identities/identities_view.dart index e62d259af..124abfaea 100644 --- a/lib/features/manage_account/presentation/profiles/identities/identities_view.dart +++ b/lib/features/manage_account/presentation/profiles/identities/identities_view.dart @@ -1,5 +1,10 @@ -import 'package:core/core.dart'; +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/responsive_utils.dart'; +import 'package:core/presentation/views/button/button_builder.dart'; +import 'package:core/presentation/views/responsive/responsive_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -42,7 +47,7 @@ class IdentitiesView extends GetWidget with PopupMenuWidge ..radiusSplash(10) ..padding(const EdgeInsets.symmetric(vertical: 12)) ..textStyle(const TextStyle(fontSize: 17, color: Colors.white, fontWeight: FontWeight.w500)) - ..onPressActionClick(() => controller.goToCreateNewIdentity()) + ..onPressActionClick(() => controller.goToCreateNewIdentity(context)) ..text(AppLocalizations.of(context).new_identity, isVertical: false)) .build() ]); @@ -77,7 +82,7 @@ class IdentitiesView extends GetWidget with PopupMenuWidge floatingActionButton: _responsiveUtils.isMobile(context) ? FloatingActionButton( key: const Key('add_new_identity'), - onPressed: () => controller.goToCreateNewIdentity(), + onPressed: () => controller.goToCreateNewIdentity(context), backgroundColor: AppColor.primaryColor, child: SvgPicture.asset(_imagePaths.icAddIdentity, width: 24, height: 24)) : null), @@ -140,7 +145,7 @@ class IdentitiesView extends GetWidget with PopupMenuWidge fontWeight: FontWeight.normal, fontSize: 17, color: Colors.black), - onCallbackAction: () => controller.goToEditIdentity(identity))), + onCallbackAction: () => controller.goToEditIdentity(context, identity))), if (identity.mayDelete == true) PopupMenuItem( padding: EdgeInsets.zero, @@ -192,7 +197,7 @@ class IdentitiesView extends GetWidget with PopupMenuWidge iconRightPadding: _responsiveUtils.isMobile(context) ? const EdgeInsets.only(right: 12) : EdgeInsets.zero) - ..onActionClick((identity) => controller.goToEditIdentity(identity))) + ..onActionClick((identity) => controller.goToEditIdentity(context, identity))) .build(); } } \ No newline at end of file diff --git a/lib/main/pages/app_pages.dart b/lib/main/pages/app_pages.dart index 224a826f0..829cb273b 100644 --- a/lib/main/pages/app_pages.dart +++ b/lib/main/pages/app_pages.dart @@ -52,6 +52,11 @@ class AppPages { opaque: false, page: () => DeferredWidget(contact_view.loadLibrary, () => contact_view.ContactView()), binding: ContactBindings()), + GetPage( + name: AppRoutes.identityCreator, + opaque: false, + page: () => DeferredWidget(identity_creator.loadLibrary, () => identity_creator.IdentityCreatorView()), + binding: IdentityCreatorBindings()), ]; static final pages = [ @@ -76,12 +81,6 @@ class AppPages { page: () => DeferredWidget(manage_account_dashboard.loadLibrary, () => manage_account_dashboard.ManageAccountDashBoardView()), binding: ManageAccountDashBoardBindings()), - GetPage( - name: AppRoutes.identityCreator, - opaque: false, - page: () => DeferredWidget(identity_creator.loadLibrary, - () => identity_creator.IdentityCreatorView()), - binding: IdentityCreatorBindings()), GetPage( name: AppRoutes.rulesFilterCreator, opaque: false, diff --git a/lib/main/routes/app_routes.dart b/lib/main/routes/app_routes.dart index c2fa7f4cf..09600929e 100644 --- a/lib/main/routes/app_routes.dart +++ b/lib/main/routes/app_routes.dart @@ -9,7 +9,7 @@ abstract class AppRoutes { static const destinationPicker = '/destination_picker'; static const mailboxCreator = '/mailbox_creator'; static const contact = '/contact'; - static const identityCreator = '$settings/identity_creator'; + static const identityCreator = '/identity_creator'; static const rulesFilterCreator = '$settings/rules_filter_creator'; static const emailsForwardCreator = '$settings/emails_forward_creator'; } \ No newline at end of file