public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { if (isStarted) { foreach (var data in SQLLiteDB.ReadUserScheduleData()) { if (data.IsNotify == false && data.Time < DateTime.Now.AddMinutes(15)) { // CrossLocalNotifications.Current.Show(data.Message, DateTime.Now.ToString(), data.Id, DateTime.Now); var manager = (NotificationManager)GetSystemService(NotificationService); if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O) { var notification = new Notification.Builder(this, "DE") .SetContentTitle(DateTime.Now.ToString() + "알림!") .SetContentText(data.Message) .SetSmallIcon(Resource.Drawable.xamagonBlue) .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.xamagonBlue)) .SetSmallIcon(Resource.Drawable.xamagonBlue) .Build(); manager.Notify(data.Id, notification); } else { var notification = new Notification.Builder(this) .SetContentTitle(DateTime.Now.ToString() + "알림!") .SetContentText(data.Message) .SetSmallIcon(Resource.Drawable.xamagonBlue) .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.xamagonBlue)) .SetSmallIcon(Resource.Drawable.xamagonBlue) .Build(); manager.Notify(data.Id, notification); } //Notify update data.IsNotify = true; SQLLiteDB.Upsert(data, false); } } } else { RegisterForegroundService(); isStarted = true; } SQLLiteDB.InsertScheduleLog(DateTime.Now); AlarmReceiver.AddAlarmEvent(10); return(StartCommandResult.Sticky); }
private void UpdateCalendar(DateTime dateTime) { if (dateTime.Day != 1) { throw new ArgumentException($"{nameof(dateTime)}.Day is {dateTime.Day} but should be 1!"); } // Remove days CalendarGrid.Children.Clear(); // Update month and year label MonthLabel.Text = dateTime.ToString("MMMM"); YearLabel.Text = dateTime.Year.ToString(); // Add days var dayOfWeek = (int)dateTime.DayOfWeek - 1; // -1 to let the week start on Monday instead of Sunday if (dayOfWeek < 0) { dayOfWeek = 6; } var daysInMonth = DateTime.DaysInMonth(dateTime.Year, dateTime.Month) + 1; var row = 0; for (var day = 1; day < daysInMonth; day++) { var currentDay = dateTime.AddDays(day - 1); var isInRange = currentDay >= RangeFrom.Date && currentDay <= RangeUntil.Date; var dayButton = new Button { Text = day.ToString(), HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, BackgroundColor = Color.White, }; //오늘 버튼 표시 if (DateTime.Now.Year == currentDay.Year && DateTime.Now.Month == currentDay.Month && DateTime.Now.Day == currentDay.Day) { FocusButton = dayButton; FocusButton.BackgroundColor = Color.Red; } dayButton.Clicked += delegate { if (FocusButton != null) { FocusButton.BackgroundColor = Color.White; } FocusButton = dayButton; FocusButton.BackgroundColor = Color.Red; ScheduleGrid.IsVisible = true; ScheduleView.Clear(); SchedueListView.ItemsSource = scheduleView; foreach (var data in SQLLiteDB.ReadUserScheduleData()) { if (dateTime.Year == data.Time.Year && dateTime.Month == data.Time.Month && Convert.ToInt16(dayButton.Text) == data.Time.Day) { scheduleView.Add(new ScheduleViewItem { Display = Helper.DateTimeToShortTime(data.Time) + " " + data.Message, Id = data.Id }); } } }; if (_shouldShowRange && isInRange) { dayButton.BackgroundColor = Color.Red; } CalendarGrid.Children.Add(dayButton, dayOfWeek, row); dayOfWeek += 1; // Begin new row if (dayOfWeek > 6) { dayOfWeek = 0; row++; } } }