public override async void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { if (this.sdelegate.Value == null) { return; } var notification = response.Notification.Request.FromNative(); if (response is UNTextInputNotificationResponse textResponse) { await Log.SafeExecute(async() => { var shinyResponse = new NotificationResponse(notification, textResponse.ActionIdentifier, textResponse.UserText); await this.sdelegate.Value.OnEntry(shinyResponse); }); } else { await Log.SafeExecute(async() => { var shinyResponse = new NotificationResponse(notification, response.ActionIdentifier, null); await this.sdelegate.Value.OnEntry(shinyResponse); }); } completionHandler(); }
public override void OnReceive(Context context, Intent intent) { //if (intent.Action != IntentAction) // return; var delegates = ShinyHost.ResolveAll <INotificationDelegate>(); if (!delegates.Any()) { return; } this.Execute(async() => { var manager = ShinyHost.Resolve <INotificationManager>(); var serializer = ShinyHost.Resolve <ISerializer>(); var stringNotification = intent.GetStringExtra("Notification"); var action = intent.GetStringExtra("Action"); var notification = serializer.Deserialize <Notification>(stringNotification); var text = RemoteInput.GetResultsFromIntent(intent)?.GetString("Result"); context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); var response = new NotificationResponse(notification, action, text); await delegates.RunDelegates(x => x.OnEntry(response)); await manager.Cancel(notification.Id); }); }
public static NotificationResponse FromNative(this UNNotificationResponse native) { var shiny = native.Notification.Request.FromNative(); NotificationResponse response = default; if (native is UNTextInputNotificationResponse textResponse) { response = new NotificationResponse( shiny, textResponse.ActionIdentifier, textResponse.UserText ); } else { response = new NotificationResponse(shiny, native.ActionIdentifier, null); } return(response); }
public void Start() { this.nativeDelegate .WhenPresented() .Where(x => !(x.Notification?.Request?.Trigger is UNPushNotificationTrigger)) .SubscribeAsync(async x => { var shiny = x.Notification.Request.FromNative(); if (shiny != null) { await this.services.RunDelegates <INotificationDelegate>(x => x.OnReceived(shiny)); x.CompletionHandler.Invoke(UNNotificationPresentationOptions.Alert); } }); this.nativeDelegate .WhenResponse() .Where(x => !(x.Response.Notification?.Request?.Trigger is UNPushNotificationTrigger)) .SubscribeAsync(async x => { var shiny = x.Response.Notification.Request.FromNative(); if (shiny != null) { NotificationResponse response = default; if (x.Response is UNTextInputNotificationResponse textResponse) { response = new NotificationResponse( shiny, textResponse.ActionIdentifier, textResponse.UserText ); } else { response = new NotificationResponse(shiny, x.Response.ActionIdentifier, null); } await this.services.RunDelegates <INotificationDelegate>(x => x.OnEntry(response)); x.CompletionHandler(); } }); }
public async void TryProcessIntent(Intent intent) { if (intent == null || !this.delegates.Any()) { return; } if (!intent.HasExtra(NOTIFICATION_KEY)) { return; } await this.delegates.RunDelegates(async ndelegate => { var notificationString = intent.GetStringExtra(NOTIFICATION_KEY); var notification = this.serializer.Deserialize <Notification>(notificationString); var response = new NotificationResponse(notification, null, null); await ndelegate.OnEntry(response); }); }
public async void TryProcessIntent(Intent intent) { if (intent == null || this.ndelegate == null) { return; } if (!intent.HasExtra(NOTIFICATION_KEY)) { return; } await this.services.SafeResolveAndExecute <INotificationDelegate>(async ndelegate => { var notificationString = intent.GetStringExtra(NOTIFICATION_KEY); var notification = this.serializer.Deserialize <Notification>(notificationString); var response = new NotificationResponse(notification, null, null); await ndelegate.OnEntry(response); }, false); }
public async Task TryProcessIntent(Intent?intent) { if (intent == null || !this.delegates.Any()) { return; } if (intent.HasExtra(IntentNotificationKey)) { var notificationString = intent.GetStringExtra(IntentNotificationKey); var notification = this.serializer.Deserialize <Notification>(notificationString); var action = intent.GetStringExtra(IntentActionKey); var text = RemoteInput.GetResultsFromIntent(intent)?.GetString("Result"); var response = new NotificationResponse(notification, action, text); // the notification lives within the intent since it has already been removed from the repo await this.delegates.RunDelegates(x => x.OnEntry(response)); } }