private static DateTime CalculateNextDate(Alarm alarm)
 {
     if (DaysOfWeek.GetHasADayBeenSelected(alarm.Days))
     {
         //return DateTime.Now.Date.AddDays(CalculateAddingDaysWhenHasDaysOfWeek(alarm));
         if (!alarm.IsGoOffPreAlarm)
         {
             return(DateTime.Now.Date.AddDays(CalculateAddingDaysWhenHasDaysOfWeek(alarm)));
         }
         else
         {
             return(DateTime.Now.Date.AddDays(CalculateAddingDaysWhenHasDaysOfWeekAndGoOffPreAlarm(alarm)));
         }
     }
     else
     {
         if (alarm.Time.Subtract(DateTime.Now.TimeOfDay).Ticks < 0 && alarm.Date == DateTime.Now.Date)
         {
             return(alarm.Date.AddDays(1));
         }
         else
         {
             return(alarm.Date);
         }
     }
 }
Пример #2
0
 private void TurnOffPreAlarm()
 {
     if (!DaysOfWeek.GetHasADayBeenSelected(alarm.Days))
     {
         alarm.IsActive = false;
         TurnOffAlarmByNotification(alarm);
     }
 }
Пример #3
0
        private void TurnOffLaterAlarm()
        {
            if (!DaysOfWeek.GetHasADayBeenSelected(alarm.Days))
            {
                Alarm.ChangeIsActive(alarm, false);
            }

            TurnOffLaterAlarmByNotification(alarm);
        }
Пример #4
0
        private async Task Save()
        {
            if (!string.IsNullOrEmpty(Name))
            {
                Name = Name.TrimStart().TrimEnd();
            }
            if (!string.IsNullOrEmpty(WakeUpText))
            {
                WakeUpText = WakeUpText.TrimStart().TrimEnd();
            }
            if (!string.IsNullOrEmpty(PackageName))
            {
                PackageName = PackageName.TrimStart().TrimEnd();
            }

            Alarm.TimeOffset = new DateTime(Date.Year, Date.Month, Date.Day, Time.Hours, Time.Minutes, 0);

            if (string.IsNullOrEmpty(Name))
            {
                await Application.Current.MainPage.DisplayAlert("", AppResources.ForgotAlarmName, AppResources.OK);
            }
            else if (Alarm.TimeOffset.Subtract(DateTime.Now).Ticks < 0 && !DaysOfWeek.GetHasADayBeenSelected(Alarm.Days))
            {
                await Application.Current.MainPage.DisplayAlert("", AppResources.SetTimePast, AppResources.OK);
            }
            else if (string.IsNullOrEmpty(WakeUpText) && Alarm.HasWakeUpText)
            {
                await Application.Current.MainPage.DisplayAlert("", AppResources.ForgotWordsThatWakeMeUp, AppResources.OK);
            }
            else if (string.IsNullOrEmpty(PackageName) && Alarm.IsLinkOtherApp)
            {
                await Application.Current.MainPage.DisplayAlert("", AppResources.ForgotLinkOtherApps, AppResources.OK);
            }
            else
            {
                if (!Alarm.IsActive)
                {
                    Alarm.ChangeIsActive(Alarm, true);
                }
                Alarm.IsLaterAlarm    = false;
                Alarm.IsGoOffPreAlarm = false;

                var id = Service.SaveAlarm(Alarm);

                if (Preferences.Get("MaxAlarmId", 3) < id)
                {
                    Preferences.Set("MaxAlarmId", id);
                }

                await ClosePopup();

                var diffString = CreateDateString.CreateTimeRemainingString(Alarm.NextAlarmTime);
                DependencyService.Get <IToastService>().Show(diffString);
            }
        }
Пример #5
0
        protected override bool ValidateFields()
        {
            var s          = base.ValidateFields();
            var validation = true;

            if (!DaysOfWeek.GetHasADayBeenSelected(Days))
            {
                HasDayBeenSelected = false;
                validation         = false;
            }

            return(s & validation);
        }
