Пример #1
0
        public static void UpdateAlarm(AlarmRecord record)
        {
            var obj = record;

            // Update native alarm
            DependencyService.Get <IAlarm>().UpdateAlarm(ref obj);
            record = obj;
            string alarmUID = record.GetUniqueIdentifier();

            // Update list
            for (int i = 0; i < ObservableAlarmList.Count; i++)
            {
                AlarmRecord item = ObservableAlarmList[i];
                //AlarmModel.Compare(record, item);
                if (item.GetUniqueIdentifier() == alarmUID)
                {
                    DependencyService.Get <ILog>().Debug("  Found AlarmRecord(UID: " + item.GetUniqueIdentifier() + ") in ObservableAlarmList.");
                    AlarmRecordDictionary.Remove(alarmUID);
                    item.DeepCopy(record);
                    AlarmRecordDictionary.Add(alarmUID, item);
                    SaveDictionary();
                    break;
                }
            }
        }
Пример #2
0
        public static void ReactivatelAlarm(AlarmRecord record)
        {
            //1. register native alarm
            int NativeAlarmID = DependencyService.Get <IAlarm>().CreateAlarm(record);
            //2. Update NativeAlarmID and AlarmState
            string UID = record.GetUniqueIdentifier();

            UpdateDictionaryAndList(UID, NativeAlarmID, true);
        }
Пример #3
0
        public static void DeactivatelAlarm(AlarmRecord record)
        {
            //1. cancel native alarm
            DependencyService.Get <IAlarm>().DeleteAlarm(record);
            //2. Make AlarmRecord's AlarmState
            string UID = record.GetUniqueIdentifier();

            UpdateDictionaryAndList(UID, 0, false);
        }
Пример #4
0
        /// <summary>
        /// Create native alarm
        /// </summary>
        public static void CreateAlarmAndSave()
        {
            // create a native alarm using AlarmModel.BindableAlarmRecord
            // After then, update Native alarm ID.
            BindableAlarmRecord.NativeAlarmID = DependencyService.Get <IAlarm>().CreateAlarm(BindableAlarmRecord);
            DependencyService.Get <ILog>().Debug("====== AlarmModel.CreateAlarm >> BindableAlarmRecord.NativeAlarmID : " + BindableAlarmRecord.NativeAlarmID);
            // ObservableAlarmList is ItemsSource for AlarmList view. This is bindable so this model
            // should be changed to reflect record change (adding a new alarm)

            AlarmRecord record = new AlarmRecord();

            record.DeepCopy(BindableAlarmRecord);
            //AlarmModel.Compare(BindableAlarmRecord, record);

            ObservableAlarmList.Add(record);
            AlarmRecordDictionary.Add(record.GetUniqueIdentifier(), record);
            SaveDictionary();
        }
Пример #5
0
        /// <summary>
        /// Called when "DELETE" button is pressed in title bar of alarm Delete Page.
        ///  - Remove selected data items from list
        ///  - Go back to the previous page(alarm main page)
        /// </summary>
        /// <param name="sender">Titlebar's RightButton(DELETE button)</param>
        /// <param name="e">System.EventArgs</param>
        private void TitleBar_RightDeleteButton_Clicked(object sender, System.EventArgs e)
        {
            for (int i = AlarmModel.ObservableAlarmList.Count - 1; i >= 0; i--)
            {
                // check if it is checked to remove
                if (AlarmModel.ObservableAlarmList[i].Delete)
                {
                    AlarmRecord record = AlarmModel.ObservableAlarmList[i];
                    //var obj = record;
                    DependencyService.Get <IAlarm>().DeleteAlarm(record);
                    // Since it has been removed in the native alarm list, remove from alarm record dictionary also
                    AlarmModel.AlarmRecordDictionary.Remove(record.GetUniqueIdentifier());
                    // remove it from list
                    AlarmModel.ObservableAlarmList.RemoveAt(i);
                }
            }

            AlarmModel.SaveDictionary();
            // Go back to alarm Main Page from alarm Delete Page.
            Navigation.PopAsync();
        }
Пример #6
0
        /// <summary>
        /// Cancel native alarm
        /// and then remove AlarmRecord from ObservableAlarmList and AlarmRecordDictionary
        /// </summary>
        /// <param name="alarm">AlarmRecord</param>
        public static void DeleteAlarm(AlarmRecord alarm)
        {
            DependencyService.Get <ILog>().Debug("======[START]  AlarmModel.DeleteAlarm >> " + alarm);
            // Cancel the native alarm
            DependencyService.Get <IAlarm>().DeleteAlarm(alarm);
            string UID = alarm.GetUniqueIdentifier();

            // Delete alarm from dictionary
            AlarmModel.AlarmRecordDictionary.Remove(UID);
            // Delete alarm from List
            for (int i = AlarmModel.ObservableAlarmList.Count - 1; i >= 0; i--)
            {
                if (AlarmModel.ObservableAlarmList[i].GetUniqueIdentifier() == UID)
                {
                    ObservableAlarmList.RemoveAt(i);
                    break;
                }
            }
            // Save
            AlarmModel.SaveDictionary();
            DependencyService.Get <ILog>().Debug("======[END]   AlarmModel.DeleteAlarm >> " + alarm);
        }
Пример #7
0
        private static void UpdateDictionaryAndList(string UID, int NativeAlarmID, bool active)
        {
            for (int i = 0; i < AlarmModel.ObservableAlarmList.Count; i++)
            {
                AlarmRecord item = AlarmModel.ObservableAlarmList[i];
                if (item.GetUniqueIdentifier() == UID)
                {
                    AlarmModel.AlarmRecordDictionary.Remove(UID);
                    item.NativeAlarmID = NativeAlarmID;
                    if (active)
                    {
                        item.AlarmState = AlarmStates.Active;
                    }
                    else
                    {
                        item.AlarmState = AlarmStates.Inactive;
                    }

                    AlarmModel.AlarmRecordDictionary.Add(UID, item);
                    AlarmModel.SaveDictionary();
                    break;
                }
            }
        }
