public override void OnReceive(Context context, Intent intent)
        {
            reminder = ReminderHelper.SelectReminder(context);
            if (reminder != null)
            {
                Intent newIntent = new Intent(context, typeof(ReminderContent));
                newIntent.PutExtra("reminder", JsonConvert.SerializeObject(reminder));

                //Add the next task to the stack
                Android.Support.V4.App.TaskStackBuilder stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(context);
                stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(ReminderContent)));
                stackBuilder.AddNextIntent(newIntent);

                // set the intent which will open when one click on notification
                PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(context).SetAutoCancel(true)
                                                     .SetDefaults((int)NotificationDefaults.All)
                                                     .SetContentIntent(resultPendingIntent).SetContentTitle("Reminder!!")
                                                     .SetSmallIcon(Resource.Drawable.notify_panel_notification_icon_bg).SetContentText("Click for details..")
                                                     .SetContentInfo("Start");
                NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                notificationManager.Notify(2, builder.Build());
            }
        }
Example #2
0
        private void switch_itemSelected(object sender, CompoundButton.CheckedChangeEventArgs e, Context context, int position)
        {
            AlarmManager manager  = (AlarmManager)context.GetSystemService(Context.AlarmService);
            Intent       myIntent = new Intent(context, typeof(ReminderNotification));

            if (e.IsChecked)
            {
                //set data
                var valuesForActivity = new Bundle();
                valuesForActivity.PutString("MESSAGE", riwayatReminder[position].Message);
                myIntent.PutExtras(valuesForActivity);

                DateTime       date            = riwayatReminder[position].Time;
                string         dateString      = $"{date.Month}/{date.Day}/{date.Year} {date.Hour}:{date.Minute}:{date.Second} {date.ToString("tt")}";
                DateTimeOffset dateOffsetValue = DateTimeOffset.Parse(dateString);
                var            millisec        = dateOffsetValue.ToUnixTimeMilliseconds();

                // set alarm
                PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, (int)millisec, myIntent, 0);
                manager.SetRepeating(AlarmType.Rtc, millisec, AlarmManager.IntervalDay, pendingIntent);
            }
            else
            {
                // cancel alarm
                PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, riwayatReminder[position].NotificationID, myIntent, 0);
                manager.Cancel(pendingIntent);
            }
            ReminderHelper.SwitchRiwayatReminder(riwayatReminder[position].Id, e.IsChecked);
        }
Example #3
0
        public void verify_adds_reminder_if_project_is_configured_with_reminders()
        {
            RavenSession.Store(new Project {
                Owner = "users/99", Title = "Project98", Id = "projects/98", MaxNoteIntervalInDaysBeforeReminder = 7, Description = "Description text"
            });
            RavenSession.SaveChanges();
            var target = NoteService.CreateNoteService(RavenSession, RavenSession.Load <User>("users/99"));

            target.RequestContext = new MockRequestContext2();

            var help = new ReminderHelper(RavenSession, templateRootPath);
            var a    = help.GetAllRemindersDueBefore(DateTime.Now);

            Assert.AreEqual(0, a.Count);

            target.OnPost(new Note {
                ProjectId = "projects/98", Text = "first on 98"
            });

            var n = RavenSession.Load <Note>("notes/1");

            Assert.AreEqual(n.ProjectId, "projects/98");


            var r = RavenSession.Load <Reminder>("reminders/1");

            Assert.AreEqual(r.ProjectId, "projects/98");
            Assert.AreEqual(r.Due.ToShortDateString(), DateTime.Now.AddDays(7).ToShortDateString());


            //a = (new ReminderHelper(RavenSession)).GetAllRemindersDueBefore(DateTime.Now.AddDays(9));
            //Assert.AreEqual(1, a.Count);
        }
Example #4
0
        private async void RefreshData()
        {
            await Task.Delay(TimeSpan.FromSeconds(0.3));

            riwayatReminder = ReminderHelper.GetReminderList();
            NotifyDataSetChanged();
        }
