/// <summary>
 /// Initializes a new instance of the <see cref="AlarmEditPage"/> class.
 /// </summary>
 /// <param name="alarmRecordData">AlarmRecord</param>
 public AlarmEditPage(AlarmRecord alarmRecordData)
 {
     // Keep the initial Alarm Record
     originalRecord = alarmRecordData;
     BindingContext = AlarmModel.BindableAlarmRecord;
     Draw();
 }
Exemple #2
0
        /// <summary>
        /// Deep copy alarm record
        /// </summary>
        /// <param name="bindableAlarmRecord">Alarm record to deep copy</param>
        /// <seealso cref="AlarmRecord">
        public void DeepCopy(AlarmRecord Record, bool includeUID = true)
        {
            // All properties should be copied to this alarm record object
            IsSerialized      = Record.IsSerialized;
            ScheduledDateTime = Record.ScheduledDateTime;
            AlarmDateFormat   = Record.AlarmDateFormat;
            Repeat            = Record.Repeat;
            WeekFlag          = Record.WeekFlag;
            WeekdayRepeatText = Record.WeekdayRepeatText;
            AlarmType         = Record.AlarmType;
            Volume            = Record.Volume;
            IsMute            = Record.IsMute;
            AlarmToneType     = Record.AlarmToneType;
            Snooze            = Record.Snooze;
            AlarmState        = Record.AlarmState;
            AlarmName         = Record.AlarmName;
            if (includeUID)
            {
                DateCreated   = Record.DateCreated;
                NativeAlarmID = Record.NativeAlarmID;
            }

            Delete             = Record.Delete;
            IsVisibleDateLabel = Record.IsVisibleDateLabel;
        }
Exemple #3
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;
                }
            }
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
 /// <summary>
 /// Update the row based on newly changed week flag
 /// </summary>
 /// <param name="alarmData">The alarm record to update alarm week flag</param>
 /// <seealso cref="AlarmRecord">
 /// <param name="changed">The changed alarm week flag</param>
 /// <seealso cref="AlarmWeekFlag">
 /// <param name="value">This input is currently not used but defined for future use</param>
 private void Update(AlarmRecord alarmData, AlarmWeekFlag changed, bool value)
 {
     if (value)
     {
         AlarmModel.BindableAlarmRecord.WeekFlag = alarmData.WeekFlag | changed;
     }
     else
     {
         AlarmModel.BindableAlarmRecord.WeekFlag = alarmData.WeekFlag & ~changed;
     }
 }
        /// <summary>
        /// This method is called when this page is showing up.
        /// </summary>
        /// <param name="alarmRecordData">The alarm record to show on this page. If a new one, default alarm record is passed.</param>
        internal void Update(AlarmRecord alarmRecordData)
        {
            originalRecord = alarmRecordData;
            BindingContext = AlarmModel.BindableAlarmRecord;

            // Update the Text of TitleLabel
            titleBar.TitleLabel.Text = AlarmModel.BindableAlarmRecord.IsSerialized ? "Edit" : "Create";
            // Update the Time of TimePicker
            editTimePickerCell.Time = AlarmModel.BindableAlarmRecord.ScheduledDateTime.TimeOfDay;
            // Update the Text of Entry for alarm name
            ((AlarmEditName)(nameCell.View)).mainEntry.Text = AlarmModel.BindableAlarmRecord.AlarmName;
        }
        /// <summary>
        /// Construct alarm name row UI
        /// </summary>
        /// <param name="recod">AlarmRecord</param>
        /// <seealso cref="AlarmRecord">
        public AlarmEditName(AlarmRecord recod)
        {
            /// Fills horizontally
            HorizontalOptions = LayoutOptions.FillAndExpand;
            /// Fills vertically
            VerticalOptions = LayoutOptions.Start;
            HeightRequest   = 198;

            if (mainLabel == null)
            {
                mainLabel = new Label
                {
                    WidthRequest  = 720 - 32 * 2,
                    HeightRequest = 54,
                    Text          = "Alarm Name",
                    Style         = AlarmStyle.T023,
                };
                // to meet To meet thin attribute for font, need to use custom feature
                FontFormat.SetFontWeight(mainLabel, FontWeight.Light);
            }

            /// Adds main label
            Children.Add(mainLabel,
                         Constraint.RelativeToParent((parent) => { return(32); }),
                         Constraint.RelativeToParent((parent) => { return(24); }));
            /// Creates entry
            mainEntry = new Entry()
            {
                WidthRequest  = 720 - (32 + 10) * 2,
                HeightRequest = 54,
                Text          = recod.AlarmName,
            };
            mainEntry.SetBinding(Entry.TextProperty, new Binding("AlarmName", BindingMode.Default, source: recod));

            /// Checks whether already set alarm name
            if (string.IsNullOrEmpty(AlarmModel.BindableAlarmRecord.AlarmName))
            {
                mainEntry.Placeholder = "Alarm";
            }
            else
            {
                mainEntry.Text = AlarmModel.BindableAlarmRecord.AlarmName;
            }

            /// Sets font size (DP base)
            mainEntry.FontSize = CommonStyle.GetDp(40);
            /// Adds to layout
            Children.Add(mainEntry,
                         Constraint.RelativeToView(mainLabel, (parent, sibling) => { return(sibling.X + 10); }),
                         Constraint.RelativeToView(mainLabel, (parent, sibling) => { return(sibling.Y + sibling.Height + 33); }));
        }
