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; AuthenticatedUser? _authenticatedChildUser;
bool isPaytabsEnabled = false; bool isPaytabsEnabled = false;
bool isLiveActivityEnabled = true;
bool isPayfortHostedPageEnabled = true; bool isPayfortHostedPageEnabled = true;
void setIsPaytabsEnabled(bool value) { void setIsPaytabsEnabled(bool value) {

@ -68,7 +68,7 @@ Future<dynamic> backgroundMessageHandler(dynamic message) async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
DartPluginRegistrant.ensureInitialized(); DartPluginRegistrant.ensureInitialized();
await Future.delayed(Duration(seconds: 2)); await Future.delayed(Duration(seconds: 2));
addLiveNotification(message, isBackgroundMessage: true); Utils.addLiveNotification(message, isBackgroundMessage: true);
} catch (e, stackTrace) { } catch (e, stackTrace) {
} }
} }
@ -115,54 +115,54 @@ Future<dynamic> backgroundMessageHandler(dynamic message) async {
// print("the activity is is created or updated"); // print("the activity is is created or updated");
// //
// } // }
addLiveNotification(dynamic data, {bool isBackgroundMessage = false}) async{ // addLiveNotification(dynamic data, {bool isBackgroundMessage = false}) async{
//
var liveActivity = LiveActivities(); // var liveActivity = LiveActivities();
//
liveActivity.init(appGroupId: "group.alhabib.patientApp"); // liveActivity.init(appGroupId: "group.alhabib.patientApp");
// if(Platform.isIOS){ // // if(Platform.isIOS){
// LiveActivityHelperChannel.removeData(); // // LiveActivityHelperChannel.removeData();
// } // // }
var queueNoForWhichActivityIdCreated = await Utils.getStringFromPrefs( CacheConst.patientQueueNoForLiveActivity); // var queueNoForWhichActivityIdCreated = await Utils.getStringFromPrefs( CacheConst.patientQueueNoForLiveActivity);
var activityId = await Utils.getStringFromPrefs( data.data['queueNo'] ??""); // var activityId = await Utils.getStringFromPrefs( data.data['queueNo'] ??"");
//
var buttonText = Utils.getCardButtonText(int.parse(data.data['callType']??"1"), data.data['roomNo']); // var buttonText = Utils.getCardButtonText(int.parse(data.data['callType']??"1"), data.data['roomNo']);
PatientQueue _patientQueue = PatientQueue( // PatientQueue _patientQueue = PatientQueue(
queueNo: data.data['queueNo'] ?? "IME-1", // queueNo: data.data['queueNo'] ?? "IME-1",
currentlyServingStatus: (data.data['servingCallType'] ?? 0) == "1" ?LocaleKeys.callForVitalSign.tr() : LocaleKeys.callForDoctor.tr() , // currentlyServingStatus: (data.data['servingCallType'] ?? 0) == "1" ?LocaleKeys.callForVitalSign.tr() : LocaleKeys.callForDoctor.tr() ,
currentlyServingToken: data.data['servingQueueNo'] ?? "IME-3", // currentlyServingToken: data.data['servingQueueNo'] ?? "IME-3",
nextTicketStatus: buttonText, // nextTicketStatus: buttonText,
callType: int.parse(data.data['callType']??"1"), // callType: int.parse(data.data['callType']??"1"),
currentlyServingCallType: int.parse(data.data['servingCallType']??"1"), // currentlyServingCallType: int.parse(data.data['servingCallType']??"1"),
yourTicketHeader: LocaleKeys.yourQueueNumber.tr(), // yourTicketHeader: LocaleKeys.yourQueueNumber.tr(),
currentlyServingTitle: LocaleKeys.currentServing.tr() // currentlyServingTitle: LocaleKeys.currentServing.tr()
); // );
if((queueNoForWhichActivityIdCreated??"") != (_patientQueue.queueNo??"")){ // if((queueNoForWhichActivityIdCreated??"") != (_patientQueue.queueNo??"")){
liveActivity.endActivity(activityId); // liveActivity.endActivity(activityId);
activityId = ""; // activityId = "";
} // }
//
if( activityId == ""){ // if( activityId == ""){
String? id = await liveActivity.createActivity( // String? id = await liveActivity.createActivity(
DateTime.now().millisecondsSinceEpoch.toString(), // DateTime.now().millisecondsSinceEpoch.toString(),
_patientQueue.toMap(), // _patientQueue.toMap(),
); // );
await Utils.saveStringFromPrefs(_patientQueue.queueNo ??"", id??""); // await Utils.saveStringFromPrefs(_patientQueue.queueNo ??"", id??"");
await Utils.saveStringFromPrefs(CacheConst.patientQueueNoForLiveActivity ??"", _patientQueue.queueNo??""); // await Utils.saveStringFromPrefs(CacheConst.patientQueueNoForLiveActivity ??"", _patientQueue.queueNo??"");
return; // return;
} // }
if(Platform.isIOS) { // if(Platform.isIOS) {
await liveActivity.createOrUpdateActivity( // await liveActivity.createOrUpdateActivity(
activityId, // activityId,
_patientQueue.toMap(), // _patientQueue.toMap(),
); // );
}else{ // }else{
await liveActivity.updateActivity( // await liveActivity.updateActivity(
activityId, // activityId,
_patientQueue.toMap(), // _patientQueue.toMap(),
); // );
} // }
} // }
callPage(String sessionID, String token) async {} callPage(String sessionID, String token) async {}
@ -669,7 +669,7 @@ class PushNotificationHandler {
// ); // );
// print("the activity is $activity"); // print("the activity is $activity");
addLiveNotification(remoteMessage, isBackgroundMessage: false); Utils.addLiveNotification(remoteMessage, isBackgroundMessage: false);
} }
else { else {

@ -1178,6 +1178,9 @@ class Utils {
} }
static addLiveNotification(dynamic data, {bool isBackgroundMessage = false}) async { 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(); var liveActivity = LiveActivities();
liveActivity.init(appGroupId: "group.alhabib.patientApp"); liveActivity.init(appGroupId: "group.alhabib.patientApp");

Loading…
Cancel
Save