diff --git a/lib/main.dart b/lib/main.dart index 2f0ef38..ea86159 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:sfm_app/product/services/api_services.dart'; import 'product/services/notification_services.dart'; import 'product/services/theme_services.dart'; import 'product/services/language_services.dart'; @@ -58,7 +59,7 @@ class _MyAppState extends State { LanguageServices languageServices = LanguageServices(); ThemeServices themeServices = ThemeServices(); final NotificationServices notificationServices = NotificationServices(); - + APIServices apiServices = APIServices(); setLocale(Locale locale) { _locale = locale; mainBloc.sinkLanguage.add(_locale); @@ -77,9 +78,15 @@ class _MyAppState extends State { // notificationServices.setupInteractMessage(); notificationServices.getDeviceToken().then((token){ print("Firebase Token: $token"); + sendNotificationToken(token); }); } + void sendNotificationToken (String token) async { + int statusCode = await apiServices.sendNotificationToken(token); + log("Notification Send StatusCode : $statusCode"); + } + @override void didChangeDependencies() { languageServices.getLocale().then((locale) => {setLocale(locale)}); diff --git a/lib/product/constant/app/api_path_constant.dart b/lib/product/constant/app/api_path_constant.dart index bcdbeb5..d7f9838 100644 --- a/lib/product/constant/app/api_path_constant.dart +++ b/lib/product/constant/app/api_path_constant.dart @@ -21,4 +21,5 @@ class APIPathConstants { static const JOIN_GROUP_PATH = "/api/groups/join"; static const APPROVE_GROUP_PATH = "/api/groups/approve"; static const DEVICE_LOGS_PATH = "/api/device-logs"; + static const NOTIFICATION_TOKEN_PATH = "/api/users/app-token"; } diff --git a/lib/product/services/api_services.dart b/lib/product/services/api_services.dart index e292d71..00c8405 100644 --- a/lib/product/services/api_services.dart +++ b/lib/product/services/api_services.dart @@ -49,6 +49,17 @@ class APIServices { return response.body; } + Future sendNotificationToken(String token) async{ + String uid = await getUID(); + Map body = { + "user_id": uid, + "app_token": token + }; + int statusCode = await NetworkManager.instance!.updateDataInServer( + APIPathConstants.NOTIFICATION_TOKEN_PATH, body); + return statusCode; + } + Future logOut(BuildContext context) async { showDialog( context: context, diff --git a/lib/product/services/notification_services.dart b/lib/product/services/notification_services.dart index 822bdbc..46ce265 100644 --- a/lib/product/services/notification_services.dart +++ b/lib/product/services/notification_services.dart @@ -75,7 +75,7 @@ class NotificationServices { importance: androidNotificationChannel.importance, priority: Priority.high, ticker: 'ticker', - actions: type == "warn1" + actions: type == "smoke_warning" ? [ const AndroidNotificationAction( "id1", @@ -117,9 +117,9 @@ class NotificationServices { return const RawResourceAndroidNotificationSound("welcome"); } else if (type == "success") { return const RawResourceAndroidNotificationSound("success_alert"); - } else if (type == "warn1") { + } else if (type == "smoke_warning") { return const RawResourceAndroidNotificationSound("warning_alarm"); - } else if (type == "warn2") { + } else if (type == "battery_warning") { return const RawResourceAndroidNotificationSound("new_alarm"); } else { return const RawResourceAndroidNotificationSound("normal");