|
|
|
|
@ -19,6 +19,7 @@ import 'package:hmg_patient_app_new/core/common_models/patient_queue.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/cache_consts.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/patient_queue_details_response_model.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/cache_service.dart';
|
|
|
|
|
import 'package:live_activities/live_activities.dart' show LiveActivities;
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
@ -39,25 +40,26 @@ Future<dynamic> backgroundMessageHandler(dynamic message) async {
|
|
|
|
|
_incomingCall(message.data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(message.data['isLiveActivity'] == true){
|
|
|
|
|
if (message.data['isLiveActivity'] == true || message.data['isLiveActivity'] == "true") {
|
|
|
|
|
print("live activity called");
|
|
|
|
|
|
|
|
|
|
LiveActivities().init(appGroupId: "group.alhabib.patientApp");
|
|
|
|
|
await LiveActivities().endAllActivities();
|
|
|
|
|
await Permission.notification.request();
|
|
|
|
|
PatientQueue _patientQueue =
|
|
|
|
|
PatientQueue(
|
|
|
|
|
queueNo: message.data['queueNo']??"IME-1",
|
|
|
|
|
currentlyServingStatus: (message.data['callType']??0) == 1 ? "Call for vital signs".needTranslation : "Call for Doctor".needTranslation,
|
|
|
|
|
currentlyServing: message.data['currentlyServing']??"IME-3",
|
|
|
|
|
nextTicketStatus: message.data['nextTicketStatus']??"Please wait! you will be called for vital signs",
|
|
|
|
|
nextTicketBackground: message.data['nextTicketBackground']??2
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await LiveActivities().createActivity(
|
|
|
|
|
// await Permission.notification.request();
|
|
|
|
|
var buttonText = Utils.getCardButtonText(int.parse(message.data['callType']??"1"), message.data['roomNo']);
|
|
|
|
|
PatientQueue _patientQueue = PatientQueue(
|
|
|
|
|
queueNo: message.data['queueNo'] ?? "IME-1",
|
|
|
|
|
currentlyServingStatus: (message.data['servingCallType'] ?? 0) == "1" ? "Call for vital signs".needTranslation : "Call for Doctor".needTranslation,
|
|
|
|
|
currentlyServingTitle: message.data['servingQueueNo'] ?? "IME-3",
|
|
|
|
|
nextTicketStatus: buttonText,
|
|
|
|
|
callType: int.parse(message.data['callType']??"1"),
|
|
|
|
|
currentlyServingCallType: int.parse(message.data['servingCallType']??"1"));
|
|
|
|
|
|
|
|
|
|
var activity= await LiveActivities().createActivity(
|
|
|
|
|
DateTime.now().millisecondsSinceEpoch.toString(),
|
|
|
|
|
_patientQueue.toMap(),
|
|
|
|
|
);
|
|
|
|
|
print("the activity is $activity");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -284,7 +286,18 @@ class PushNotificationHandler {
|
|
|
|
|
|
|
|
|
|
init(BuildContext context) async {
|
|
|
|
|
this.context = context;
|
|
|
|
|
|
|
|
|
|
final PermissionStatus status = await Permission.notification.request();
|
|
|
|
|
if (status.isGranted) {
|
|
|
|
|
// Notification permissions granted
|
|
|
|
|
print("Notification permissions granted");
|
|
|
|
|
} else if (status.isDenied) {
|
|
|
|
|
// Notification permissions denied
|
|
|
|
|
print("Notification permissions not granted");
|
|
|
|
|
|
|
|
|
|
} else if (status.isPermanentlyDenied) {
|
|
|
|
|
// // Notification permissions permanently denied, open app settings
|
|
|
|
|
// await openAppSettings();
|
|
|
|
|
}
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
voIPKit.getVoIPToken().then((value) {
|
|
|
|
|
print("🎈 APNS VOIP KIT TOKEN: $value");
|
|
|
|
|
@ -337,19 +350,29 @@ class PushNotificationHandler {
|
|
|
|
|
// timeOutTimer.cancel();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
try {
|
|
|
|
|
final fcmToken = await FirebaseMessaging.instance.getToken().catchError((err) {
|
|
|
|
|
print(err);
|
|
|
|
|
});
|
|
|
|
|
if (fcmToken != null) onToken(fcmToken);
|
|
|
|
|
// }
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
print("Notification Exception: $ex");
|
|
|
|
|
}
|
|
|
|
|
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
|
try {
|
|
|
|
|
final fcmToken = await FirebaseMessaging.instance.getToken().catchError((err) {
|
|
|
|
|
print(err);
|
|
|
|
|
});
|
|
|
|
|
if (fcmToken != null) onToken(fcmToken);
|
|
|
|
|
// }
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
print("Notification Exception: $ex");
|
|
|
|
|
}
|
|
|
|
|
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
|
|
|
|
|
|
// if (Platform.isAndroid) {
|
|
|
|
|
// try {
|
|
|
|
|
// final fcmToken = await FirebaseMessaging.instance.getToken().catchError((err) {
|
|
|
|
|
// print(err);
|
|
|
|
|
// });
|
|
|
|
|
// if (fcmToken != null) onToken(fcmToken);
|
|
|
|
|
// // }
|
|
|
|
|
// } catch (ex) {
|
|
|
|
|
// print("Notification Exception: $ex");
|
|
|
|
|
// }
|
|
|
|
|
// FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
final permission = await FirebaseMessaging.instance.requestPermission();
|
|
|
|
|
@ -367,6 +390,7 @@ class PushNotificationHandler {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage? message) async {
|
|
|
|
|
|
|
|
|
|
if (message != null) {
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
await Future.delayed(Duration(milliseconds: 3000)).then((value) {
|
|
|
|
|
@ -436,24 +460,22 @@ class PushNotificationHandler {
|
|
|
|
|
|
|
|
|
|
if(remoteMessage.data['isLiveActivity'] == true || remoteMessage.data['isLiveActivity'] == 'true'){
|
|
|
|
|
print("live activity called");
|
|
|
|
|
LiveActivities().init(appGroupId: "group.alhabib.patientApp");
|
|
|
|
|
await LiveActivities().endAllActivities();
|
|
|
|
|
await Permission.notification.request();
|
|
|
|
|
// await Permission.notification.request();
|
|
|
|
|
var buttonText = Utils.getCardButtonText(int.parse(remoteMessage.data['callType']??"1"), remoteMessage.data['roomNo']);
|
|
|
|
|
PatientQueue _patientQueue =
|
|
|
|
|
PatientQueue(
|
|
|
|
|
title: remoteMessage.data['title']??"HMG",
|
|
|
|
|
contentText: remoteMessage.data['contentText']??"HMG Queue line",
|
|
|
|
|
nextTicket: remoteMessage.data['nextTicket']??"IME-1",
|
|
|
|
|
currentlyServingStatus: remoteMessage.data['currentlyServingStatus']??"Call for vital signs",
|
|
|
|
|
currentlyServing: remoteMessage.data['currentlyServing']??"IME-3",
|
|
|
|
|
nextTicketStatus: remoteMessage.data['nextTicketStatus']??"Please wait! you will be called for vital signs",
|
|
|
|
|
nextTicketBackground: remoteMessage.data['nextTicketBackground']??2
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await LiveActivities().createActivity(
|
|
|
|
|
queueNo: remoteMessage.data['queueNo'] ?? "IME-1",
|
|
|
|
|
currentlyServingStatus: (remoteMessage.data['servingCallType'] ?? 0) == 1 ? "Call for vital signs".needTranslation : "Call for Doctor".needTranslation,
|
|
|
|
|
currentlyServingTitle: remoteMessage.data['servingQueueNo'] ?? "IME-3",
|
|
|
|
|
nextTicketStatus: buttonText,
|
|
|
|
|
callType: int.parse(remoteMessage.data['callType']??"1"),currentlyServingCallType: int.parse(remoteMessage.data['servingCallType']??"1"));
|
|
|
|
|
var activity = await LiveActivities().createActivity(
|
|
|
|
|
DateTime.now().millisecondsSinceEpoch.toString(),
|
|
|
|
|
_patientQueue.toMap(),
|
|
|
|
|
);
|
|
|
|
|
print("the activity is $activity");
|
|
|
|
|
}
|
|
|
|
|
// GetNotificationsResponseModel notification = new GetNotificationsResponseModel();
|
|
|
|
|
//
|
|
|
|
|
|