TF-82 Create an email as drafts
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:core/core.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/composer/data/datasource/autocomplete_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/composer/data/datasource/composer_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/composer/data/datasource/contact_datasource.dart';
|
||||
@@ -20,62 +21,117 @@ import 'package:tmail_ui_user/features/composer/domain/repository/composer_repos
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/contact_repository.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete_with_device_contact_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/get_device_contact_suggestions_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/save_email_as_drafts_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/upload_attachment_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/save_email_addresses_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/send_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/upload_mutiple_attachment_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/composer_controller.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/datasource/email_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/datasource/html_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/email_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/html_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/repository/email_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/usecases/local_file_picker_interactor.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class ComposerBindings extends Bindings {
|
||||
class ComposerBindings extends BaseBindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
_bindingsUtils();
|
||||
super.dependencies();
|
||||
}
|
||||
|
||||
void _bindingsUtils() {
|
||||
Get.lazyPut(() => EmailAddressDatabaseManager(Get.find<DatabaseClient>()));
|
||||
Get.lazyPut(() => Uuid());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.lazyPut(() => ComposerDataSourceImpl(Get.find<ComposerAPI>()));
|
||||
Get.lazyPut(() => LocalComposerDataSourceImpl(Get.find<EmailAddressDatabaseManager>()));
|
||||
Get.lazyPut(() => AutoCompleteDataSourceImpl());
|
||||
Get.lazyPut(() => LocalAutoCompleteDataSourceImpl(Get.find<EmailAddressDatabaseManager>()));
|
||||
Get.lazyPut(() => ContactDataSourceImpl());
|
||||
Get.lazyPut(() => HtmlDataSourceImpl(
|
||||
Get.find<HtmlAnalyzer>(),
|
||||
Get.find<DioClient>()
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSource() {
|
||||
Get.lazyPut<ComposerDataSource>(() => Get.find<ComposerDataSourceImpl>());
|
||||
Get.lazyPut<AutoCompleteDataSource>(() => Get.find<AutoCompleteDataSourceImpl>());
|
||||
Get.lazyPut<ContactDataSource>(() => Get.find<ContactDataSourceImpl>());
|
||||
Get.lazyPut<EmailDataSource>(() => Get.find<EmailDataSourceImpl>());
|
||||
Get.lazyPut<HtmlDataSource>(() => Get.find<HtmlDataSourceImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepositoryImpl() {
|
||||
Get.lazyPut(() => ComposerRepositoryImpl({
|
||||
DataSourceType.network: Get.find<ComposerDataSource>(),
|
||||
DataSourceType.local: Get.find<LocalComposerDataSourceImpl>(),
|
||||
}));
|
||||
Get.lazyPut<ComposerRepository>(() => Get.find<ComposerRepositoryImpl>());
|
||||
Get.lazyPut(() => SaveEmailAddressesInteractor(Get.find<ComposerRepository>()));
|
||||
Get.lazyPut(() => AutoCompleteDataSourceImpl());
|
||||
Get.lazyPut<AutoCompleteDataSource>(() => Get.find<AutoCompleteDataSourceImpl>());
|
||||
Get.lazyPut(() => LocalAutoCompleteDataSourceImpl(Get.find<EmailAddressDatabaseManager>()));
|
||||
Get.lazyPut(() => AutoCompleteRepositoryImpl({
|
||||
DataSourceType.network: Get.find<AutoCompleteDataSource>(),
|
||||
DataSourceType.local: Get.find<LocalAutoCompleteDataSourceImpl>(),
|
||||
}));
|
||||
Get.lazyPut<AutoCompleteRepository>(() => Get.find<AutoCompleteRepositoryImpl>());
|
||||
Get.lazyPut(() => GetAutoCompleteInteractor(Get.find<AutoCompleteRepository>()));
|
||||
Get.lazyPut(() => Uuid());
|
||||
Get.lazyPut(() => TextEditingController());
|
||||
Get.lazyPut(() => ContactDataSourceImpl());
|
||||
Get.lazyPut<ContactDataSource>(() => Get.find<ContactDataSourceImpl>());
|
||||
Get.lazyPut(() => ContactRepositoryImpl(Get.find<ContactDataSource>()));
|
||||
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
|
||||
Get.lazyPut(() => EmailRepositoryImpl(
|
||||
Get.find<EmailDataSource>(),
|
||||
Get.find<HtmlDataSource>()
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepository() {
|
||||
Get.lazyPut<ComposerRepository>(() => Get.find<ComposerRepositoryImpl>());
|
||||
Get.lazyPut<AutoCompleteRepository>(() => Get.find<AutoCompleteRepositoryImpl>());
|
||||
Get.lazyPut<ContactRepository>(() => Get.find<ContactRepositoryImpl>());
|
||||
Get.lazyPut<EmailRepository>(() => Get.find<EmailRepositoryImpl>());
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsInteractor() {
|
||||
Get.lazyPut(() => SaveEmailAddressesInteractor(Get.find<ComposerRepository>()));
|
||||
Get.lazyPut(() => GetAutoCompleteInteractor(Get.find<AutoCompleteRepository>()));
|
||||
Get.lazyPut(() => GetDeviceContactSuggestionsInteractor(Get.find<ContactRepository>()));
|
||||
Get.lazyPut(() => GetAutoCompleteWithDeviceContactInteractor(
|
||||
Get.find<GetAutoCompleteInteractor>(),
|
||||
Get.find<GetDeviceContactSuggestionsInteractor>()));
|
||||
Get.find<GetDeviceContactSuggestionsInteractor>()
|
||||
));
|
||||
Get.lazyPut(() => LocalFilePickerInteractor());
|
||||
Get.lazyPut(() => UploadAttachmentInteractor(
|
||||
Get.find<ComposerRepository>()));
|
||||
Get.lazyPut(() => UploadAttachmentInteractor(Get.find<ComposerRepository>()));
|
||||
Get.lazyPut(() => UploadMultipleAttachmentInteractor(Get.find<UploadAttachmentInteractor>()));
|
||||
Get.lazyPut(() => SendEmailInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => SaveEmailAsDraftsInteractor(Get.find<EmailRepository>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsController() {
|
||||
Get.lazyPut(() => TextEditingController());
|
||||
Get.lazyPut(() => ComposerController(
|
||||
Get.find<SendEmailInteractor>(),
|
||||
Get.find<SaveEmailAddressesInteractor>(),
|
||||
Get.find<GetAutoCompleteInteractor>(),
|
||||
Get.find<GetAutoCompleteWithDeviceContactInteractor>(),
|
||||
Get.find<AppToast>(),
|
||||
Get.find<ImagePaths>(),
|
||||
Get.find<Uuid>(),
|
||||
Get.find<DeviceInfoPlugin>(),
|
||||
Get.find<TextEditingController>(),
|
||||
Get.find<LocalFilePickerInteractor>(),
|
||||
Get.find<UploadMultipleAttachmentInteractor>()));
|
||||
Get.find<SendEmailInteractor>(),
|
||||
Get.find<SaveEmailAddressesInteractor>(),
|
||||
Get.find<GetAutoCompleteInteractor>(),
|
||||
Get.find<GetAutoCompleteWithDeviceContactInteractor>(),
|
||||
Get.find<AppToast>(),
|
||||
Get.find<ImagePaths>(),
|
||||
Get.find<Uuid>(),
|
||||
Get.find<DeviceInfoPlugin>(),
|
||||
Get.find<TextEditingController>(),
|
||||
Get.find<LocalFilePickerInteractor>(),
|
||||
Get.find<UploadMultipleAttachmentInteractor>(),
|
||||
Get.find<SaveEmailAsDraftsInteractor>()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_body_value.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
@@ -30,6 +31,7 @@ import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete_with_device_contact_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/upload_attachment_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/save_email_addresses_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/save_email_as_drafts_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/send_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/upload_mutiple_attachment_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/email_action_type_extension.dart';
|
||||
@@ -62,6 +64,7 @@ class ComposerController extends BaseController {
|
||||
final LocalFilePickerInteractor _localFilePickerInteractor;
|
||||
final UploadMultipleAttachmentInteractor _uploadMultipleAttachmentInteractor;
|
||||
final DeviceInfoPlugin _deviceInfoPlugin;
|
||||
final SaveEmailAsDraftsInteractor _saveEmailAsDraftsInteractor;
|
||||
|
||||
List<EmailAddress> listToEmailAddress = [];
|
||||
List<EmailAddress> listCcEmailAddress = [];
|
||||
@@ -96,6 +99,7 @@ class ComposerController extends BaseController {
|
||||
this.subjectEmailInputController,
|
||||
this._localFilePickerInteractor,
|
||||
this._uploadMultipleAttachmentInteractor,
|
||||
this._saveEmailAsDraftsInteractor,
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -272,9 +276,10 @@ class ComposerController extends BaseController {
|
||||
return emailQuotedHtml;
|
||||
}
|
||||
|
||||
Future<Email> generateEmail() async {
|
||||
Future<Email> generateEmail({bool asDrafts = false}) async {
|
||||
final generateEmailId = EmailId(Id(_uuid.v1()));
|
||||
final outboxMailboxId = composerArguments.value!.mapMailboxId[PresentationMailbox.roleOutbox];
|
||||
final draftMailboxId = composerArguments.value!.mapMailboxId[PresentationMailbox.roleDrafts];
|
||||
final listFromEmailAddress = {
|
||||
EmailAddress(null, composerArguments.value!.userProfile.email)
|
||||
};
|
||||
@@ -286,11 +291,12 @@ class ComposerController extends BaseController {
|
||||
|
||||
return Email(
|
||||
generateEmailId,
|
||||
mailboxIds: {outboxMailboxId!: true},
|
||||
mailboxIds: asDrafts ? {draftMailboxId!: true} : {outboxMailboxId!: true},
|
||||
from: listFromEmailAddress,
|
||||
to: listToEmailAddress.toSet(),
|
||||
cc: listCcEmailAddress.toSet(),
|
||||
bcc: listBccEmailAddress.toSet(),
|
||||
keywords: asDrafts ? {KeyWordIdentifier.emailDraft : true} : null,
|
||||
subject: _subjectEmail,
|
||||
htmlBody: {
|
||||
EmailBodyPart(
|
||||
@@ -450,6 +456,15 @@ class ComposerController extends BaseController {
|
||||
attachments.removeWhere((attachment) => attachment == attachmentRemoved);
|
||||
}
|
||||
|
||||
void saveEmailAsDrafts() async {
|
||||
_saveEmailAddress();
|
||||
|
||||
final newEmail = await generateEmail(asDrafts: true);
|
||||
final accountId = composerArguments.value!.session.accounts.keys.first;
|
||||
|
||||
mailboxDashBoardController.consumeState(_saveEmailAsDraftsInteractor.execute(accountId, newEmail));
|
||||
}
|
||||
|
||||
void backToEmailViewAction() {
|
||||
popBack();
|
||||
}
|
||||
|
||||
@@ -22,28 +22,35 @@ class ComposerView extends GetWidget<ComposerController> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
controller.htmlEditorApi?.unfocus(context);
|
||||
controller.saveEmailAsDrafts();
|
||||
return true;
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColor.primaryLightColor,
|
||||
body: SafeArea(
|
||||
right: responsiveUtils.isMobileDevice(context) && responsiveUtils.isLandscape(context),
|
||||
left: responsiveUtils.isMobileDevice(context) && responsiveUtils.isLandscape(context),
|
||||
child: Container(
|
||||
margin: EdgeInsets.zero,
|
||||
alignment: Alignment.topCenter,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
_buildTopBar(context),
|
||||
Expanded(child: _buildBodyComposer(context))
|
||||
])
|
||||
)
|
||||
),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
controller.htmlEditorApi?.unfocus(context);
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColor.primaryLightColor,
|
||||
body: SafeArea(
|
||||
right: responsiveUtils.isMobileDevice(context) && responsiveUtils.isLandscape(context),
|
||||
left: responsiveUtils.isMobileDevice(context) && responsiveUtils.isLandscape(context),
|
||||
child: Container(
|
||||
margin: EdgeInsets.zero,
|
||||
alignment: Alignment.topCenter,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
_buildTopBar(context),
|
||||
Expanded(child: _buildBodyComposer(context))
|
||||
])
|
||||
)
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -54,7 +61,10 @@ class ComposerView extends GetWidget<ComposerController> {
|
||||
child: Obx(() => (TopBarComposerWidgetBuilder(imagePaths, controller.isEnableEmailSendButton.value)
|
||||
..addSendEmailActionClick(() => controller.sendEmailAction(context))
|
||||
..addAttachFileActionClick(() => controller.openPickAttachmentMenu(context, _pickAttachmentsActionTiles(context)))
|
||||
..addBackActionClick(() => controller.backToEmailViewAction()))
|
||||
..addBackActionClick(() {
|
||||
controller.saveEmailAsDrafts();
|
||||
controller.backToEmailViewAction();
|
||||
}))
|
||||
.build()),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user