TF-1205: rename class
This commit is contained in:
@@ -1,46 +1,46 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource/firebase_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource_impl/hive_account_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/local/firebase_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/repository/firebase_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/firebase_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_firebase_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_firebase_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/save_firebase_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource_impl/hive_fcm_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/repository/fcm_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_fcm_token_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_fcm_token_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/save_fcm_token_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
|
||||
|
||||
class FireBaseBindings extends BaseBindings {
|
||||
class FCMBindings extends BaseBindings {
|
||||
@override
|
||||
void bindingsController() {}
|
||||
|
||||
@override
|
||||
void bindingsDataSource() {
|
||||
Get.put<FirebaseDatasource>(Get.find<HiveFirebaseDatasourceImpl>());
|
||||
Get.put<FCMDatasource>(Get.find<HiveFCMDatasourceImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.put(HiveFirebaseDatasourceImpl(
|
||||
Get.find<FirebaseCacheManager>(),
|
||||
Get.put(HiveFCMDatasourceImpl(
|
||||
Get.find<FCMCacheManager>(),
|
||||
Get.find<CacheExceptionThrower>(),
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsInteractor() {
|
||||
Get.put(DeleteFirebaseCacheInteractor(Get.find<FirebaseRepositoryImpl>()));
|
||||
Get.put(SaveFirebaseCacheInteractor(Get.find<FirebaseRepositoryImpl>()));
|
||||
Get.put(GetFirebaseCacheInteractor(Get.find<FirebaseRepositoryImpl>()));
|
||||
Get.put(DeleteFCMTokenCacheInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.put(SaveFCMTokenCacheInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.put(GetFCMTokenCacheInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepository() {
|
||||
Get.put<FirebaseRepository>(Get.find<FirebaseRepositoryImpl>());
|
||||
Get.put<FCMRepository>(Get.find<FCMRepositoryImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepositoryImpl() {
|
||||
Get.put(FirebaseRepositoryImpl(Get.find<FirebaseDatasource>()));
|
||||
Get.put(FCMRepositoryImpl(Get.find<FCMDatasource>()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:model/firebase/firebase_dto.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/save_firebase_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/presentation/firebase_options.dart';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
await dotenv.load(fileName: 'env.file');
|
||||
try {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
} catch (e) {
|
||||
log('NotificationService::initializeNotificationService(): $e');
|
||||
}
|
||||
log('firebaseMessagingBackgroundHandler: ${message.data}');
|
||||
}
|
||||
|
||||
class NotificationService {
|
||||
factory NotificationService() => _instance;
|
||||
|
||||
NotificationService._internal();
|
||||
|
||||
static final NotificationService _instance = NotificationService._internal();
|
||||
|
||||
static get _firebaseMessaging => FirebaseMessaging.instance;
|
||||
|
||||
static Stream<String> get onTokenRefresh => _firebaseMessaging.onTokenRefresh;
|
||||
static bool _isFlutterLocalNotificationsInitialized = false;
|
||||
|
||||
static Future<void> initializeNotificationService() async {
|
||||
try {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
} catch (e) {
|
||||
log('NotificationService::initializeNotificationService(): $e');
|
||||
}
|
||||
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
|
||||
if (_isFlutterLocalNotificationsInitialized) return;
|
||||
final _saveFirebaseCacheInteractor = Get.find<SaveFirebaseCacheInteractor>();
|
||||
final token = await _firebaseMessaging.getToken();
|
||||
_saveFirebaseCacheInteractor.execute(FirebaseDto(token));
|
||||
await _initFirebaseMessaging();
|
||||
_isFlutterLocalNotificationsInitialized = true;
|
||||
}
|
||||
|
||||
static Future<void> _initFirebaseMessaging() async {
|
||||
FirebaseMessaging.onMessage.listen(_handleIncomingForegroundNotification);
|
||||
FirebaseMessaging.onMessageOpenedApp.listen(_handleOpenedAppNotification);
|
||||
}
|
||||
|
||||
static Future<void> _handleIncomingForegroundNotification(
|
||||
RemoteMessage remoteMessage,
|
||||
) async {
|
||||
log('firebaseMessagingForegroundHandler: ${remoteMessage.data}');
|
||||
}
|
||||
|
||||
static void _handleOpenedAppNotification(RemoteMessage remoteMessage) {}
|
||||
|
||||
|
||||
static Future<void> deleteToken() async => _firebaseMessaging.deleteToken();
|
||||
}
|
||||
Reference in New Issue
Block a user