Beispiel #1
0
        public override void OnReceive(Context context, Intent intent)
        {
            NotificationType  type = (NotificationType)intent.GetIntExtra("type", 0);
            NotificationsEnum data = (NotificationsEnum)intent.GetIntExtra("data", 0);

            switch (type)
            {
            case NotificationType.Local:
                GenerateLocalNotificationBroadcasted(context, data.Data(), 0);
                break;

            case NotificationType.Permissions:
                GenerateLocalPermissionsNotificationBroadcasted(context, data.Data());
                break;

            case NotificationType.InBackground:
                GenerateLocalNotificationOnlyIfInBackgroundBroadcasted(context, data.Data());
                break;

            case NotificationType.ForegroundWithUpdates:
                long ticks = intent.GetLongExtra("ticks", 0);
                GenerateForegroundServiceNotificationWithUpdatesBroadcasted(
                    context, data.Data(), ticks);
                break;

            default:
                return;
            }
        }
Beispiel #2
0
 private string SelectChannel(NotificationsEnum type)
 {
     return(type switch
     {
         NotificationsEnum.NewMessageReceived => _exposureChannelId,
         NotificationsEnum.BackgroundFetch => _backgroundFetchChannelId,
         NotificationsEnum.TimedReminder => _countdownChannelId,
         NotificationsEnum.TimedReminderFinished => _reminderChannelId,
         _ => _permissionsChannelId
     });
Beispiel #3
0
        public static NotificationViewModel Data(this NotificationsEnum notificationType)
        {
            switch (notificationType)
            {
            case NotificationsEnum.NewMessageReceived:
                return(new NotificationViewModel
                {
                    Type = NotificationsEnum.NewMessageReceived,
                    Title = "NOTIFICATION_HEADER".Translate(),
                    Body = "NOTIFICATION_DESCRIPTION".Translate()
                });

            case NotificationsEnum.ApiDeprecated:
                return(new NotificationViewModel
                {
                    Type = NotificationsEnum.ApiDeprecated,
                    Title = "NOTIFICATION_UPDATE_HEADER".Translate(),
                    Body = (ServiceLocator.Current.GetInstance <IDeviceInfo>().Platform == DevicePlatform.iOS ?
                            "NOTIFICATION_iOS_UPDATE_DESCRIPTION" :
                            "NOTIFICATION_ANDROID_UPDATE_DESCRIPTION").Translate()
                });

            case NotificationsEnum.ConsentNeeded:
                return(new NotificationViewModel
                {
                    Type = NotificationsEnum.ConsentNeeded,
                    Title = "NOTIFICATION_UPDATE_HEADER".Translate(),
                    Body = "NOTIFICATION_CONSENT_DESCRIPTION".Translate()
                });

            case NotificationsEnum.ReApproveConsents:
                return(new NotificationViewModel
                {
                    Type = NotificationsEnum.ReApproveConsents,
                    Title = "NOTIFICATION_CONSENT_HEADER".Translate(),
                    Body = "NOTIFICATION_CONSENT_DESCRIPTION".Translate()
                });

            case NotificationsEnum.BackgroundFetch:
                return(new NotificationViewModel
                {
                    Type = NotificationsEnum.BackgroundFetch,
                    Title = "NOTIFICATION_BACKGROUND_FETCH_HEADER".Translate(),
                    Body = "NOTIFICATION_BACKGROUND_FETCH_DESCRIPTION".Translate()
                });

            default:
                throw new InvalidEnumArgumentException("Notification type does not exist");
            }
        }
Beispiel #4
0
 public static void CreateNotificationOnlyIfInBackground(NotificationsEnum notificationType)
 {
     LocalNotificationsManager.GenerateLocalNotificationOnlyIfInBackground(notificationType.Data());
 }
Beispiel #5
0
 public static void CreateNotification(NotificationsEnum notificationType, int triggerInSeconds)
 {
     LocalNotificationsManager.GenerateLocalNotification(notificationType.Data(), triggerInSeconds);
 }
        public void PermissionsNotificationIsGenerated(bool hasBluetooth, bool hasLocation, NotificationsEnum type)
        {
            ResetData();
            LocalNotificationsManager.HasBeenCalled[type] = false;
            LocalNotificationsManager.HasBeenCalled[NotificationsEnum.NoNotification] = false;
            try
            {
                new FetchExposureKeysHelper()
                .FetchExposureKeyBatchFilesFromServerAsync(
                    null,
                    CancellationToken.None)
                .GetAwaiter()
                .GetResult();
            }
            catch (Exception)
            {
                // ignore
            }

            Assert.True(
                !LocalNotificationsManager.HasBeenCalled[NotificationsEnum.NoNotification] ||
                LocalNotificationsManager.HasBeenCalled[type]);
        }