TF-1812 Abstract method in handle background task
(cherry picked from commit 16b62ed183e32f10ce9b1002f4097144317650f1)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:tmail_ui_user/features/offline_mode/config/work_manager_constants.dart';
|
||||
import 'package:tmail_ui_user/features/offline_mode/scheduler/one_time_work_request.dart';
|
||||
import 'package:tmail_ui_user/features/offline_mode/scheduler/periodic_work_request.dart';
|
||||
import 'package:tmail_ui_user/features/offline_mode/scheduler/work_request.dart';
|
||||
@@ -46,15 +47,23 @@ class WorkSchedulerController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> handleBackgroundTask(String taskName, Map<String, dynamic>? inputData) {
|
||||
if (inputData != null && inputData.isNotEmpty) {
|
||||
final typeTask = inputData['workerType'];
|
||||
final dataObject = inputData['data'];
|
||||
log('WorkSchedulerController::handleBackgroundTask():typeTask: $typeTask | dataObject: $dataObject');
|
||||
final workType = WorkerType.values.firstWhereOrNull((type) => type.name == typeTask);
|
||||
log('WorkSchedulerController::handleBackgroundTask():workType: $workType');
|
||||
}
|
||||
Future<bool> handleBackgroundTask(String taskName, Map<String, dynamic>? inputData) async {
|
||||
log('WorkSchedulerController::handleBackgroundTask():taskName: $taskName | inputData: $inputData');
|
||||
try {
|
||||
if (inputData != null && inputData.isNotEmpty) {
|
||||
final workerType = inputData.remove(WorkManagerConstants.workerTypeKey);
|
||||
final dataObject = inputData;
|
||||
log('WorkSchedulerController::handleBackgroundTask():workerType: $workerType | dataObject: $dataObject');
|
||||
final matchedType = WorkerType.values.firstWhereOrNull((type) => type.name == workerType);
|
||||
|
||||
if (matchedType != null) {
|
||||
await matchedType.usingObserver().bindDI();
|
||||
await matchedType.usingObserver().observe(taskName, dataObject);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
logError('WorkSchedulerController::handleBackgroundTask():EXCEPTION: $e');
|
||||
}
|
||||
return Future.value(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user