Пример #8
0
        // When button clicked, need to do followings:
        // 1. check time set by users
        // 2. convert TimeSpan to DateTime (since epoc time)
        // 3. get alarm name
        // 4. get alarm key (creation date which identify alarm uniquely)
        // 5. save a new record or update existing alarm.
        /// <summary>
        /// Invoked when "DONE" button is clicked
        /// </summary>
        /// <param name="sender">Titlebar's right button(DONE button)</param>
        /// <param name="e">EventArgs</param>
        private void DONE_Clicked(object sender, EventArgs e)
        {
            // Get time from TimePicker
            TimeSpan ts  = editTimePickerCell.Time;
            DateTime now = System.DateTime.Now;

            AlarmModel.BindableAlarmRecord.ScheduledDateTime = new System.DateTime(now.Year, now.Month, now.Day, ts.Hours, ts.Minutes, 0);
            // Get name from Entry
            AlarmModel.BindableAlarmRecord.AlarmName         = ((AlarmEditName)nameCell.View).mainEntry.Text;
            AlarmModel.BindableAlarmRecord.WeekdayRepeatText = AlarmModel.BindableAlarmRecord.GetFormatted(AlarmModel.BindableAlarmRecord.WeekFlag, AlarmModel.BindableAlarmRecord.AlarmState < AlarmStates.Inactive ? true : false);

            DependencyService.Get <ILog>().Debug("*** [START] [Clicked_SaveAlarm] BindableAlarmRecord : " + AlarmModel.BindableAlarmRecord);
            AlarmModel.BindableAlarmRecord.PrintProperty();

            AlarmRecord duplicate      = new AlarmRecord();
            bool        existSameAlarm = CheckAlarmExist(ref duplicate);

            if (existSameAlarm)
            {
                DependencyService.Get <ILog>().Debug("[Clicked_SaveAlarm] SAME ALARM EXISTS!!!!  duplicate : " + duplicate);
                duplicate.PrintProperty();

                // Need to show information
                Toast.DisplayText("Alarm already set for " + AlarmModel.BindableAlarmRecord.ScheduledDateTime + " " + AlarmModel.BindableAlarmRecord.AlarmName + ".\r\n Existing alarm updated.");

                // Use alarm created date for unique identifier for an alarm record
                string alarmUID = AlarmModel.BindableAlarmRecord.GetUniqueIdentifier();

                if (!AlarmModel.BindableAlarmRecord.IsSerialized)
                {
                    // in case that AlarmEditPage is shown by clicking a FloatingButton
                    // when trying to create a system alarm and save it, find the same alarm
                    // expected behavior : update the previous one and do not create a new alarm
                    DependencyService.Get <ILog>().Debug("  case 1:   A new alarm will be not created. The existing alarm(duplicate) will be updated with new info.");
                    AlarmModel.BindableAlarmRecord.IsSerialized = true;
                    // Copy modified data to the existing alarm record except alarm UID & native UID
                    duplicate.DeepCopy(AlarmModel.BindableAlarmRecord, false);
                    // Update the existing alarm(duplicate)
                    AlarmModel.UpdateAlarm(duplicate);
                }
                else if (alarmUID.Equals(duplicate.GetUniqueIdentifier()))
                {
                    // in case that AlarmEditPage is shown by selecting an item of ListView in AlarmListPage
                    // At saving time, just update itself. (It doesn't affect other alarms)
                    DependencyService.Get <ILog>().Debug("  case 2:   duplicate == AlarmModel.BindableAlarmRecord. So, just update BindableAlarmRecord.");
                    AlarmModel.UpdateAlarm(AlarmModel.BindableAlarmRecord);
                }
                else
                {
                    // in case that AlarmEditPage is shown by selecting an item of ListView in AlarmListPage
                    // At saving time, the same alarm is found.
                    // In case that this alarm is not new, the existing alarm(duplicate) will be deleted and it will be updated.
                    DependencyService.Get <ILog>().Debug("  case 3:   delete duplicate and then update BindableAlarmRecord.");
                    // 1. delete duplicate alarm
                    AlarmModel.DeleteAlarm(duplicate);
                    // 2. update bindableAlarmRecord
                    AlarmModel.UpdateAlarm(AlarmModel.BindableAlarmRecord);
                }
            }
            else
            {
                DependencyService.Get <ILog>().Debug("NO SAME ALARM EXISTS!!!!");
                if (!AlarmModel.BindableAlarmRecord.IsSerialized)
                {
                    // In case that AlarmEditPage is shown by clicking FloatingButton
                    // There's no same alarm. So, just create a new alarm and add to list and dictionary.
                    DependencyService.Get <ILog>().Debug("  case 4:   just create an alarm");
                    AlarmModel.BindableAlarmRecord.IsSerialized = true;
                    AlarmModel.CreateAlarmAndSave();
                }
                else
                {
                    // in case that AlarmEditPage is shown by selecting an item of ListView in AlarmListPage
                    // There's no same alarm. So, just update itself.
                    DependencyService.Get <ILog>().Debug("  case 5:   just update itself");
                    AlarmModel.UpdateAlarm(AlarmModel.BindableAlarmRecord);
                }
            }

            AlarmModel.PrintAll("Move from AlarmEditPage to AlarmListPage");
            ((App)Application.Current).floatingButton.Show();
            Navigation.PopAsync();
        }