async void OnBtnSaveClicked(object sender, EventArgs e) { var viewModel = (AlarmClockDetailModel)BindingContext; if (string.IsNullOrEmpty(viewModel.Name)) { return; } var alarmTime = new DateTime(viewModel.SelectedDate.Year, viewModel.SelectedDate.Month, viewModel.SelectedDate.Day, viewModel.SelectedTime.Hours, viewModel.SelectedTime.Minutes, 0); var alarmClockInfo = new AlarmClockInfo { ID = viewModel.ID, Name = viewModel.Name, MusicName = viewModel.MusicName, MusicPath = viewModel.MusicPath, AlarmTime = alarmTime }; if (alarmClockInfo.ID < 1) { alarmClockInfo.CreatedDate = DateTime.UtcNow; } alarmClockInfo.LastUpdatedDate = DateTime.UtcNow; alarmClockInfo.IsEnable = true; await App.DbContext.SaveAlarmClockAsync(alarmClockInfo); await Navigation.PopAsync(); }
public async Task RunCounter(CancellationToken token) { AlarmClockInfo CurrentAlarmClockInfo = null; await Task.Run(async() => { while (true) { var alarmClockInfo = await App.DbContext.GetEnableAlarmClockAsync(); if (alarmClockInfo != null) { if (CurrentAlarmClockInfo != null && CurrentAlarmClockInfo.ID == alarmClockInfo.ID) { await Task.Delay(1000); continue; } CurrentAlarmClockInfo = alarmClockInfo; Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send <AlarmClockInfo>(alarmClockInfo, "AlarmClockInfoMessage"); }); } await Task.Delay(1000); } }, token); }
public async Task <int> SaveAlarmClockAsync(AlarmClockInfo model) { if (model.ID != 0) { return(await _database.UpdateAsync(model)); } else { return(await _database.InsertAsync(model)); } }
private async Task BindAsycn() { _alarmClockInfo = (AlarmClockInfo)BindingContext; BindingContext = new ShowAlarmClockModel { Name = _alarmClockInfo.Name, SelectedTime = _alarmClockInfo.AlarmTime.ToString("HH:mm") }; if (!string.IsNullOrEmpty(_alarmClockInfo.MusicPath)) { await CrossMediaManager.Current.Play(_alarmClockInfo.MusicPath); } }
void IAlarmAndNotificationService.ScheduleLocalNotification(string notificationTitle, string notificationMessage, DateTime specificDateTime, TimeSpan timeSpan, int notificationId, NotificationInterval interval) { DateTime utcDateTime = new DateTime(specificDateTime.Ticks + timeSpan.Ticks).ToUniversalTime(); Java.Util.Date nativeDate = DateTimeToNativeDate(utcDateTime); Intent alarmReciver = new Intent(Forms.Context, typeof(AlarmReceiver)); alarmReciver.PutExtra("Title", notificationTitle); alarmReciver.PutExtra("Message", notificationMessage); alarmReciver.PutExtra("NotificationId", notificationId); alarmReciver.PutExtra("Time", (specificDateTime + timeSpan).ToString()); alarmReciver.PutExtra("Interval", interval.ToString()); System.Diagnostics.Debug.WriteLine($"Schedule LocalNotification : for time : {nativeDate.ToString()}"); PendingIntent pendingIntent = PendingIntent.GetBroadcast(Forms.Context, notificationId, alarmReciver, PendingIntentFlags.CancelCurrent); AlarmClockInfo alarmClockInfo = new AlarmClockInfo(nativeDate.Time, pendingIntent); var alarmManager = (AlarmManager)Android.App.Application.Context.GetSystemService(Context.AlarmService); if (interval == NotificationInterval.Day) { alarmManager.SetRepeating(AlarmType.RtcWakeup, nativeDate.Time, IntervalDay, pendingIntent); } else if (interval == NotificationInterval.Hours) { alarmManager.SetRepeating(AlarmType.RtcWakeup, nativeDate.Time, IntervalHour, pendingIntent); } else if (interval == NotificationInterval.Week) { alarmManager.SetRepeating(AlarmType.RtcWakeup, nativeDate.Time, IntervalDay * 7, pendingIntent); } else if (interval == NotificationInterval.None) { alarmManager.Set(AlarmType.RtcWakeup, nativeDate.Time, pendingIntent); } }
public void SetSeasonAlarmClock(TDCEnum.EGameSeason s, Action complete, bool repeat = false) { var alarm = new AlarmClockInfo (); alarm.SetAlarmSeason (s); alarm.Callback = complete; alarm.Repeat = repeat; m_AlarmClocks.Add (alarm); }
public void SetHourAlarmClock(int h, Action complete, bool repeat = false) { var alarm = new AlarmClockInfo (); alarm.SetAlarmHour (h); alarm.Callback = complete; alarm.Repeat = repeat; m_AlarmClocks.Add (alarm); }
public void SetDayAlarmClock(int d, Action complete) { var alarm = new AlarmClockInfo (); alarm.SetAlarmDay (d); alarm.Callback = complete; alarm.Repeat = false; m_AlarmClocks.Add (alarm); }
public async Task <int> DeleteAlarmClockAsync(AlarmClockInfo model) { return(await _database.DeleteAsync(model)); }