From 02cd542bd9806b1ee9c9bbb60a6c19d76a65298b Mon Sep 17 00:00:00 2001 From: tahaalam Date: Thu, 23 Jul 2026 11:39:30 +0300 Subject: [PATCH] WD: config based live activity placed. * variable place in the appstate to manage the live activity * single utility function to show the live activity --- lib/core/app_state.dart | 1 + lib/core/utils/push_notification_handler.dart | 100 +++++++++--------- lib/core/utils/utils.dart | 3 + 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index a27b727e..4b3d2e0c 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -47,6 +47,7 @@ class AppState { AuthenticatedUser? _authenticatedChildUser; bool isPaytabsEnabled = false; + bool isLiveActivityEnabled = true; bool isPayfortHostedPageEnabled = true; void setIsPaytabsEnabled(bool value) { diff --git a/lib/core/utils/push_notification_handler.dart b/lib/core/utils/push_notification_handler.dart index 559c936c..3b09b1cb 100644 --- a/lib/core/utils/push_notification_handler.dart +++ b/lib/core/utils/push_notification_handler.dart @@ -68,7 +68,7 @@ Future backgroundMessageHandler(dynamic message) async { WidgetsFlutterBinding.ensureInitialized(); DartPluginRegistrant.ensureInitialized(); await Future.delayed(Duration(seconds: 2)); - addLiveNotification(message, isBackgroundMessage: true); + Utils.addLiveNotification(message, isBackgroundMessage: true); } catch (e, stackTrace) { } } @@ -115,54 +115,54 @@ Future backgroundMessageHandler(dynamic message) async { // print("the activity is is created or updated"); // // } -addLiveNotification(dynamic data, {bool isBackgroundMessage = false}) async{ - - var liveActivity = LiveActivities(); - - liveActivity.init(appGroupId: "group.alhabib.patientApp"); - // if(Platform.isIOS){ - // LiveActivityHelperChannel.removeData(); - // } - var queueNoForWhichActivityIdCreated = await Utils.getStringFromPrefs( CacheConst.patientQueueNoForLiveActivity); - var activityId = await Utils.getStringFromPrefs( data.data['queueNo'] ??""); - - var buttonText = Utils.getCardButtonText(int.parse(data.data['callType']??"1"), data.data['roomNo']); - PatientQueue _patientQueue = PatientQueue( - queueNo: data.data['queueNo'] ?? "IME-1", - currentlyServingStatus: (data.data['servingCallType'] ?? 0) == "1" ?LocaleKeys.callForVitalSign.tr() : LocaleKeys.callForDoctor.tr() , - currentlyServingToken: data.data['servingQueueNo'] ?? "IME-3", - nextTicketStatus: buttonText, - callType: int.parse(data.data['callType']??"1"), - currentlyServingCallType: int.parse(data.data['servingCallType']??"1"), - yourTicketHeader: LocaleKeys.yourQueueNumber.tr(), - currentlyServingTitle: LocaleKeys.currentServing.tr() - ); - if((queueNoForWhichActivityIdCreated??"") != (_patientQueue.queueNo??"")){ - liveActivity.endActivity(activityId); - activityId = ""; - } - - if( activityId == ""){ - String? id = await liveActivity.createActivity( - DateTime.now().millisecondsSinceEpoch.toString(), - _patientQueue.toMap(), - ); - await Utils.saveStringFromPrefs(_patientQueue.queueNo ??"", id??""); - await Utils.saveStringFromPrefs(CacheConst.patientQueueNoForLiveActivity ??"", _patientQueue.queueNo??""); - return; - } - if(Platform.isIOS) { - await liveActivity.createOrUpdateActivity( - activityId, - _patientQueue.toMap(), - ); - }else{ - await liveActivity.updateActivity( - activityId, - _patientQueue.toMap(), - ); - } -} +// addLiveNotification(dynamic data, {bool isBackgroundMessage = false}) async{ +// +// var liveActivity = LiveActivities(); +// +// liveActivity.init(appGroupId: "group.alhabib.patientApp"); +// // if(Platform.isIOS){ +// // LiveActivityHelperChannel.removeData(); +// // } +// var queueNoForWhichActivityIdCreated = await Utils.getStringFromPrefs( CacheConst.patientQueueNoForLiveActivity); +// var activityId = await Utils.getStringFromPrefs( data.data['queueNo'] ??""); +// +// var buttonText = Utils.getCardButtonText(int.parse(data.data['callType']??"1"), data.data['roomNo']); +// PatientQueue _patientQueue = PatientQueue( +// queueNo: data.data['queueNo'] ?? "IME-1", +// currentlyServingStatus: (data.data['servingCallType'] ?? 0) == "1" ?LocaleKeys.callForVitalSign.tr() : LocaleKeys.callForDoctor.tr() , +// currentlyServingToken: data.data['servingQueueNo'] ?? "IME-3", +// nextTicketStatus: buttonText, +// callType: int.parse(data.data['callType']??"1"), +// currentlyServingCallType: int.parse(data.data['servingCallType']??"1"), +// yourTicketHeader: LocaleKeys.yourQueueNumber.tr(), +// currentlyServingTitle: LocaleKeys.currentServing.tr() +// ); +// if((queueNoForWhichActivityIdCreated??"") != (_patientQueue.queueNo??"")){ +// liveActivity.endActivity(activityId); +// activityId = ""; +// } +// +// if( activityId == ""){ +// String? id = await liveActivity.createActivity( +// DateTime.now().millisecondsSinceEpoch.toString(), +// _patientQueue.toMap(), +// ); +// await Utils.saveStringFromPrefs(_patientQueue.queueNo ??"", id??""); +// await Utils.saveStringFromPrefs(CacheConst.patientQueueNoForLiveActivity ??"", _patientQueue.queueNo??""); +// return; +// } +// if(Platform.isIOS) { +// await liveActivity.createOrUpdateActivity( +// activityId, +// _patientQueue.toMap(), +// ); +// }else{ +// await liveActivity.updateActivity( +// activityId, +// _patientQueue.toMap(), +// ); +// } +// } callPage(String sessionID, String token) async {} @@ -669,7 +669,7 @@ class PushNotificationHandler { // ); // print("the activity is $activity"); - addLiveNotification(remoteMessage, isBackgroundMessage: false); + Utils.addLiveNotification(remoteMessage, isBackgroundMessage: false); } else { diff --git a/lib/core/utils/utils.dart b/lib/core/utils/utils.dart index 1e4a0a03..3b8fd9c2 100644 --- a/lib/core/utils/utils.dart +++ b/lib/core/utils/utils.dart @@ -1178,6 +1178,9 @@ class Utils { } static addLiveNotification(dynamic data, {bool isBackgroundMessage = false}) async { + debugPrint("live activity is enabled or not ${getIt().isLiveActivityEnabled}"); + if(!getIt().isLiveActivityEnabled) return; + var liveActivity = LiveActivities(); liveActivity.init(appGroupId: "group.alhabib.patientApp");