Example #5
0
        public void DeleteAll()
        {
            foreach (TaskModel task in Tasks.ToList())
            {
                Delete(task);
            }

            // Odstranění "zapomenutých" připoměnutí
            ReminderHelper.RemoveAll();
        }
Example #6
0
        //
        // GET: /Scheduler/

        public ActionResult Index()
        {
            var schedule = RavenSession.Load <ScheduleSettings>("scheduleSettings/1");
            var data     = new List <EmailReminderData>();

            int delayHours = 4;

            if (schedule == null)
            {
                schedule = new ScheduleSettings {
                    Id = "scheduleSettings/1"
                }; RavenSession.Store(schedule); ViewBag.Message = "This is the first run!";
                ViewBag.Error = "First run, creating session";
                return(View());
            }


            if ((DateTime.Now - schedule.LastRun).TotalHours > delayHours)
            {
                try
                {
                    var logic = new ReminderHelper(RavenSession, Server.MapPath("/Views/Templates/"));

                    var reminders = logic.GetAllRemindersDueBefore(DateTime.Now);
                    var msgs      = logic.ComposeMessages(reminders);
                    ViewBag.Messages = msgs;
                    var emails = logic.SendEmails(msgs);
                    ViewBag.SentMessages = emails;
                    logic.UpdateMsgCount(reminders);
                }
                catch (Exception ex)
                {
                    ViewBag.Error = ex.Message;
                }

                ViewBag.Message = "Last run: " + schedule.LastRun;

                if (data.Count > 0)
                {
                    string emailText = GetEmailText(data);
                    RavenSession.Store(new TempTextEmail {
                        Text = emailText
                    });
                }
                schedule.LastNumberOfNotifications = data.Count;
                schedule.LastRun = DateTime.Now;
                RavenSession.SaveChanges();
            }
            else
            {
                ViewBag.Error = "Scheduler will not run before" + (delayHours - (DateTime.Now - schedule.LastRun).TotalHours).ToString() + " hours";
            }
            return(View(data));
        }
Example #7
0
        protected override void OnResume()
        {
            base.OnResume();

            // fetch latest data
            List <RiwayatReminder> data = ReminderHelper.GetReminderList();

            // update data
            RecyclerView        rvRiwayatReminder = FindViewById <RecyclerView>(Resource.Id.rvRiwayatReminder);
            ReminderAdapter     mAdapter          = new ReminderAdapter(data);
            LinearLayoutManager mLayoutManager    = new LinearLayoutManager(this);

            rvRiwayatReminder.SetLayoutManager(mLayoutManager);
            rvRiwayatReminder.SetAdapter(mAdapter);
        }
Example #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ReminderContent);

            // Create your application here
            reminder = JsonConvert.DeserializeObject <Reminder>(Intent.GetStringExtra("reminder"));
            ReminderHelper.DeleteReminder(this, reminder);
            _txtNote        = FindViewById <TextView>(Resource.Id.txt_note);
            _txtNote.Text   = reminder.Note;
            _btnBack        = FindViewById <Button>(Resource.Id.btn_back);
            _btnBack.Click += (sender, e) => {
                StartActivity(new Intent(this, typeof(ListReminder)));
            };
        }
 private void BindData()
 {
     listitem = ReminderHelper.GetReminderList(this).ToArray();
     if (listitem.Length > 0)
     {
         adapter         = new GridReminder(this, listitem);
         list.Adapter    = adapter;
         list.ItemClick += List_ItemClick;
     }
     else
     {
         list.Visibility      = Android.Views.ViewStates.Invisible;
         _txtLabel.Visibility = Android.Views.ViewStates.Visible;
         _txtLabel.Text       = "No upcoming reminders!!";
     }
 }
