Пример #1
0
        public void TriggerLocalNotificationUnsafe(AppNotificationMessage message)
        {
            if ((message == null) || string.IsNullOrEmpty(message.Text))
            {
                return;
            }

            if (UIApplication.SharedApplication.ApplicationState == UIApplicationState.Background)
            {
                var notification = new UILocalNotification
                {
                    FireDate  = NSDate.FromTimeIntervalSinceNow(1),
                    AlertBody = message.Text,
                    SoundName = UILocalNotification.DefaultSoundName
                };

                if (!string.IsNullOrEmpty(message.ID))
                {
                    notification.UserInfo = new NSDictionary("nm", JsonConvert.SerializeObject(message));
                }

                UIApplication.SharedApplication.ScheduleLocalNotification(notification);
            }
            else
            {
                Logger.Log("WARNING: RemoteNotifications.TriggerLocalNotification: notification not triggered because app is active");
            }
        }
Пример #2
0
        public static void OnMessage <T>(T presenter, AppNotificationMessage msg)
            where T : FrameworkElement, IInAppNotificationPresenter
        {
            if (msg.Local && !presenter.Dispatcher.HasThreadAccess)
            {
                return;
            }

            if (msg.Data is ExportResult result)
            {
                if (result.State is not ExportState.Succeeded)
                {
                    return;
                }

                var content = ResourceHelper.InflateDataTemplate("ExportNotificationTemplate", result);
                ShowNotification(presenter, content, 5000);
            }
            else if (msg.Data is ExportGlyphsResult glyphsResult)
            {
                if (!glyphsResult.Success)
                {
                    return;
                }

                var content = ResourceHelper.InflateDataTemplate("ExportGlyphsTemplate", glyphsResult);
                ShowNotification(presenter, content, 5000);
            }
            else if (msg.Data is ExportFontFileResult fontExportResult)
            {
                if (!fontExportResult.Success)
                {
                    return;
                }

                var content = ResourceHelper.InflateDataTemplate("ExportFontNotificationTemplate", fontExportResult);
                ShowNotification(presenter, content, 5000);
            }
            else if (msg.Data is AddToCollectionResult added)
            {
                if (!added.Success)
                {
                    return;
                }

                var content = ResourceHelper.InflateDataTemplate("AddedToCollectionNotificationTemplate", added);
                ShowNotification(presenter, content, 5000);
            }
            else if (msg.Data is CollectionUpdatedArgs cua)
            {
                var content = ResourceHelper.InflateDataTemplate("RemoveFromCollectionNotification", cua);
                ShowNotification(presenter, content, 5000);
            }
            else if (msg.Data is string s)
            {
                ShowNotification(presenter, s, msg.DurationInMilliseconds > 0 ? msg.DurationInMilliseconds : 4000);
            }
        }
Пример #3
0
        private async Task handleLocalRecordingsMessage(AppNotificationMessage message)
        {
            LoggerService.Instance.Log("Cloud.handleLocalRecordingsMessage: notification received pulling the recordings");
            await libraryViewModel.Poll(false);

            LoggerService.Instance.Log("Cloud.handleLocalRecordingsMessage: pull completed");
            SelectedItem = CloudItem.Library;
            switch (message.Type)
            {
            case AppNotificationType.DownloadComplete:
                libraryViewModel.SelectedView = (int)LibraryViewMode.Device;
                var localItems = libraryViewModel.LocalItems.ToList();
                var localItem  = localItems.FirstOrDefault(c => c.ID == message.ID);
                libraryViewModel.SelectedLibraryItem = localItem;
                if (localItem != null)
                {
                    libraryViewModel.ListViewItemSelected.Execute(localItem);
                }

                break;

            case AppNotificationType.RecordingReady:
            case AppNotificationType.DownloadFailed:
                libraryViewModel.SelectedView = (int)LibraryViewMode.Cloud;
                var cloudItems = libraryViewModel.CloudItems.ToList();
                var cloudItem  = cloudItems.FirstOrDefault(c => c.ID == message.ID);
                libraryViewModel.SelectedCloudItem = cloudItem;
                if (cloudItem != null)
                {
                    libraryViewModel.ListViewItemSelected.Execute(cloudItem);
                }
                else
                {
                    LoggerService.Instance.Log("ERROR: Cloud.handleLocalRecordingsMessage: cannot find cloud item: " + message.ID);
                }

                if (!libraryViewModel.AutoDownload && (cloudItem != null) && (message.Type == AppNotificationType.RecordingReady))
                {
                    //XXX: Prevent application hang at loading screen
                    Device.StartTimer(TimeSpan.FromSeconds(2), () =>
                    {
                        Task.Factory.StartNew(() =>
                        {
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                if (await Application.Current.MainPage.DisplayAlert("Download", "Do you want to download " + cloudItem.FullTitle + " to your device?", "Yes", "No"))
                                {
                                    await libraryViewModel.DownloadItem(cloudItem, true);
                                }
                            });
                        });

                        return(false);
                    });
                }
                break;
            }
        }
