private View CreateTimeView(ViewGroup root, ViewItemSchedule schedule) { LinearLayout layout = new LinearLayout(root.Context) { Orientation = Orientation.Vertical, LayoutParameters = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent) }; layout.SetPadding(0, 0, 0, ThemeHelper.AsPx(root.Context, 4)); layout.AddView(new TextView(root.Context) { Text = PowerPlannerResources.GetStringTimeToTime(DateHelper.ToShortTimeString(schedule.StartTime), DateHelper.ToShortTimeString(schedule.EndTime)) }); if (!string.IsNullOrWhiteSpace(schedule.Room)) { layout.AddView(new TextView(root.Context) { Text = schedule.Room.Trim() }); } return(layout); }
public MyScheduleItemView(Context context, ViewItemSchedule s) : base(context) { Schedule = s; base.Orientation = Orientation.Vertical; base.SetPaddingRelative(ThemeHelper.AsPx(context, 5), ThemeHelper.AsPx(context, 5), 0, 0); m_classColorBindingInstance = Binding.SetBinding(s.Class, nameof(s.Class.Color), (c) => { base.Background = new ColorDrawable(ColorTools.GetColor(c.Color)); }); // Can't figure out how to let both class name and room wrap while giving more importance // to room like I did on UWP, so just limiting name to 2 lines for now till someone complains. var textViewName = CreateTextView(""); m_classNameBindingInstance = Binding.SetBinding(s.Class, nameof(s.Class.Name), (c) => { textViewName.Text = c.Name; }); textViewName.SetMaxLines(2); base.AddView(textViewName); base.AddView(CreateTextView(GetStringTimeToTime(s))); if (!string.IsNullOrWhiteSpace(s.Room)) { base.AddView(CreateTextView(s.Room)); } }
public ScheduleItem(DayScheduleItemsArranger arranger, ViewItemSchedule viewItem) : base(arranger) { Item = viewItem; StartTime = viewItem.StartTime.TimeOfDay; EndTime = viewItem.EndTime.TimeOfDay; }
private void addSchedule(ViewItemSchedule s, List <ScheduleCreator> creators) { foreach (ScheduleCreator c in creators) { if (c.Add(s)) { return; } } creators.Add(new ScheduleCreator(s)); }
private static XmlDocument GeneratePayload(AccountDataItem account, ViewItemSchedule s) { var c = s.Class; var builder = new ToastContentBuilder() .AddToastActivationInfo(new ViewClassArguments() { LocalAccountId = account.LocalAccountId, ItemId = c.Identifier, LaunchSurface = LaunchSurface.Toast }.SerializeToString(), ToastActivationType.Foreground) .SetToastScenario(ToastScenario.Reminder) .AddText(c.Name) .AddText(string.Format(_timeToTime, _timeFormatter.Format(s.StartTime), _timeFormatter.Format(s.EndTime))); if (!string.IsNullOrWhiteSpace(s.Room)) { builder.AddText(s.Room); } builder.AddToastInput(new ToastSelectionBox("snoozeTime") { DefaultSelectionBoxItemId = "5", Items = { new ToastSelectionBoxItem("5", PowerPlannerResources.GetXMinutes(5)), new ToastSelectionBoxItem("10", PowerPlannerResources.GetXMinutes(10)), new ToastSelectionBoxItem("15", PowerPlannerResources.GetXMinutes(15)), new ToastSelectionBoxItem("30", PowerPlannerResources.GetXMinutes(30)), new ToastSelectionBoxItem("45", PowerPlannerResources.GetXMinutes(45)) } }); builder.AddButton(new ToastButtonSnooze() { SelectionBoxId = "snoozeTime" }); builder.AddButton(new ToastButtonDismiss()); return(builder.GetToastContent().GetXml()); }
protected static int compareViaClass( ViewItemClass class1, DateTime dateCreated1, DateTime actualDate1, ViewItemClass class2, DateTime dateCreated2, DateTime actualDate2) { if (class1 == null || class2 == null || class1 == class2) { return(dateCreated1.CompareTo(dateCreated2)); } ViewItemSchedule schedule1 = findSchedule(class1, actualDate1); ViewItemSchedule schedule2 = findSchedule(class2, actualDate2); //if both schedules missing, group by class if (schedule1 == null && schedule2 == null) { return(class1.CompareTo(class2)); } //if the other schedule is missing, this item should go first if (schedule2 == null) { return(-1); } //if this schedule is missing, the other item should go first if (schedule1 == null) { return(1); } //get the comparison of their start times int comp = schedule1.StartTime.TimeOfDay.CompareTo(schedule2.StartTime.TimeOfDay); //if they started at the same time, use the updated time if (comp == 0) { return(dateCreated1.CompareTo(dateCreated2)); } return(comp); }
private static AdaptiveGroup GenerateTileNotificationMediumGroupContent(ViewItemSchedule schedule) { AdaptiveSubgroup subgroup = new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = TrimString(schedule.Class.Name, 40) }, new AdaptiveText() { Text = GetTimeString(schedule.StartTime), HintStyle = AdaptiveTextStyle.TitleNumeral } } }; if (!string.IsNullOrWhiteSpace(schedule.Room)) { subgroup.Children.Add(new AdaptiveText() { Text = TrimString(schedule.Room, 40), HintStyle = AdaptiveTextStyle.CaptionSubtle, HintWrap = true }); } return(new AdaptiveGroup() { Children = { subgroup } }); }
protected override void OnDataContextChanged() { IEnumerable <ViewItemSchedule> schedules = DataContext as IEnumerable <ViewItemSchedule>; if (schedules == null || !schedules.Any()) { return; } ViewItemSchedule first = schedules.First(); _labelDayOfWeeks.Text = string.Join(", ", schedules.Select(i => i.DayOfWeek).Distinct().OrderBy(i => i).Select(i => DateTools.ToLocalizedString(i))); _labelTime.Text = PowerPlannerResources.GetStringTimeToTime(DateTimeFormatterExtension.Current.FormatAsShortTime(first.StartTime), DateTimeFormatterExtension.Current.FormatAsShortTime(first.EndTime)); if (string.IsNullOrWhiteSpace(first.Room)) { _visibilityRoom.IsVisible = false; } else { _labelRoom.Text = first.Room; _visibilityRoom.IsVisible = true; } if (first.ScheduleWeek == PowerPlannerSending.Schedule.Week.BothWeeks) { _visibilityWeek.IsVisible = false; } else { _labelWeek.Text = PowerPlannerResources.GetLocalizedWeek(first.ScheduleWeek); _visibilityWeek.IsVisible = false; } base.OnDataContextChanged(); }
private static TileBindingContentAdaptive GenerateSmallContent(IEnumerable <ViewItemSchedule> schedules, DateTime date, DateTime relativeTo) { ViewItemSchedule first = schedules.First(); string timeString; if (date.Date == relativeTo.Date) { timeString = GetTimeString(first.StartTime); } else { timeString = date.ToString("M/d"); } return(new TileBindingContentAdaptive() { TextStacking = TileTextStacking.Center, Children = { new AdaptiveText() { Text = TrimString(first.Class.Name, 35), HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = timeString, HintAlign = AdaptiveTextAlign.Center, HintStyle = AdaptiveTextStyle.CaptionSubtle } } }); }
private void UserControl_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args) { IEnumerable <ViewItemSchedule> schedules = DataContext as IEnumerable <ViewItemSchedule>; if (schedules == null || !schedules.Any()) { return; } ViewItemSchedule first = schedules.First(); var timeFormatter = new DateTimeFormatter("shorttime"); TextBlockDayOfWeeks.Text = string.Join(", ", schedules.Select(i => i.DayOfWeek).Distinct().OrderBy(i => i).Select(i => DateTools.ToLocalizedString(i))); TextBlockName.Text = LocalizedResources.Common.GetStringTimeToTime(timeFormatter.Format(first.StartTime), timeFormatter.Format(first.EndTime)); if (string.IsNullOrWhiteSpace(first.Room)) { TextBlockRoom.Visibility = Visibility.Collapsed; } else { TextBlockRoom.Text = first.Room; TextBlockRoom.Visibility = Visibility.Visible; } if (first.ScheduleWeek == PowerPlannerSending.Schedule.Week.BothWeeks) { TextBlockWeek.Visibility = Visibility.Collapsed; } else { TextBlockWeek.Text = LocalizedResources.Common.GetLocalizedWeek(first.ScheduleWeek); TextBlockWeek.Visibility = Visibility.Visible; } }
private void Adapter_ScheduleItemClick(object sender, ViewItemSchedule e) { ScheduleItemClick?.Invoke(this, e); }
/// <summary> /// Finds related schedules and edits them as a batch /// </summary> /// <param name="schedule"></param> public void EditTimes(ViewItemSchedule schedule) { var group = schedule.Class.GetGroupOfSchedulesWithSharedEditingValues(schedule); EditTimes(group); }
private int getColumn(ViewItemSchedule s) { return(getColumn(s.DayOfWeek)); }
private void _snapshot_ScheduleItemClick(object sender, ViewItemSchedule e) { ScheduleItemClick?.Invoke(this, e); }
public UIScheduleItemView(ViewItemSchedule item) { Item = item; m_classBindingHost.BindingObject = item.Class; m_classBindingHost.SetBackgroundColorBinding(this, nameof(item.Class.Color)); var minTextHeight = UIFont.PreferredCaption1.LineHeight; var labelClass = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, TextColor = UIColor.White, Lines = 0, Font = UIFont.PreferredCaption1 }; m_classBindingHost.SetLabelTextBinding(labelClass, nameof(item.Class.Name)); this.Add(labelClass); labelClass.StretchWidth(this, left: 4); // Time and room don't need to be data bound, since these views will be re-created if those change var labelTime = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = PowerPlannerResources.GetStringTimeToTime(DateTimeFormatterExtension.Current.FormatAsShortTime(item.StartTime), DateTimeFormatterExtension.Current.FormatAsShortTime(item.EndTime)), TextColor = UIColor.White, Lines = 1, Font = UIFont.PreferredCaption1 }; this.Add(labelTime); labelTime.StretchWidth(this, left: 4); labelTime.SetContentCompressionResistancePriority(1000, UILayoutConstraintAxis.Vertical); if (string.IsNullOrWhiteSpace(item.Room)) { this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-2-[labelClass(>={minTextHeight})][labelTime]->=2-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary( "labelClass", labelClass, "labelTime", labelTime))); } else { var textViewRoom = new UITextView() { TranslatesAutoresizingMaskIntoConstraints = false, Text = item.Room.Trim(), TextColor = UIColor.White, //TintColor = UIColor.White, // Link color WeakLinkTextAttributes = new NSDictionary(UIStringAttributeKey.ForegroundColor, UIColor.White, UIStringAttributeKey.UnderlineStyle, 1), // Underline links and make them white BackgroundColor = UIColor.Clear, Font = UIFont.PreferredCaption1, Editable = false, ScrollEnabled = false, // Link detection: http://iosdevelopertips.com/user-interface/creating-clickable-hyperlinks-from-a-url-phone-number-or-address.html DataDetectorTypes = UIDataDetectorType.All }; // Lose the padding: https://stackoverflow.com/questions/746670/how-to-lose-margin-padding-in-uitextview textViewRoom.TextContainerInset = UIEdgeInsets.Zero; textViewRoom.TextContainer.LineFragmentPadding = 0; this.Add(textViewRoom); textViewRoom.StretchWidth(this, left: 4, right: 4); textViewRoom.SetContentCompressionResistancePriority(900, UILayoutConstraintAxis.Vertical); this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-2-[labelClass(>={minTextHeight})][labelTime][labelRoom]->=2-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary( "labelClass", labelClass, "labelTime", labelTime, "labelRoom", textViewRoom))); } }
public MyScheduleItem(Context context, ViewItemSchedule s) : base(context) { Schedule = s; ViewItemClass c = s.Class as ViewItemClass; base.Orientation = Orientation.Vertical; base.Background = new ColorDrawable(ColorTools.GetColor(c.Color)); double hours = (s.EndTime.TimeOfDay - s.StartTime.TimeOfDay).TotalHours; base.LayoutParameters = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MatchParent, (int)Math.Max(HeightOfHour * hours, 0)); var marginSides = ThemeHelper.AsPx(context, 6); var marginBetween = ThemeHelper.AsPx(context, -2); var tvClass = new TextView(context) { Text = c.Name, Typeface = Typeface.DefaultBold }; tvClass.SetTextColor(Color.White); tvClass.SetSingleLine(true); tvClass.SetPadding(marginSides, 0, marginSides, 0); var tvTime = new TextView(context) { Text = PowerPlannerResources.GetStringTimeToTime(DateHelper.ToShortTimeString(s.StartTime), DateHelper.ToShortTimeString(s.EndTime)), Typeface = Typeface.DefaultBold }; tvTime.SetTextColor(Color.White); tvTime.SetSingleLine(true); tvTime.SetPadding(marginSides, marginBetween, marginSides, 0); var tvRoom = new TextView(context) { Text = s.Room, Typeface = Typeface.DefaultBold }; tvRoom.SetTextColor(Color.White); tvRoom.SetPadding(marginSides, marginBetween, marginSides, 0); if (hours >= 1.1) { base.AddView(tvClass); base.AddView(tvTime); base.AddView(tvRoom); } else { LinearLayout firstGroup = new LinearLayout(context); tvClass.LayoutParameters = new LinearLayout.LayoutParams( 0, LinearLayout.LayoutParams.WrapContent) { Weight = 1 }; firstGroup.AddView(tvClass); tvTime.SetPadding(marginSides, 0, marginSides, 0); tvTime.LayoutParameters = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent); firstGroup.AddView(tvTime); base.AddView(firstGroup); base.AddView(tvRoom); } }
private static TileBindingContentAdaptive GenerateTileNotificationWideContent(IEnumerable <ViewItemSchedule> schedules) { TileBindingContentAdaptive content = new TileBindingContentAdaptive(); if (schedules.Any()) { // Create and add the first large content content.Children.Add(GenerateTileNotificationWideAndLargeGroupContent(schedules.ElementAt(0))); if (schedules.Count() > 1) { // Add the image spacer content.Children.Add(new AdaptiveImage() { Source = "Assets/Tiles/Padding/4px.png", HintAlign = AdaptiveImageAlign.Left, HintRemoveMargin = true }); const int MAX_ADDITIONAL = 4; for (int i = 1; i < schedules.Count() && i < MAX_ADDITIONAL; i++) { ViewItemSchedule schedule = schedules.ElementAt(i); var group = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { HintWeight = 20, Children = { new AdaptiveText() { Text = GetTimeString(schedule.StartTime), HintStyle = AdaptiveTextStyle.CaptionSubtle } } }, new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = TrimString(schedule.Class.Name, 22), HintStyle = AdaptiveTextStyle.CaptionSubtle } } } } }; if (!string.IsNullOrWhiteSpace(schedule.Room)) { group.Children.Last().HintWeight = 30; group.Children.Add(new AdaptiveSubgroup() { // Don't need to assign weight since it gets the remaining from 100, // which saves spaces in the XML! Children = { new AdaptiveText() { Text = TrimString(schedule.Room, 32), HintStyle = AdaptiveTextStyle.CaptionSubtle } } }); } content.Children.Add(group); } } } return(content); }
private static AdaptiveGroup GenerateTileNotificationWideAndLargeGroupContent(ViewItemSchedule schedule) { return(new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { HintWeight = 44, Children = { new AdaptiveText() { Text = GetTimeString(schedule.StartTime), HintStyle = AdaptiveTextStyle.SubheaderNumeral } } }, new AdaptiveSubgroup() { HintWeight = 57, Children = { new AdaptiveText() { Text = TrimString(schedule.Class.Name, 50), HintAlign = AdaptiveTextAlign.Right }, new AdaptiveText() { Text = schedule.Room == null ? "" : TrimString(schedule.Room, 50), HintAlign = AdaptiveTextAlign.Right, HintStyle = AdaptiveTextStyle.CaptionSubtle } } } } }); }
public UIScheduleItemView(ViewItemSchedule item) { Item = item; m_classBindingHost.BindingObject = item.Class; m_classBindingHost.SetBackgroundColorBinding(this, nameof(item.Class.Color)); var minTextHeight = UIFont.PreferredCaption1.LineHeight; var labelClass = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, TextColor = UIColor.White, Lines = 0, Font = UIFont.PreferredCaption1 }; m_classBindingHost.SetLabelTextBinding(labelClass, nameof(item.Class.Name)); this.Add(labelClass); labelClass.StretchWidth(this, left: 4); // Time and room don't need to be data bound, since these views will be re-created if those change var labelTime = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = PowerPlannerResources.GetStringTimeToTime(DateTimeFormatterExtension.Current.FormatAsShortTime(item.StartTime), DateTimeFormatterExtension.Current.FormatAsShortTime(item.EndTime)), TextColor = UIColor.White, Lines = 1, Font = UIFont.PreferredCaption1 }; this.Add(labelTime); labelTime.StretchWidth(this, left: 4); labelTime.SetContentCompressionResistancePriority(1000, UILayoutConstraintAxis.Vertical); if (string.IsNullOrWhiteSpace(item.Room)) { this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-2-[labelClass(>={minTextHeight})][labelTime]->=2-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary( "labelClass", labelClass, "labelTime", labelTime))); } else { var labelRoom = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = item.Room.Trim(), TextColor = UIColor.White, Font = UIFont.PreferredCaption1, Lines = 0 }; this.Add(labelRoom); labelRoom.StretchWidth(this, left: 4, right: 4); labelRoom.SetContentCompressionResistancePriority(900, UILayoutConstraintAxis.Vertical); this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-2-[labelClass(>={minTextHeight})][labelTime][labelRoom]->=2-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary( "labelClass", labelClass, "labelTime", labelTime, "labelRoom", labelRoom))); } }
public MyScheduleItem(ViewItemSchedule s) { ViewItemClass c = s.Class as ViewItemClass; base.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top; base.Background = new SolidColorBrush(ColorTools.GetColor(c.Color)); var timeSpan = s.EndTime.TimeOfDay - s.StartTime.TimeOfDay; var hours = timeSpan.TotalHours; var showTimeText = timeSpan.TotalMinutes >= 38; base.Height = Math.Max(HEIGHT_OF_HOUR * hours, 0); base.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); base.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); base.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); base.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); base.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); TextBlock tbClass = new TextBlock() { Text = c.Name, Style = Application.Current.Resources["BaseTextBlockStyle"] as Style, Foreground = Brushes.White, FontWeight = FontWeights.SemiBold, Margin = new Windows.UI.Xaml.Thickness(6, 0, 6, 0), TextWrapping = Windows.UI.Xaml.TextWrapping.NoWrap, FontSize = 14 }; Grid.SetColumnSpan(tbClass, 2); base.Children.Add(tbClass); // Add the time text (xx:xx to xx:xx) - do NOT show the date text for anything below 38 minutes as that will overlap with the title and get pushed beneath it. TextBlock tbTime = null; if (showTimeText) { var timeFormatter = new DateTimeFormatter("shorttime"); tbTime = new TextBlock() { Text = LocalizedResources.Common.GetStringTimeToTime(timeFormatter.Format(s.StartTime), timeFormatter.Format(s.EndTime)), Style = Application.Current.Resources["BaseTextBlockStyle"] as Style, Foreground = Brushes.White, FontWeight = FontWeights.SemiBold, Margin = new Windows.UI.Xaml.Thickness(6, -2, 6, 0), TextWrapping = Windows.UI.Xaml.TextWrapping.NoWrap, FontSize = 14 }; } TextBlock tbRoom = new TextBlock() { Text = s.Room, Style = Application.Current.Resources["BaseTextBlockStyle"] as Style, Foreground = Brushes.White, FontWeight = FontWeights.SemiBold, Margin = new Windows.UI.Xaml.Thickness(6, -2, 6, 0), TextWrapping = Windows.UI.Xaml.TextWrapping.WrapWholeWords, FontSize = 14 }; if (hours >= 1.1) { if (showTimeText) { Grid.SetRow(tbTime, 1); Grid.SetColumnSpan(tbTime, 2); base.Children.Add(tbTime); } if (!string.IsNullOrWhiteSpace(s.Room)) { Grid.SetRow(tbRoom, showTimeText ? 2 : 1); Grid.SetColumnSpan(tbRoom, 2); base.Children.Add(tbRoom); } } else { if (showTimeText) { tbTime.Margin = new Thickness(tbTime.Margin.Left, tbTime.Margin.Top, tbTime.Margin.Right, 8); tbTime.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom; Grid.SetRow(tbTime, 2); base.Children.Add(tbTime); } tbRoom.Margin = new Thickness(tbRoom.Margin.Left, tbRoom.Margin.Top, tbRoom.Margin.Right, 8); tbRoom.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom; tbRoom.TextAlignment = TextAlignment.Right; tbRoom.TextWrapping = TextWrapping.NoWrap; tbRoom.TextTrimming = TextTrimming.CharacterEllipsis; Grid.SetRow(tbRoom, showTimeText ? 2 : 1); Grid.SetColumn(tbRoom, 1); base.Children.Add(tbRoom); } }
public static ViewItemClass GetClosestClassBasedOnSchedule(DateTime now, AccountDataItem account, IEnumerable <ViewItemClass> classes) { if (classes == null) { return(null); } var currWeek = account.GetWeekOnDifferentDate(now); var schedules = SchedulesOnDay.Get(classes, now, currWeek, trackChanges: false); ViewItemSchedule closestBefore = null; ViewItemSchedule closestAfter = null; //look through all schedules foreach (var s in schedules) { //if the class is currently going on if (now.TimeOfDay >= s.StartTime.TimeOfDay && now.TimeOfDay <= s.EndTime.TimeOfDay) { return(s.Class); } //else if the class is in the future, we instantly select it for the after class since it's sorted from earliest to latest else if (s.StartTime.TimeOfDay >= now.TimeOfDay) { // Make sure it's only 10 mins after if ((s.StartTime.TimeOfDay - now.TimeOfDay) < TimeSpan.FromMinutes(10)) { closestAfter = s; } // Regardless we break break; } else { // Make sure it's only 10 mins before if ((now.TimeOfDay - s.EndTime.TimeOfDay) < TimeSpan.FromMinutes(10)) { closestBefore = s; } } } if (closestAfter == null && closestBefore == null) { return(null); } else if (closestAfter == null) { return(closestBefore.Class); } else if (closestBefore == null) { return(closestAfter.Class); } else if ((now.TimeOfDay - closestBefore.EndTime.TimeOfDay) < (closestAfter.StartTime.TimeOfDay - now.TimeOfDay)) { return(closestBefore.Class); } else { return(closestAfter.Class); } }
public void Save() { TryStartDataOperationAndThenNavigate(async delegate { if (StartTime >= EndTime) { new PortableMessageDialog("Your end time must be greater than your start time.", "Invalid end time").Show(); return; } if (DayOfWeeks.Count == 0) { new PortableMessageDialog("You must select at least one day of week. If you want to delete this time, use the delete option in the menu.", "No day of weeks").Show(); return; } var updatedAndNewSchedules = new List <DataItemSchedule>(); Guid classId = AddParams != null ? AddParams.Class.Identifier : EditParams.GroupedSchedules.First().Class.Identifier; // Get the existing schedules List <ViewItemSchedule> existingSchedules = EditParams != null ? EditParams.GroupedSchedules.ToList() : new List <ViewItemSchedule>(); for (int i = 0; i < DayOfWeeks.Count; i++) { DayOfWeek dayOfWeek = DayOfWeeks[i]; // First try to find an existing schedule that already matches this day of week ViewItemSchedule existingSchedule = existingSchedules.FirstOrDefault(s => s.DayOfWeek == dayOfWeek); // If we couldn't find one, try picking a schedule that doesn't have any day of week matches if (existingSchedule == null) { existingSchedule = existingSchedules.FirstOrDefault(s => !DayOfWeeks.Contains(s.DayOfWeek)); } // Remove the schedule we added if (existingSchedule != null) { existingSchedules.Remove(existingSchedule); } DataItemSchedule dataItem = new DataItemSchedule() { Identifier = existingSchedule != null ? existingSchedule.Identifier : Guid.NewGuid(), UpperIdentifier = classId, StartTime = AsUtc(StartTime), EndTime = AsUtc(EndTime), Room = Room, DayOfWeek = dayOfWeek, ScheduleWeek = ScheduleWeek, ScheduleType = PowerPlannerSending.Schedule.Type.Normal }; updatedAndNewSchedules.Add(dataItem); } // Deleted schedules are any remaining existing schedules var deletedScheduleIds = existingSchedules.Select(i => i.Identifier).ToArray(); DataChanges changes = new DataChanges(); foreach (var s in updatedAndNewSchedules) { changes.Add(s); } foreach (var id in deletedScheduleIds) { changes.DeleteItem(id); } if (!changes.IsEmpty()) { await PowerPlannerApp.Current.SaveChanges(changes); } }, delegate { this.RemoveViewModel(); }); }
public static string GetStringTimeToTime(ViewItemSchedule s) { return(PowerPlannerResources.GetStringTimeToTime(DateHelper.ToShortTimeString(s.StartTime), DateHelper.ToShortTimeString(s.EndTime))); }