Пример #6
0
        public static void SetRepeatAlarm(Routine routine)
        {
            long diffMillis = 0;

            if (DaysOfWeek.GetHasADayBeenSelected(routine.Days))
            {
                diffMillis = CalculateTimeDiff(routine);
            }

            if (diffMillis != 0)
            {
                SetAlarmByManager(routine, diffMillis);
            }
        }
Пример #7
0
        public static string CreateDateToString(Alarm alarm)
        {
            if (alarm.IsLaterAlarm)
            {
                return(AppResources.RingingSoon);
            }

            if (DaysOfWeek.GetHasADayBeenSelected(alarm.Days))
            {
                return(ConvertDaysOfWeekToString(alarm));
            }

            return(ConvertDateToString(alarm.Date));
        }
Пример #8
0
        public static void SetRepeatAlarm(Alarm alarm)
        {
            long diffMillis = 0;

            if (DaysOfWeek.GetHasADayBeenSelected(alarm.Days))
            {
                diffMillis = CalculateTimeDiffForRepeatAlarm(alarm);
            }

            if (diffMillis != 0)
            {
                SetAlarmByManager(alarm, diffMillis);
            }

            SetNotifiyPreAlarm(alarm, diffMillis);
        }
Пример #9
0
        private async Task Save()
        {
            Name = Name.TrimStart().TrimEnd();

            if (string.IsNullOrEmpty(Name))
            {
                await Application.Current.MainPage.DisplayAlert("", StringResources.ForgotRoutineName, StringResources.OK);
            }
            else if (!DaysOfWeek.GetHasADayBeenSelected(Routine.Days))
            {
                await Application.Current.MainPage.DisplayAlert("", StringResources.ForgotRoutineDays, StringResources.OK);
            }
            else if (HasNoHabit)
            {
                await Application.Current.MainPage.DisplayAlert("", StringResources.ForgotHabit, StringResources.OK);
            }
            else
            {
                if (Routine.Id == 0)
                {
                    Routine.Index = App.RoutineService.Routines.Count;
                }
                var id = App.RoutineService.SaveRoutine(Routine);

                foreach (var habit in Habits)
                {
                    habit.RoutineId = id;
                }
                App.HabitService.SaveHabits(Habits);

                foreach (var habit in HabitsForDelete)
                {
                    if (habit.Id != 0)
                    {
                        App.HabitService.DeleteHabit(habit.Id);
                    }
                }

                await ClosePopup();

                var diffString = CreateTimeToString.CreateTimeRemainingString(Routine.NextAlarmTime);
                DependencyService.Get <IToastService>().Show(diffString);
            }
        }
Пример #10
0
        private static Bundle GetAlarmBundle(Alarm alarm)
        {
            var bundle = new Bundle();

            bundle.PutInt("id", alarm.Id);
            bundle.PutString("name", alarm.Name);
            bundle.PutBoolean("IsAlarmOn", alarm.IsAlarmOn);
            bundle.PutBoolean("IsVibrateOn", alarm.IsVibrateOn);
            bundle.PutBoolean("IsVoiceRecognition", alarm.IsVoiceRecognition);
            bundle.PutBoolean("IsNotDelayAlarm", alarm.IsNotDelayAlarm);
            bundle.PutBoolean("IsFiveCount", alarm.IsFiveCount);
            bundle.PutBoolean("IsGoOffPreAlarm", alarm.IsGoOffPreAlarm);
            bundle.PutBoolean("IsTurnOffPreAlarm", alarm.IsTurnOffPreAlarm);
            bundle.PutBoolean("HasWakeUpText", alarm.HasWakeUpText);
            bundle.PutString("WakeUpText", alarm.WakeUpText);
            bundle.PutBoolean("IsLinkOtherApp", alarm.IsLinkOtherApp);
            bundle.PutString("PackageName", alarm.PackageName);
            bundle.PutBoolean("IsRepeating", DaysOfWeek.GetHasADayBeenSelected(alarm.Days));
            bundle.PutString("toneName", alarm.Tone);
            bundle.PutInt("alarmVolume", alarm.Volume);

            return(bundle);
        }