TF-123 Implement refresh all mailbox
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/caching/state_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/repository/credential_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/state_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/mailbox_controller.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart';
|
||||
|
||||
@@ -24,16 +28,23 @@ class MailboxBindings extends Bindings {
|
||||
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>()));
|
||||
Get.lazyPut<MailboxDataSource>(() => Get.find<MailboxDataSourceImpl>());
|
||||
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
|
||||
Get.lazyPut(() => MailboxRepositoryImpl({
|
||||
DataSourceType.network: Get.find<MailboxDataSource>(),
|
||||
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>(),
|
||||
}));
|
||||
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
|
||||
Get.lazyPut<StateDataSource>(() => Get.find<StateDataSourceImpl>());
|
||||
Get.lazyPut(() => MailboxRepositoryImpl(
|
||||
{
|
||||
DataSourceType.network: Get.find<MailboxDataSource>(),
|
||||
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>()
|
||||
},
|
||||
Get.find<StateDataSource>()
|
||||
));
|
||||
Get.lazyPut<MailboxRepository>(() => Get.find<MailboxRepositoryImpl>());
|
||||
Get.lazyPut(() => GetAllMailboxInteractor(Get.find<MailboxRepository>()));
|
||||
Get.lazyPut(() => RefreshAllMailboxInteractor(Get.find<MailboxRepository>()));
|
||||
Get.lazyPut(() => TreeBuilder());
|
||||
Get.put(MailboxController(
|
||||
Get.find<GetAllMailboxInteractor>(),
|
||||
Get.find<DeleteCredentialInteractor>(),
|
||||
Get.find<RefreshAllMailboxInteractor>(),
|
||||
Get.find<TreeBuilder>(),
|
||||
Get.find<ResponsiveUtils>()));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_read_sta
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/get_all_mailboxes_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart';
|
||||
@@ -19,21 +20,26 @@ import 'package:tmail_ui_user/features/thread/domain/state/mark_as_multiple_emai
|
||||
import 'package:tmail_ui_user/features/thread/domain/state/move_multiple_email_to_mailbox_state.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmapState;
|
||||
|
||||
class MailboxController extends BaseController {
|
||||
|
||||
final mailboxDashBoardController = Get.find<MailboxDashBoardController>();
|
||||
final GetAllMailboxInteractor _getAllMailboxInteractor;
|
||||
final DeleteCredentialInteractor _deleteCredentialInteractor;
|
||||
final RefreshAllMailboxInteractor _refreshAllMailboxInteractor;
|
||||
final TreeBuilder _treeBuilder;
|
||||
final ResponsiveUtils responsiveUtils;
|
||||
|
||||
final defaultMailboxList = <PresentationMailbox>[].obs;
|
||||
final folderMailboxNodeList = <MailboxNode>[].obs;
|
||||
|
||||
jmapState.State? currentMailboxState;
|
||||
|
||||
MailboxController(
|
||||
this._getAllMailboxInteractor,
|
||||
this._deleteCredentialInteractor,
|
||||
this._refreshAllMailboxInteractor,
|
||||
this._treeBuilder,
|
||||
this.responsiveUtils
|
||||
);
|
||||
@@ -52,11 +58,11 @@ class MailboxController extends BaseController {
|
||||
if (success is MarkAsEmailReadSuccess ||
|
||||
success is MarkAsMultipleEmailReadAllSuccess ||
|
||||
success is MarkAsMultipleEmailReadHasSomeEmailFailure) {
|
||||
refreshGetAllMailboxAction();
|
||||
refreshMailboxChanges();
|
||||
} else if (success is MoveMultipleEmailToMailboxAllSuccess
|
||||
|| success is MoveMultipleEmailToMailboxHasSomeEmailFailure) {
|
||||
mailboxDashBoardController.clearState();
|
||||
refreshGetAllMailboxAction();
|
||||
refreshMailboxChanges();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -68,17 +74,6 @@ class MailboxController extends BaseController {
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void refreshGetAllMailboxAction() {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
if (accountId != null) {
|
||||
getAllMailboxAction(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
void getAllMailboxAction(AccountId accountId) async {
|
||||
consumeState(_getAllMailboxInteractor.execute(accountId));
|
||||
}
|
||||
|
||||
@override
|
||||
void onData(Either<Failure, Success> newState) {
|
||||
super.onData(newState);
|
||||
@@ -93,6 +88,7 @@ class MailboxController extends BaseController {
|
||||
void onDone() {
|
||||
viewState.value.map((success) {
|
||||
if (success is GetAllMailboxSuccess) {
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
defaultMailboxList.value = success.defaultMailboxList;
|
||||
_setUpMapMailboxIdDefault(success.defaultMailboxList);
|
||||
}
|
||||
@@ -100,8 +96,24 @@ class MailboxController extends BaseController {
|
||||
}
|
||||
|
||||
@override
|
||||
void onError(error) {
|
||||
print('$error');
|
||||
void onError(error) {}
|
||||
|
||||
void getAllMailboxAction(AccountId accountId) async {
|
||||
consumeState(_getAllMailboxInteractor.execute(accountId));
|
||||
}
|
||||
|
||||
void refreshAllMailbox() {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
if (accountId != null) {
|
||||
consumeState(_getAllMailboxInteractor.execute(accountId));
|
||||
}
|
||||
}
|
||||
|
||||
void refreshMailboxChanges() {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
if (accountId != null && currentMailboxState != null) {
|
||||
consumeState(_refreshAllMailboxInteractor.execute(accountId, currentMailboxState!));
|
||||
}
|
||||
}
|
||||
|
||||
void _buildTree(List<PresentationMailbox> folderMailboxList) async {
|
||||
|
||||
@@ -31,7 +31,7 @@ class MailboxView extends GetWidget<MailboxController> {
|
||||
left: false,
|
||||
child: RefreshIndicator(
|
||||
color: AppColor.primaryColor,
|
||||
onRefresh: () async => controller.refreshGetAllMailboxAction(),
|
||||
onRefresh: () async => controller.refreshAllMailbox(),
|
||||
child: SingleChildScrollView(
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
child: Padding(
|
||||
|
||||
Reference in New Issue
Block a user