Exemple #9
0
        /// <summary>
        /// Called when a data item is selected or unselected
        /// </summary>
        /// <param name="sender">ListView's data item</param>
        /// <param name="e">SelectedItemChangedEventArgs</param>
        private void AlarmDeleteListview_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return;
            }

            AlarmRecord item = (AlarmRecord)e.SelectedItem;

            item.Delete = !item.Delete;

            // make it deselected
            ((ListView)sender).SelectedItem = null;
        }
Exemple #10
0
        /// <summary>
        /// Constructor for Alarm list ui class
        /// </summary>
        public AlarmListUI()
        {
            /// Creates alarm custom cell template based on AlarmListCell
            var customCell = new DataTemplate(typeof(AlarmListCell));

            /// AlarmList view property setting
            alarmListView = new ListView
            {
                /// Sets vertical option to fill
                VerticalOptions = LayoutOptions.FillAndExpand,
                /// All rows are in even size
                HasUnevenRows = false,
                /// Sets item source by Observable alarm list
                ItemsSource = AlarmModel.ObservableAlarmList,
                /// Sets template to customCell object
                ItemTemplate = customCell
            };

            /// Command to trigger page push (AlarmEditPage)
            Command = new Command(async(o) =>
            {
                /// Needs to await for page push
                await Navigation.PushAsync(AlarmPageController.GetInstance(AlarmPages.EditPage, o));
            });

            /// When an item is selected, execute a command if command is set.
            alarmListView.ItemSelected += (s, e) =>
            {
                /// skips for no selected item case
                if (e.SelectedItem == null)
                {
                    // Todo: handle deselect case
                    return;
                }

                /// checks selected item
                AlarmRecord alarm = e.SelectedItem as AlarmRecord;
                /// Deselects first
                ((ListView)s).SelectedItem = null; // de-select the row
                /// Executes commands if it has beens set.
                if (Command != null && Command.CanExecute(null))
                {
                    Command.Execute(alarm);
                }
            };

            /// Adds alarmListView to this StackLayout
            Children.Add(alarmListView);
        }
        /// <summary>
        /// Called when the floating button has been clicked
        /// Show a page for editing an alarm
        /// When the floating button is clicked (new alarm request), new alarm will be created and call
        /// Alarm Edit Page with the created alarm record
        /// </summary>
        /// <param name="sender">floating button object</param>
        /// <seealso cref="System.object">
        /// <param name="e">Event argument for event of floating button.</param>
        /// <seealso cref="System.EventArgs">
        public void OnFloatingButtonClicked(object sender, EventArgs e)
        {
            if (AlarmModel.ObservableAlarmList.Count >= MAX_ITEMS_LIMIT)
            {
                Toast.DisplayText("Maximum number of alarms(" + MAX_ITEMS_LIMIT + ") reached.");
                return;
            }

            /// Creates default alarm record
            AlarmRecord defaultAlarmRecord = new AlarmRecord();

            defaultAlarmRecord.SetDefault();
            /// Call via alarm page controller which instantiates page once
            Navigation.PushAsync(AlarmPageController.GetInstance(AlarmPages.EditPage, defaultAlarmRecord), false);
        }
 /// <summary>
 /// Determines whether ObservableAlarmList contains an alarm which is scheduled at the same time and has the same alarm name.
 /// </summary>
 /// <param name="duplicate">AlarmRecord</param>
 /// <returns> true if a same alarm is found in the list; otherwise, false.</returns>
 private bool CheckAlarmExist(ref AlarmRecord duplicate)
 {
     foreach (AlarmRecord item in AlarmModel.ObservableAlarmList)
     {
         // Check scheduled time and alarm name
         if (item.ScheduledDateTime.Equals(AlarmModel.BindableAlarmRecord.ScheduledDateTime) &&
             item.AlarmName.Equals(AlarmModel.BindableAlarmRecord.AlarmName))
         {
             // a same alarm is found.
             duplicate.DeepCopy(item);
             return(true);
         }
     }
     // there's no same alarm.
     duplicate = null;
     return(false);
 }
