예제 #1
0
        public void ShowTaskReminderNotification(TaskReminderNotification notification)
        {
            //we create the pending intent when the user clicks the notification...
            var action = new NotificationAction
            {
                Action     = NotificationActionType.OPEN_TASK,
                TaskId     = notification.TaskId,
                TaskListId = notification.TaskListId
            };
            var clickIntent = MainActivity.CreateIntent(
                notification.Id,
                MainActivity.InitParamsKey,
                JsonConvert.SerializeObject(action));

            var pendingIntent = TaskStackBuilder.Create(Application.Context)
                                .AddNextIntent(clickIntent)
                                .GetPendingIntent(1, (int)PendingIntentFlags.UpdateCurrent);

            var localNotification = new TaskNotification
            {
                LargeContent =
                    $"{notification.TaskTitle}{System.Environment.NewLine}" +
                    $"{notification.TaskBody}",
                Title = notification.TaskListTitle,
                Id    = notification.Id
            };
            var builder = BuildSimpleNotification(localNotification);

            builder.SetContentIntent(pendingIntent);

            //we create the pending intent when the user clicks the mark as completed button...
            var mcIntent = MarkTaskAsCompletedReceiver.CreateIntent(
                notification.Id,
                MarkTaskAsCompletedReceiver.MarkTaskAsCompletedKey,
                JsonConvert.SerializeObject(notification));

            var mcPendingIntent = PendingIntent.GetBroadcast(
                Application.Context,
                0,
                mcIntent,
                0);

            string title = _textProvider.Get("MarkTaskAs", _textProvider.Get("Completed"));

            builder.AddAction(Resource.Drawable.ic_check_white_48dp, title, mcPendingIntent);

            var notif = builder.Build();

            NotifManager.Notify(notification.Id, notif);
        }