Example #10
0
        public void verify_sends_email()
        {
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 20), RemindersSent = 0, LastNoteText = "Created 20.10", ProjectId = "projects/99"
            });
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 19), RemindersSent = 1, LastNoteText = "Created 19.10", ProjectId = "projects/99"
            });
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 18), RemindersSent = 2, LastNoteText = "Created 18.10", ProjectId = "projects/99"
            });
            RavenSession.SaveChanges();

            var target    = new ReminderHelper(RavenSession, templateRootPath);
            var reminders = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 20));
            var msgs      = target.ComposeMessages(reminders);
            // var emails = target.SendEmails(msgs);
        }
        private void List_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            AlertDialog alert = dialog.Create();

            alert.SetTitle("Delete");
            alert.SetMessage("Are you sure!");
            alert.SetIcon(Resource.Drawable.notification_template_icon_low_bg);
            alert.SetButton("yes", (c, ev) =>
            {
                reminder = listitem[e.Position];
                ReminderHelper.DeleteReminder(this, reminder);
                StartActivity(new Intent(this, typeof(DeleteReminder)));
                GC.Collect();
            });
            alert.SetButton2("no", (c, ev) => { });
            alert.Show();
        }
Example #12
0
        private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e, Context context, int position)
        {
            Spinner spinner = (Spinner)sender;

            if (e.Position == 0)
            {
                // edit
                Intent activityReminderSet = new Intent(context, typeof(ActivityReminderSet));

                // set data
                var valuesForActivity = new Bundle();
                valuesForActivity.PutString("MODE", "EDIT");
                valuesForActivity.PutInt("HOUR", riwayatReminder[position].Time.Hour);
                valuesForActivity.PutInt("MINUTE", riwayatReminder[position].Time.Minute);
                valuesForActivity.PutInt("ID", riwayatReminder[position].Id);
                valuesForActivity.PutInt("NOTIFICATIONID", riwayatReminder[position].NotificationID);
                valuesForActivity.PutString("MESSAGE", riwayatReminder[position].Message);

                // start activity with data
                activityReminderSet.PutExtras(valuesForActivity);
                context.StartActivity(activityReminderSet);
            }

            if (e.Position == 1 && riwayatReminder.Count > 0)
            {
                // delete - cancel
                AlarmManager  manager       = (AlarmManager)context.GetSystemService(Context.AlarmService);
                Intent        myIntent      = new Intent(context, typeof(ReminderNotification));
                PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, riwayatReminder[position].NotificationID, myIntent, 0);
                manager.Cancel(pendingIntent);

                // delete - db
                ReminderHelper.DeleteReminder(riwayatReminder[position].Id);

                // refresh data
                riwayatReminder.Clear();
                NotifyDataSetChanged();
                RefreshData();
                spinner.SetSelection(2);
            }
        }
Example #13
0
        public void verify_loads_reminders()
        {
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 20), RemindersSent = 0, LastNoteText = "Created 20.10", ProjectId = "projects/99"
            });
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 19), RemindersSent = 1, LastNoteText = "Created 19.10", ProjectId = "projects/99"
            });
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 18), RemindersSent = 2, LastNoteText = "Created 18.10", ProjectId = "projects/99"
            });
            RavenSession.SaveChanges();

            var target = new ReminderHelper(RavenSession, templateRootPath);
            var a      = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 17));

            Assert.AreEqual(0, a.Count);

            a = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 21));
            Assert.AreEqual(3, a.Count);
        }