Exemple #13
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();
        }
Exemple #14
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();
        }
Exemple #15
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);
        }
        /// <summary>
        /// Constructor for this class
        /// It defines UIs for this row
        /// </summary>
        /// <param name="alarmRecord">AlarmRecord</param>
        public AlarmEditSlider(AlarmRecord alarmRecord)
        {
            BindingContext    = alarmRecord;
            HorizontalOptions = LayoutOptions.FillAndExpand;
            //VerticalOptions = LayoutOptions.Start;
            HeightRequest = 120;
            /// volume image beside slider
            volumeImage = new Image()
            {
                HeightRequest = 50,
                WidthRequest  = 50,
                Source        = alarmRecord.IsMute ? "alarm/01_volume_vibration.png" : "alarm/00_volume_icon.png",
            };
            ImageAttributes.SetBlendColor(volumeImage, Color.FromRgba(50, 150, 166, 204));
            // volume image depends on 'IsMute' value of AlarmModel.BindableAlarmRecord
            // When volume is mute, volume image changes to vibration image.
            volumeImage.SetBinding(Image.SourceProperty, new Binding("IsMute", BindingMode.Default, new MuteToImageSourceConverter(), source: AlarmModel.BindableAlarmRecord));

            /// slider to change volume
            slider = new Slider()
            {
                WidthRequest  = 720 - (32 + 50 + 32 + 32),
                Value         = AlarmModel.BindableAlarmRecord.Volume,
                HeightRequest = 50,
            };
            // Slider's Value affect volume of AlarmModel.BindableAlarmRecord
            //slider.SetBinding(Slider.ValueProperty, new Binding("Volume", BindingMode.OneWayToSource, source: AlarmModel.BindableAlarmRecord));
            slider.SetBinding(Slider.ValueProperty, new Binding("Volume", BindingMode.TwoWay, source: AlarmModel.BindableAlarmRecord));

            Children.Add(volumeImage,
                         Constraint.RelativeToParent((parent) => { return(32); }),
                         Constraint.RelativeToParent((parent) => { return((120 - 50) / 2); }));

            Children.Add(slider,
                         Constraint.RelativeToParent((parent) => { return(32 + 50 + 20); }),
                         Constraint.RelativeToParent((parent) => { return((120 - 50) / 2); }));
        }
