public override void OnReceive(Context context, Intent intent)
 {
     if (_memories != null && _memories.Any())
     {
         var createNotificationIntent = new Intent(context, typeof(NotificationCreationService));
         createNotificationIntent.PutExtra(NOTIFICATION_TITLE_EXTRA, NotificationRandomnessService.GetNotificationTitle());
         createNotificationIntent.PutExtra(NOTIFICATION_TEXT_EXTRA, NotificationRandomnessService.GetRandomMemory(_memories).Description);
         context.StartService(createNotificationIntent);
     }
     SetNextNotification();
 }
示例#2
0
        private static void RestartNotificationQueue()
        {
            ClearExistingNotifications();
            if (_memories == null || !_memories.Any())
            {
                return;
            }
            if (_settings == null)
            {
                return;
            }

            const int IOS_NOTIFICATION_LIMIT = 64;
            double    runningIntervalTotal   = 0;

            for (var ii = 1; ii < IOS_NOTIFICATION_LIMIT - 1; ii++)
            {
                runningIntervalTotal += NotificationRandomnessService.GetNotificationIntervalMilliseconds(_settings.GenerationMinInterval, _settings.GenerationMaxInterval);
                if (NotificationRandomnessService.DoesIntervalLandInDoNotDisturb(runningIntervalTotal, _settings.DoNotDisturbStartTime, _settings.DoNotDisturbStopTime))
                {
                    runningIntervalTotal += NotificationRandomnessService.GetDoNotDisturbLengthMilliseconds(_settings.DoNotDisturbStartTime, _settings.DoNotDisturbStopTime);
                }
                var notification = new UILocalNotification
                {
                    FireDate   = NSDate.FromTimeIntervalSinceNow(runningIntervalTotal / 1000),
                    AlertTitle = NotificationRandomnessService.GetNotificationTitle(),
                    AlertBody  = NotificationRandomnessService.GetRandomMemory(_memories).Description,
                    SoundName  = UILocalNotification.DefaultSoundName
                };

                UIApplication.SharedApplication.ScheduleLocalNotification(notification);
            }

            var restartNotification = new UILocalNotification
            {
                FireDate       = NSDate.FromTimeIntervalSinceNow(runningIntervalTotal / 1000),
                AlertTitle     = "Notification limit reached",
                AlertBody      = "Cringebot has reached the iOS-imposed limit of 64 scheduled notifications. Please relaunch Cringebot or toggle the simulation setting to receive notifications again.",
                SoundName      = UILocalNotification.DefaultSoundName,
                RepeatInterval = NSCalendarUnit.Hour
            };

            UIApplication.SharedApplication.ScheduleLocalNotification(restartNotification);
        }