Пример #4
0
        public bool FireNotificationReceived(AppNotificationMessage args)
        {
            var notificationReceived = NotificationReceived;

            if (notificationReceived != null)
            {
                notificationReceived(this, args);
                return(true);
            }

            return(false);
        }
Пример #5
0
        private async Task handleNotificationMessage(AppNotificationMessage message)
        {
            LoggerService.Instance.Log("Cloud.handleNotificationMessage: notification received pulling messages");
            await notificationsViewModel.Poll(false);

            LoggerService.Instance.Log("Cloud.handleNotificationMessage: pull completed");
            SelectedItem = CloudItem.Notifications;
            if (notificationsViewModel.NotificationItems != null)
            {
                var items = notificationsViewModel.NotificationItems.ToList();
                var item  = items.FirstOrDefault(c => c.ID == message.ID);
                notificationsViewModel.SelectedItem = item;
                if (item != null)
                {
                    notificationsViewModel.ListViewItemSelected.Execute(item);
                }
            }
        }
Пример #6
0
        public async Task TriggerLocalNotification(AppNotificationMessage message)
        {
            if ((message == null) || string.IsNullOrEmpty(message.Text))
            {
                return;
            }

            Logger.Log("RemoteNotifications.TriggerLocalNotification: message: " + message + " nid: " + message.ID);

            TaskCompletionSource <bool> localNotificationtriggered = new TaskCompletionSource <bool>();

            Device.BeginInvokeOnMainThread(() =>
            {
                Logger.Log("RemoteNotifications.TriggerLocalNotification: BeginInvokeOnMainThread: ");

                TriggerLocalNotificationUnsafe(message);
                localNotificationtriggered.SetResult(true);
            });

            await localNotificationtriggered.Task;
        }
 void OnNotificationMessage(AppNotificationMessage msg)
 {
     InAppNotificationHelper.OnMessage(this, msg);
 }
 public Task TriggerLocalNotification(AppNotificationMessage arg)
 {
     throw new NotImplementedException();
 }
 public bool FireNotificationReceived(AppNotificationMessage args)
 {
     throw new NotImplementedException();
 }
Пример #10
0
        private async Task handleRemoteNotification(Notification notification)
        {
            if (notification.RecordQueueItem == null)
            {
                LoggerService.Instance.Log("ERROR: Cloud.handleRemoteNotification: notification.RecordQueueItem is null");
                return;
            }

            LoggerService.Instance.Log("Cloud.handleRemoteNotification: notification.type: " + notification.Type.ToString());
            switch (notification.Type)
            {
            case NotificationType.NewRecording:
                if (!libraryViewModel.AutoDownload)
                {
                    var message = new AppNotificationMessage()
                    {
                        ID   = notification.LibraryItem?.ID,
                        Text = "Your recording \"" + notification.RecordQueueItem.FullTitle + "\" is ready to download!",
                        Type = AppNotificationType.RecordingReady
                    };

                    await RemoteNotificationsService.Instance.TriggerLocalNotification(message);

                    LoggerService.Instance.Log("Local notification triggered");
                }
                else
                {
                    LoggerService.Instance.Log("Local notification not triggered because autodownload is enabled");
                    if (libraryViewModel == null)
                    {
                        LoggerService.Instance.Log("ERROR: Cloud.handleRemoteNotification: libraryViewModel is null");
                        return;
                    }

                    if (notification.LibraryItem != null)
                    {
                        if (!LocalLibraryService.Instance.IsItemAddedForDownload(notification.LibraryItem.ID, accountViewModel.UserInfo.Email))
                        {
                            LocalLibraryService.Instance.CreateCloudItemId(notification.LibraryItem.ID, accountViewModel.UserInfo.Email);
                            await libraryViewModel.DownloadItem(notification.LibraryItem, false);
                        }
                        else
                        {
                            LoggerService.Instance.Log("Cloud.handleRemoteNotification: item is already downloading/downloaded or has been ignored before enabling auto download.");
                        }
                    }
                }
                return;

            case NotificationType.FailedRecording:
            case NotificationType.BrowsingError:
            case NotificationType.RecordingIssue:
            {
                var message = new AppNotificationMessage()
                {
                    ID   = notification.ID,
                    Text = "Your recording \"" + notification.RecordQueueItem.FullTitle + "\" has failed!",
                    Type = AppNotificationType.RecordingFailed
                };

                await RemoteNotificationsService.Instance.TriggerLocalNotification(message);

                LoggerService.Instance.Log("Local notification triggered");
            }
                return;

            case NotificationType.DownloadExpiring:
            {
                var message = new AppNotificationMessage()
                {
                    ID   = notification.ID,
                    Text = "Your recording \"" + notification.RecordQueueItem.FullTitle + "\"  is about to expire soon!",
                    Type = AppNotificationType.DownloadExpiring
                };

                await RemoteNotificationsService.Instance.TriggerLocalNotification(message);

                LoggerService.Instance.Log("Local notification triggered");
            }
                return;

            default:
                LoggerService.Instance.Log("Unrecognized notification type");
                return;
            }
        }
