Esempio n. 1
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);
        }
Esempio n. 2
0
        private static void SetNextNotification()
        {
            if (_settings == null)
            {
                return;
            }

            var timerIntent        = new Intent(Application.Context, typeof(MyNotificationManager));
            var timerPendingIntent = PendingIntent.GetBroadcast
                                         (Application.Context, NOTIFICATION_REQUEST_CODE, timerIntent, PendingIntentFlags.UpdateCurrent);
            var alarmManager         = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService);
            var notificationInterval = NotificationRandomnessService.GetNotificationIntervalMilliseconds(_settings.GenerationMinInterval, _settings.GenerationMaxInterval);

            if (NotificationRandomnessService.DoesIntervalLandInDoNotDisturb(notificationInterval, _settings.DoNotDisturbStartTime, _settings.DoNotDisturbStopTime))
            {
                notificationInterval += NotificationRandomnessService.GetDoNotDisturbLengthMilliseconds(_settings.DoNotDisturbStartTime, _settings.DoNotDisturbStopTime);
            }
            var alarmTimeMillis = SystemClock.ElapsedRealtime() + notificationInterval;

            alarmManager.SetExact(AlarmType.ElapsedRealtime, alarmTimeMillis, timerPendingIntent);
        }