Skip to content

Commit

Permalink
[Android][Disable work manager] ADR
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangdat committed Jan 12, 2024
1 parent 8223127 commit 67fca11
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 33. Disable work manager in sending email automatically

Date: 2024-01-12

## Status

Accepted

## Context

- In some Wifi environments, network connection status not return the right value
- We can not manage the schedule of sending email well (it depends on the Android scheduler)

## Decision

- Disable work manager in sending email automatically
- The status of network in be check directly with `InternetConnectionChecker.hasConnection`
```dart
Future<bool> hasInternetConnection() {
return _internetConnectionChecker.hasConnection;
}
```

## Consequences

- If user send message when network is not available, message will be cached and then
- User can resend message manually when network is available
- User can edit/delete cached messages
13 changes: 2 additions & 11 deletions lib/features/caching/caching_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/local/local_spam_report_manager.dart';
import 'package:tmail_ui_user/features/offline_mode/controller/work_manager_controller.dart';
import 'package:tmail_ui_user/features/offline_mode/manager/sending_email_cache_manager.dart';
import 'package:tmail_ui_user/features/push_notification/data/keychain/keychain_sharing_manager.dart';

Expand Down Expand Up @@ -72,7 +71,7 @@ class CachingManager {
_sessionHiveCacheClient.clearAllData(),
_newEmailHiveCacheClient.clearAllData(),
_openedEmailHiveCacheClient.clearAllData(),
_clearSendingEmailCache(),
_sendingEmailCacheManager.clearAllSendingEmails(),
],
if (PlatformInfo.isIOS)
_keychainSharingManager.delete()
Expand All @@ -92,7 +91,7 @@ class CachingManager {
...[
_newEmailHiveCacheClient.clearAllData(),
_openedEmailHiveCacheClient.clearAllData(),
_clearSendingEmailCache(),
_sendingEmailCacheManager.clearAllSendingEmails(),
]
], eagerError: true);
}
Expand Down Expand Up @@ -139,12 +138,4 @@ class CachingManager {
_fileUtils.removeFolder(CachingConstants.openedEmailContentFolderName),
]);
}

Future<void> _clearSendingEmailCache() async {
final listSendingEmails = await _sendingEmailCacheManager.getAllSendingEmails();
final sendingIds = listSendingEmails.map((sendingEmail) => sendingEmail.sendingId).toSet().toList();
if (sendingIds.isNotEmpty) {
await _sendingEmailCacheManager.clearAllSendingEmails();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ import 'package:tmail_ui_user/features/manage_account/presentation/model/account
import 'package:tmail_ui_user/features/manage_account/presentation/model/manage_account_arguments.dart';
import 'package:tmail_ui_user/features/network_connection/presentation/network_connection_controller.dart'
if (dart.library.html) 'package:tmail_ui_user/features/network_connection/presentation/web_network_connection_controller.dart';
import 'package:tmail_ui_user/features/offline_mode/config/work_manager_constants.dart';
import 'package:tmail_ui_user/features/offline_mode/controller/work_manager_controller.dart';
import 'package:tmail_ui_user/features/offline_mode/work_manager/one_time_work_request.dart';
import 'package:tmail_ui_user/features/offline_mode/work_manager/worker_type.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailbox_state_to_refresh_state.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart';
Expand Down Expand Up @@ -155,7 +151,6 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:tmail_ui_user/main/routes/route_utils.dart';
import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
import 'package:uuid/uuid.dart';
import 'package:workmanager/workmanager.dart' as work_manager;

class MailboxDashBoardController extends ReloadableController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class MailboxVisibilityView extends GetWidget<MailboxVisibilityController>
categories,
controller,
toggleMailboxCategories: controller.toggleMailboxCategories,
padding: EdgeInsetsDirectional.symmetric(vertical: 8)
padding: const EdgeInsetsDirectional.symmetric(vertical: 8)
),
AnimatedContainer(
duration: const Duration(milliseconds: 400),
Expand Down
2 changes: 0 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:core/presentation/utils/theme_utils.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/platform_info.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
import 'package:tmail_ui_user/features/offline_mode/config/work_manager_config.dart';
import 'package:tmail_ui_user/main/bindings/main_bindings.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations_delegate.dart';
Expand Down

0 comments on commit 67fca11

Please sign in to comment.