Пример #11
0
        private async void handleNotificationReceived(object sender, AppNotificationMessage message)
        {
            try
            {
                LoggerService.Instance.Log("Cloud.handleNotificationReceived: Start notification processing");

                if (accountViewModel == null)
                {
                    LoggerService.Instance.Log("Cloud.handleNotificationReceived: Account is null. Exiting");
                    return;
                }

                if (!accountViewModel.SignedIn)
                {
                    LoggerService.Instance.Log("Cloud.handleNotificationReceived: Account not logged in. Trying to log in.");

                    var stored = accountViewModel.LoadUserFromCredentials();
                    if (stored == null)
                    {
                        LoggerService.Instance.Log("Cloud.handleNotificationReceived: Account stored credits are null.");
                        return;
                    }

                    if (string.IsNullOrEmpty(stored.AuthToken))
                    {
                        LoggerService.Instance.Log("Cloud.handleNotificationReceived: Account AuthToken is null.");
                        return;
                    }

                    var error = await accountViewModel.SignInWithTokenAsync(stored, false);

                    if (!string.IsNullOrEmpty(error))
                    {
                        LoggerService.Instance.Log("ERROR: Cloud.handleNotificationReceived: SignIn Error: " + error);
                    }

                    LoggerService.Instance.Log("Cloud.handleNotificationReceived: SignIn success");
                }

                switch (message.Type)
                {
                case AppNotificationType.DownloadComplete:
                case AppNotificationType.RecordingReady:
                case AppNotificationType.DownloadFailed:
                    await handleLocalRecordingsMessage(message);

                    break;

                case AppNotificationType.RecordingFailed:
                case AppNotificationType.DownloadExpiring:
                    await handleNotificationMessage(message);

                    break;

                case AppNotificationType.RemoteNotification:
                    LoggerService.Instance.Log("Cloud.handleNotificationReceived: Loading Notification item");
                    var notification = await NotificationClient.Get(message.ID, RemoteNotificationsService.Instance.GetTokenType(), RemoteNotificationsService.Instance.GetTokenValue());

                    if (notification == null)
                    {
                        LoggerService.Instance.Log("ERROR: Cloud.handleNotificationReceived: Cannot get notification " + message.ID + " from server");
                        return;
                    }

                    notification.LibraryItem = new LibraryItem()
                    {
                        ID     = notification.RecordingID,
                        Title  = notification.RecordQueueItem != null ? notification.RecordQueueItem.Title : string.Empty,
                        Series = notification.RecordQueueItem != null ? notification.RecordQueueItem.Series : string.Empty,
                    };

                    await handleRemoteNotification(notification);

                    break;
                }
            }
            catch (Exception ex)
            {
                LoggerService.Instance.Log("Error while processing notification: " + ex);
            }
            finally
            {
                message.WaitHandle?.SetResult(true);
            }
        }