Exemple #17
0
 public AlarmModel()
 {
     ObservableAlarmList   = new ObservableCollection <AlarmRecord>();
     AlarmRecordDictionary = DependencyService.Get <IAlarmPersistentHandler>().DeserializeAlarmRecord();
     BindableAlarmRecord   = new AlarmRecord();
     if (AlarmRecordDictionary == null)
     {
         AlarmRecordDictionary = new Dictionary <string, AlarmRecord>();
     }
     else
     {
         foreach (var alarmItem in AlarmRecordDictionary)
         {
             // Key is DateCreated
             var keyString = alarmItem.Key;
             // Retrieve alarm record
             AlarmRecord retrieved = alarmItem.Value;
             DependencyService.Get <ILog>().Debug("AlarmModel - Key : " + keyString);
             DependencyService.Get <ILog>().Debug("AlarmModel - Value : " + retrieved);
             // Add the retrieved alarm to list for AlarmListUI
             ObservableAlarmList.Add(retrieved);
         }
     }
 }
Exemple #18
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;
                }
            }
        }
Exemple #19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="record">AlarmRecord</param>
 public AlarmEditSliderCell(AlarmRecord record)
 {
     View = new AlarmEditSlider(record);
 }
        /// <summary>
        /// Draws alarm list
        /// </summary>
        /// <returns>Returns RelativeLayout</returns>
        protected virtual RelativeLayout Draw()
        {
            /// Need to get bindable context to assign list value
            AlarmRecord alarmData = (AlarmRecord)BindingContext;

            /// If binding context is null, can't proceed further action
            if (alarmData == null)
            {
                return(null);
            }

            alarmData.PrintProperty();

            /// Alarm item layout should be set if null
            if (alarmItemLayout == null)
            {
                // The layout of item cell
                alarmItemLayout = new RelativeLayout
                {
                    HeightRequest = 22 + 93 + 29,
                };

                // Time Label
                timeLabel = new Label()
                {
                    Text = (((App)Application.Current).Is24hourFormat) ?
                           alarmData.ScheduledDateTime.ToString("HH:mm") : alarmData.ScheduledDateTime.ToString("hh:mm"),
                    Style = alarmData.AlarmState == AlarmStates.Inactive ? AlarmStyle.ATO001D : AlarmStyle.ATO001,
                };
                // to meet To meet thin attribute for font, need to use custom feature
                FontFormat.SetFontWeight(timeLabel, FontWeight.Light);
                /// Style set for time label for normal case
                timeLabel.SetBinding(Label.StyleProperty, new Binding("AlarmState", BindingMode.Default, new AlarmStateToPropertyConverter(), AlarmModelComponent.Time));
                /// Needs to set binding context for scheduled time
                timeLabel.SetBinding(Label.TextProperty, new Binding("ScheduledDateTime", BindingMode.Default, new ScheduledDateTimeToTextConverter(), LabelType.Time));
                // Added to layout
                alarmItemLayout.Children.Add(timeLabel,
                                             Constraint.RelativeToParent((parent) =>
                {
                    return(32);
                }),
                                             Constraint.RelativeToParent((parent) =>
                {
                    return(22);
                }));

                // AM/PM Label
                amPmLabel = new Label()
                {
                    //the text of AM/PM label
                    Text = (((App)Application.Current).Is24hourFormat) ?
                           "" : alarmData.ScheduledDateTime.ToString("tt"),
                    Style = alarmData.AlarmState == AlarmStates.Inactive ? AlarmStyle.ATO002D : AlarmStyle.ATO002,
                };
                // to meet To meet thin attribute for font, need to use custom feature
                FontFormat.SetFontWeight(amPmLabel, FontWeight.Light);
                //amPmLabel.IsVisible = (((Tizen.App)Application.Current).Is24hourFormat) ? false : true;
                amPmLabel.SetBinding(Label.IsVisibleProperty, new Binding("AlarmDateFormat", BindingMode.Default, new DateFormatToVisibleConverter()));
                // Set style depending on alarm state
                amPmLabel.SetBinding(Label.StyleProperty, new Binding("AlarmState", BindingMode.Default, new AlarmStateToPropertyConverter(), AlarmModelComponent.AmPm));
                amPmLabel.SetBinding(Label.TextProperty, new Binding("ScheduledDateTime", BindingMode.Default, new ScheduledDateTimeToTextConverter(), LabelType.AmPm));
                // Added to layout
                alarmItemLayout.Children.Add(amPmLabel,
                                             Constraint.RelativeToView(timeLabel, (parent, sibling) => sibling.X + sibling.Width + 10),
                                             Constraint.RelativeToView(timeLabel, (parent, sibling) => sibling.Y + 36));

                // Repeat Image
                repeatImage = new Image
                {
                    Source        = "alarm/clock_ic_repeat.png",
                    WidthRequest  = 38,
                    HeightRequest = 38,
                };
                // Bind repeat Image's visibiliy to weekly repeating value
                repeatImage.SetBinding(Image.IsVisibleProperty, new Binding("Repeat", mode: BindingMode.Default));
                // Set repeat image's blending color on alarm state
                ImageAttributes.SetBlendColor(repeatImage, alarmData.AlarmState == AlarmStates.Inactive ? Color.FromHex("66000000") : Color.FromHex("FFFFFF"));
                repeatImage.SetBinding(ImageAttributes.BlendColorProperty, new Binding("AlarmState", BindingMode.OneWay, new AlarmStateToPropertyConverter(), AlarmModelComponent.Repeat));
                // Added to layout
                alarmItemLayout.Children.Add(repeatImage,
                                             Constraint.RelativeToParent((parent) => (720 - 104 - 32 - 268)),
                                             Constraint.RelativeToParent((parent) => (22 + 93) - (43 + 43)));

                /// Alarm Name Label
                alamNameLabel = new Label();
                /// For alarm name label, to meet To meet thin attribute for font, need to use custom feature
                FontFormat.SetFontWeight(alamNameLabel, FontWeight.Normal);
                /// Bind alarm lable's style to alarm state
                alamNameLabel.SetBinding(Label.StyleProperty, new Binding("AlarmState", BindingMode.OneWay, new AlarmStateToPropertyConverter(), AlarmModelComponent.Name));
                /// Bind label's text property to AlarmMode's AlarmName.
                alamNameLabel.SetBinding(Label.TextProperty, "AlarmName");
                // Update alarm name label's TranslationX property value according to repeat image's visibility
                alamNameLabel.SetBinding(Label.TranslationXProperty, new Binding("Repeat", BindingMode.OneWay, converter: new AlarmNameLabelPositionConverter()));
                // Bind alarm name label's visibility
                alamNameLabel.SetBinding(Label.IsVisibleProperty, new Binding("IsVisibleDateLabel", BindingMode.Default, new DateLabelVisibleToVisibility(), false));
                //alamNameLabel.Text = alarmData.AlarmName;
                // Added to relative layout
                alarmItemLayout.Children.Add(alamNameLabel,
                                             Constraint.RelativeToParent((parent) => (720 - 104 - 32 - 268)),
                                             Constraint.RelativeToParent((parent) => (22 + 93 - (43 + 43))));

                /// WeekDays Label
                weekDaysLabel = new Label()
                {
                    FormattedText = alarmData.GetFormatted(alarmData.WeekFlag, alarmData.AlarmState < AlarmStates.Inactive ? true : false),
                    IsVisible     = !alarmData.IsVisibleDateLabel,
                    Style         = alarmData.AlarmState == AlarmStates.Inactive ? AlarmStyle.ATO004D : AlarmStyle.ATO004,
                };
                // to meet To meet thin attribute for font, need to use custom feature
                FontFormat.SetFontWeight(weekDaysLabel, FontWeight.Normal);
                /// Style set for time label for normal case
                weekDaysLabel.SetBinding(Label.StyleProperty, new Binding("AlarmState", BindingMode.OneWay, new AlarmStateToPropertyConverter(), AlarmModelComponent.Weekly));
                /// Sets binding context for weekdays label
                weekDaysLabel.SetBinding(Label.FormattedTextProperty, new Binding("WeekdayRepeatText", BindingMode.Default));
                weekDaysLabel.SetBinding(Label.IsVisibleProperty, new Binding("IsVisibleDateLabel", BindingMode.Default, new DateLabelVisibleToVisibility(), false));
                /// Adds to relative layout
                alarmItemLayout.Children.Add(weekDaysLabel,
                                             Constraint.RelativeToParent((parent) => (720 - 104 - 32 - 268)),
                                             Constraint.RelativeToParent((parent) => (22 + 93) - 43));

                // Date label
                // DateLabel is only visible when the alarm name is empty and repeat weekly is Never.
                dateLabel = new Label
                {
                    Text = alarmData.ScheduledDateTime.ToString("ddd, d MMM"),
                };
                // to meet To meet thin attribute for font, need to use custom feature
                FontFormat.SetFontWeight(dateLabel, FontWeight.Normal);
                dateLabel.SetBinding(Label.IsVisibleProperty, new Binding("IsVisibleDateLabel", BindingMode.Default, new DateLabelVisibleToVisibility(), true));
                dateLabel.SetBinding(Label.StyleProperty, new Binding("AlarmState", BindingMode.Default, new AlarmStateToPropertyConverter(), AlarmModelComponent.Date));
                alarmItemLayout.Children.Add(dateLabel,
                                             Constraint.RelativeToParent((parent) => (720 - 104 - 32 - 268)),
                                             Constraint.RelativeToParent((parent) => 22));

                /// Switch object to represent that the alarm is active or not
                switchObj = new Switch
                {
                    HeightRequest = 72,
                    WidthRequest  = 72,
                    IsToggled     = alarmData.AlarmState == AlarmStates.Inactive ? false : true,
                };
                /// Bind IsToggled property to alarm state
                //switchObj.SetBinding(Switch.IsToggledProperty, new Binding("AlarmState", BindingMode.OneWay, new AlarmStateToPropertyConverter(), AlarmModelComponent.State));
                /// Adds to relative layout
                alarmItemLayout.Children.Add(switchObj,
                                             Constraint.RelativeToParent((parent) =>
                {
                    return(720 - 104);
                }),
                                             Constraint.RelativeToParent((parent) =>
                {
                    return(22 + 93 - 72);
                }));

                /// Adds an event
                switchObj.Toggled += (s, e) =>
                {
                    //Switch sObj = s as Switch;
                    ///// Needs valid parent to proceed
                    //if (sObj.Parent == null || sObj.Parent.Parent == null)
                    //{
                    //    return;
                    //}

                    ///// Need binding context to check state
                    //AlarmRecord am = (AlarmRecord)((AlarmListCell)sObj.Parent.Parent).BindingContext;
                    //if (am == null)
                    //{
                    //    return;
                    //}
                    AlarmRecord am = (AlarmRecord)BindingContext;
                    /// Modify state and re-draw it. Redraw must be called to redraw
                    //am.AlarmState = e.Value ? AlarmStates.Active : AlarmStates.Inactive;
                    if (e.Value)
                    {
                        AlarmModel.ReactivatelAlarm(am);
                    }
                    else
                    {
                        AlarmModel.DeactivatelAlarm(am);
                    }

                    AlarmModel.PrintAll("After switch is toggled...");
                };
            }
            else
            {
                switchObj.IsVisible = true;
            }

            return(alarmItemLayout);
        }
