WD: config based live activity placed.

* variable place in the appstate to manage the live activity
* single utility function to show the live activity
live_activities
tahaalam 3 weeks ago
parent cb569c2770
commit 02cd542bd9

@ -47,6 +47,7 @@ class AppState {
AuthenticatedUser? _authenticatedChildUser;
bool isPaytabsEnabled = false;
bool isLiveActivityEnabled = true;
bool isPayfortHostedPageEnabled = true;
void setIsPaytabsEnabled(bool value) {

@ -68,7 +68,7 @@ Future<dynamic> 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<dynamic> 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 {

@ -1178,6 +1178,9 @@ class Utils {
}
static addLiveNotification(dynamic data, {bool isBackgroundMessage = false}) async {
debugPrint("live activity is enabled or not ${getIt<AppState>().isLiveActivityEnabled}");
if(!getIt<AppState>().isLiveActivityEnabled) return;
var liveActivity = LiveActivities();
liveActivity.init(appGroupId: "group.alhabib.patientApp");

Loading…
Cancel
Save