Example #14
0
        private void createNotification(string message, DateTime date)
        {
            PendingIntent pendingIntent;
            AlarmManager  manager  = (AlarmManager)GetSystemService(Context.AlarmService);
            Intent        myIntent = new Intent(this, typeof(ReminderNotification));

            //bundling
            var valuesForActivity = new Bundle();

            valuesForActivity.PutString("MESSAGE", message);
            myIntent.PutExtras(valuesForActivity);

            //convert
            string         dateString      = $"{date.Month}/{date.Day}/{date.Year} {date.Hour}:{date.Minute}:{date.Second} {date.ToString("tt")}";
            DateTimeOffset dateOffsetValue = DateTimeOffset.Parse(dateString);
            var            millisec        = dateOffsetValue.ToUnixTimeMilliseconds();

            if (Mode == "EDIT")
            {
                Log.Debug("set", "edit");

                // cancel alarm
                pendingIntent = PendingIntent.GetBroadcast(this, NotificationId, myIntent, 0);
                manager.Cancel(pendingIntent);

                // set new alarm
                pendingIntent = PendingIntent.GetBroadcast(this, (int)millisec, myIntent, 0);
                manager.SetRepeating(AlarmType.Rtc, millisec, AlarmManager.IntervalDay, pendingIntent);
                ReminderHelper.UpdateRiwayatReminder(Id, (int)millisec, date, message, true);
            }
            else
            {
                Log.Debug("set", "add");
                pendingIntent = PendingIntent.GetBroadcast(this, (int)millisec, myIntent, 0);
                manager.SetRepeating(AlarmType.Rtc, millisec, AlarmManager.IntervalDay, pendingIntent);
                ReminderHelper.SaveRiwayatReminder((int)millisec, date, message);
            }
            Log.Debug("set", "ok");
            Finish();
        }
Example #15
0
        public void verify_increase_sentcount()
        {
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 20), RemindersSent = 0, LastNoteText = "Created 20.10", ProjectId = "projects/99"
            });
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 19), RemindersSent = 1, LastNoteText = "Created 19.10", ProjectId = "projects/99"
            });
            RavenSession.Store(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 18), RemindersSent = 2, LastNoteText = "Created 18.10", ProjectId = "projects/99"
            });
            RavenSession.SaveChanges();

            var target = new ReminderHelper(RavenSession, templateRootPath);
            var result = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 20));

            Assert.AreEqual(result.Count, 2);
            target.UpdateMsgCount(result);
            RavenSession.SaveChanges();
            result = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 20));
            Assert.AreEqual(result.Count, 1);
        }
Example #16
0
        public void verify_compose_message_with_all_reminders_for_one_users()
        {
            var reminders = new List <Reminder>();

            reminders.Add(new  Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 20), RemindersSent = 0, LastNoteText = "Created 20.10", ProjectId = "projects/99", ProjectTitle = "Project99"
            });
            reminders.Add(new Reminder {
                UserId = "users/98", Due = new DateTime(2012, 10, 19), RemindersSent = 0, LastNoteText = "Created 19.10", ProjectId = "projects/98", ProjectTitle = "Project99"
            });
            reminders.Add(new Reminder {
                UserId = "users/99", Due = new DateTime(2012, 10, 18), RemindersSent = 0, LastNoteText = "Created 18.10", ProjectId = "projects/99", ProjectTitle = "Project99"
            });

            var target = new ReminderHelper(RavenSession, templateRootPath);
            var result = target.ComposeMessages(reminders);

            Assert.AreEqual(result.Count, 2);
            Assert.AreEqual(result[0].Reminders.Count, 2);
            Assert.AreEqual(result[1].Reminders.Count, 1);
            Assert.IsTrue(result[0].HtmlBodyString.Contains("Project99"));
        }
Example #17
0
        void SaveRecords(Object sender, EventArgs eventArgs)
        {
            reminder.Note = _txtNote.Text;
            if (Vaidate())
            {
                DateTime currentDT  = DateTime.Now;
                DateTime selectedDT = Convert.ToDateTime(reminder.Date + " " + reminder.Time);

                // Reminder should not be applied on past date time
                if (selectedDT > currentDT)
                {
                    ReminderHelper.InsertReminderData(this, reminder);
                    ScheduleReminder(reminder);
                    var reminderAdded = new Intent(this, typeof(ReminderAdded));
                    reminderAdded.PutExtra("reminder", JsonConvert.SerializeObject(reminder));
                    StartActivity(reminderAdded);
                }
                else
                {
                    Toast.MakeText(this, "This is invalid selelction of Date, Time!", ToastLength.Short).Show();
                }
            }
        }