Exemple #21
0
        public static bool Compare(AlarmRecord firstItem, AlarmRecord secondItem)
        {
            bool same = true;

            if (firstItem.IsSerialized != secondItem.IsSerialized)
            {
                DependencyService.Get <ILog>().Debug("[Compare] IsSerialized " + firstItem.IsSerialized + "  vs " + secondItem.IsSerialized);
                same = false;
            }

            if (firstItem.AlarmDateFormat != secondItem.AlarmDateFormat)
            {
                DependencyService.Get <ILog>().Debug("[Compare] AlarmDateFormat " + firstItem.AlarmDateFormat + "  vs " + secondItem.AlarmDateFormat);
                same = false;
            }

            if (firstItem.ScheduledDateTime != secondItem.ScheduledDateTime)
            {
                DependencyService.Get <ILog>().Debug("[Compare] ScheduledDateTime " + firstItem.ScheduledDateTime + "  vs " + secondItem.ScheduledDateTime);
                same = false;
            }

            if (firstItem.Repeat != secondItem.Repeat)
            {
                DependencyService.Get <ILog>().Debug("[Compare] Repeat " + firstItem.Repeat + "  vs " + secondItem.Repeat);
                same = false;
            }

            if (firstItem.WeekFlag != secondItem.WeekFlag)
            {
                DependencyService.Get <ILog>().Debug("[Compare] WeekFlag " + firstItem.WeekFlag + "  vs " + secondItem.WeekFlag);
                same = false;
            }

            if (firstItem.WeekdayRepeatText != secondItem.WeekdayRepeatText)
            {
                DependencyService.Get <ILog>().Debug("[Compare] WeekdayRepeatText " + firstItem.WeekdayRepeatText + "  vs " + secondItem.WeekdayRepeatText);
                same = false;
            }

            if (firstItem.AlarmType != secondItem.AlarmType)
            {
                DependencyService.Get <ILog>().Debug("[Compare] AlarmType " + firstItem.AlarmType + "  vs " + secondItem.AlarmType);
                same = false;
            }

            if (firstItem.Volume != secondItem.Volume)
            {
                DependencyService.Get <ILog>().Debug("[Compare] Volume " + firstItem.Volume + "  vs " + secondItem.Volume);
                same = false;
            }

            if (firstItem.IsMute != secondItem.IsMute)
            {
                DependencyService.Get <ILog>().Debug("[Compare] IsMute " + firstItem.IsMute + "  vs " + secondItem.IsMute);
                same = false;
            }

            if (firstItem.AlarmToneType != secondItem.AlarmToneType)
            {
                DependencyService.Get <ILog>().Debug("[Compare] AlarmToneType " + firstItem.AlarmToneType + "  vs " + secondItem.AlarmToneType);
                same = false;
            }

            if (firstItem.Snooze != secondItem.Snooze)
            {
                DependencyService.Get <ILog>().Debug("[Compare] Snooze " + firstItem.Snooze + "  vs " + secondItem.Snooze);
                same = false;
            }

            if (firstItem.AlarmState != secondItem.AlarmState)
            {
                DependencyService.Get <ILog>().Debug("[Compare] AlarmState " + firstItem.AlarmState + "  vs " + secondItem.AlarmState);
                same = false;
            }

            if (firstItem.AlarmName != secondItem.AlarmName)
            {
                DependencyService.Get <ILog>().Debug("[Compare] AlarmName " + firstItem.AlarmName + "  vs " + secondItem.AlarmName);
                same = false;
            }

            if (firstItem.DateCreated != secondItem.DateCreated)
            {
                DependencyService.Get <ILog>().Debug("[Compare] DateCreated " + firstItem.DateCreated + "  vs " + secondItem.DateCreated);
                same = false;
            }

            if (firstItem.NativeAlarmID != secondItem.NativeAlarmID)
            {
                DependencyService.Get <ILog>().Debug("[Compare] NativeAlarmID " + firstItem.NativeAlarmID + "  vs " + secondItem.NativeAlarmID);
                same = false;
            }

            if (firstItem.Delete != secondItem.Delete)
            {
                DependencyService.Get <ILog>().Debug("[Compare] Delete " + firstItem.Delete + "  vs " + secondItem.Delete);
                same = false;
            }

            if (firstItem.IsVisibleDateLabel != secondItem.IsVisibleDateLabel)
            {
                DependencyService.Get <ILog>().Debug("[Compare] IsVisibleDateLabel " + firstItem.IsVisibleDateLabel + "  vs " + secondItem.IsVisibleDateLabel);
                same = false;
            }

            return(same);
        }
        // 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();
        }
Exemple #23
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="alarmRecordData">alarmRecordData</param>
 public AlarmEditTimePickerCell(AlarmRecord alarmRecordData)
 {
     Time = alarmRecordData.ScheduledDateTime.TimeOfDay;
 }
Exemple #24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="record">AlarmRecord</param>
 public AlarmEditNameCell(AlarmRecord record)
 {
     View = new AlarmEditName(record);
 }