Beispiel #1
0
        private View CreateListItemEditingScheduleClass(ViewGroup root, ViewItemClass c)
        {
            var view = new ListItemEditingScheduleClassView(root, c);

            view.OnAddClassTimeRequested   += View_OnAddClassTimeRequested;
            view.OnEditClassTimesRequested += View_OnEditClassTimesRequested;
            view.OnEditClassRequested      += View_OnEditClassRequested;

            return(view);
        }
Beispiel #2
0
 public TableViewSource(UITableView tableView, ClassGradesViewModel viewModel)
 {
     _tableView = tableView;
     _viewModel = viewModel;
     _class     = viewModel.Class;
     _gradesCollectionChangedHandler            = new WeakEventHandler <NotifyCollectionChangedEventArgs>(Grades_CollectionChanged).Handler;
     _class.WeightCategories.CollectionChanged += new WeakEventHandler <NotifyCollectionChangedEventArgs>(WeightCategories_CollectionChanged).Handler;
     _viewModel.ClassViewModel.ViewItemsGroupClass.UnassignedItems.CollectionChanged += new WeakEventHandler <NotifyCollectionChangedEventArgs>(UnassignedItems_CollectionChanged).Handler;
     UpdateGradeCollectionChangedHandlers();
 }
        private static DateTime getDayOfReminderTime(BaseViewItemHomeworkExam h, AccountDataItem account, ref bool hasClassTime)
        {
            ViewItemClass c = h.GetClassOrNull();

            if (c == null)
            {
                return(DateTime.MinValue);
            }

            return(h.GetDayOfReminderTime(out hasClassTime));
        }
Beispiel #4
0
 public void SelectClassWithinSemester(ViewItemClass classToSelect, bool allowGoingBack = false)
 {
     if (classToSelect == null)
     {
         SelectClassWithoutLoading(Guid.Empty, allowGoingBack);
     }
     else
     {
         SelectClassWithoutLoading(classToSelect.Identifier, allowGoingBack);
     }
 }
 public void ViewClass(ViewItemClass c)
 {
     if (PowerPlannerApp.ShowClassesAsPopups)
     {
         OpenClassAsPopup(c);
     }
     else
     {
         Navigate(new ClassViewModel(this, CurrentLocalAccountId, c.Identifier, DateTime.Today, CurrentSemester));
     }
 }
        private static DateTime GetDayOfReminderTime(ViewItemTaskOrEvent h, ref bool hasClassTime)
        {
            ViewItemClass c = h.Class;

            if (c == null)
            {
                return(DateTime.MinValue);
            }

            return(h.GetDayOfReminderTime(out hasClassTime));
        }
Beispiel #7
0
        public ConfigureClassWeightCategoriesViewModel(BaseViewModel parent, ViewItemClass c) : base(parent)
        {
            Class = c;

            WeightCategories = new MyObservableList <EditingWeightCategoryViewModel>(c.WeightCategories.Select(
                                                                                         i => new EditingWeightCategoryViewModel()
            {
                Name       = i.Name,
                Weight     = i.WeightValue,
                Identifier = i.Identifier
            }));
        }
 public void ViewClass(ViewItemClass c, ClassViewModel.ClassPages?initialPage = null)
 {
     if (PowerPlannerApp.ShowClassesAsPopups)
     {
         OpenClassAsPopup(c, initialPage);
     }
     else
     {
         Navigate(new ClassViewModel(this, CurrentLocalAccountId, c.Identifier, DateTime.Today, CurrentSemester)
         {
             InitialPage = initialPage
         });
     }
 }
        private void UserControl_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            if (_currClass != null)
            {
                DeregisterOldClass(_currClass);
            }

            _currClass = args.NewValue as ViewItemClass;

            if (_currClass != null)
            {
                RegisterNewClass(_currClass);
            }
        }
        public ListItemEditingScheduleClassView(ViewGroup root, ViewItemClass c) : base(Resource.Layout.ListItemEditingScheduleClass, root)
        {
            DataContext = c;

            FindViewById <Button>(Resource.Id.ButtonAddTime).Click += delegate { OnAddClassTimeRequested?.Invoke(this, (ViewItemClass)DataContext); };
            FindViewById(Resource.Id.ListItemEditingScheduleClass_ClassName).Click += delegate { OnEditClassRequested?.Invoke(this, (ViewItemClass)DataContext); };

            _timesItemsControlWrapper = new ItemsControlWrapper(FindViewById <ViewGroup>(Resource.Id.ViewGroupClassTimes))
            {
                ItemTemplate = new CustomDataTemplate <ViewItemSchedule[]>(CreateListViewTimeItem)
            };

            c.Schedules.CollectionChanged += new WeakEventHandler <NotifyCollectionChangedEventArgs>(Schedules_CollectionChanged).Handler;
            UpdateTimes();
        }
        public ConfigureClassGradeScaleViewModel(BaseViewModel parent, ViewItemClass c) : base(parent)
        {
            Class = c;

            GradeScales = new MyObservableList <GradeScale>(c.GradeScales.Select(
                                                                i => new GradeScale()
            {
                StartGrade = i.StartGrade,
                GPA        = i.GPA
            }));
            foreach (var gradeScale in GradeScales)
            {
                gradeScale.PropertyChanged += GradeScale_PropertyChanged;
            }
        }
        protected static ViewItemSchedule findSchedule(ViewItemClass c, DateTime date)
        {
            if (c == null || c.IsNoClassClass || c.Schedules == null)
            {
                return(null);
            }

            for (int i = 0; i < c.Schedules.Count; i++)
            {
                if (c.Schedules[i].DayOfWeek == date.DayOfWeek)
                {
                    return(c.Schedules[i]);
                }
            }

            return(null);
        }
        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);
        }
Beispiel #14
0
        private View CreateClassMenuItem(ViewGroup root, ViewItemClass c)
        {
            var layout = new ListItemClassMenuItemView(root)
            {
                DataContext = c
            };

            layout.Click += delegate
            {
                var dontWait = ViewModel.SelectClass(c.Identifier);
                _drawerLayout.CloseDrawers();
            };

            UpdateIsClassSelected(layout, c.Identifier);

            PropertyChangedEventHandler propertyChangedHandler = null;

            propertyChangedHandler = new WeakEventHandler <PropertyChangedEventArgs>((s, e) =>
            {
                try
                {
                    if (e.PropertyName.Equals(nameof(ViewModel.SelectedClass)))
                    {
                        UpdateIsClassSelected(layout, c.Identifier);
                    }
                }
                catch (ObjectDisposedException)
                {
                    ViewModel.PropertyChanged -= propertyChangedHandler;
                }
                catch (Exception ex)
                {
                    TelemetryExtension.Current?.TrackException(ex);
                }
            }).Handler;
            ViewModel.PropertyChanged += propertyChangedHandler;

            return(layout);
        }
Beispiel #15
0
        /// <summary>
        /// Does not modify the current SelectedItem
        /// </summary>
        /// <returns></returns>
        private bool updateAvailableItems()
        {
            // if they haven't picked a semester, we MUST display selecting semester options
            if (hasNoSemester())
            {
                _selectedClass = null;

                if (makeAvailableItemsLike(SELECTING_SEMESTER_ITEMS))
                {
                    restoreDefaultMemoryItems();
                }
            }

            else if (hasNoClasses())
            {
                _selectedClass = null;

                if (makeAvailableItemsLike(NO_CLASSES_ITEMS))
                {
                    restoreDefaultMemoryItems();
                }
            }

            else
            {
                makeAvailableItemsLike(GetDefaultItems());
            }



            // make sure the class is valid too
            //if (SelectedItem == NavigationManager.MainMenuSelections.Classes)
            //{
            //    if (updateSelectedClass())
            //        return true;
            //}

            return(false);
        }
            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);
                }
            }
        /// <summary>
        /// Returns true if the class takes place on the specified date.
        /// </summary>
        /// <param name="date"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public static bool DoesClassOccurOnDate(AccountDataItem account, DateTime date, ViewItemClass c)
        {
            if (c.Schedules == null || c.Schedules.Count == 0 || account == null)
            {
                return(false);
            }

            var currWeek = account.GetWeekOnDifferentDate(date);

            return(c.Schedules.Any(s =>
                                   s.DayOfWeek == date.DayOfWeek &&
                                   (s.ScheduleWeek == Schedule.Week.BothWeeks || s.ScheduleWeek == currWeek)));
        }
Beispiel #18
0
        public static AddTaskOrEventViewModel CreateForEdit(BaseViewModel parent, EditParameter editParams)
        {
            var account = parent.FindAncestor <MainWindowViewModel>()?.CurrentAccount;

            if (account == null)
            {
                throw new NullReferenceException("CurrentAccount was null");
            }
            ViewItemClass   c    = editParams.Item.Class;
            TaskOrEventType type = editParams.Item.Type;

            if (c == null)
            {
                throw new NullReferenceException("Class of the item was null. Item id " + editParams.Item.Identifier);
            }

            if (c.Semester == null)
            {
                throw new NullReferenceException("Semester of the class was null. Item id " + editParams.Item.Identifier);
            }

            if (c.Semester.Classes == null)
            {
                throw new NullReferenceException("Classes of the semester was null. Item id " + editParams.Item.Identifier);
            }

            var model = new AddTaskOrEventViewModel(parent)
            {
                Account               = account,
                State                 = OperationState.Editing,
                EditParams            = editParams,
                Name                  = editParams.Item.Name,
                Classes               = GetClassesWithNoClassClass(c.Semester.Classes),
                Date                  = editParams.Item.DateInSchoolTime.Date,
                Details               = editParams.Item.Details,
                Type                  = type,
                ImageNames            = editParams.Item.ImageNames.ToArray(),
                IsInDifferentTimeZone = parent.FindAncestorOrSelf <MainScreenViewModel>().CurrentAccount.IsInDifferentTimeZone,
                Class                 = c // Assign class last, since it also assigns weight categories
            };

            // Assign existing image attachments
            model.ImageAttachments = new ObservableCollection <BaseEditingImageAttachmentViewModel>(editParams.Item.ImageNames.Select(i => new EditingExistingImageAttachmentViewModel(model, i)));

            switch (editParams.Item.GetActualTimeOption())
            {
            case DataItemMegaItem.TimeOptions.AllDay:
                model.SelectedTimeOption = model.TimeOption_AllDay;
                break;

            case DataItemMegaItem.TimeOptions.BeforeClass:
                model.SelectedTimeOption = model.TimeOption_BeforeClass;
                break;

            case DataItemMegaItem.TimeOptions.Custom:
                model._startTime         = new TimeSpan(editParams.Item.DateInSchoolTime.Hour, editParams.Item.DateInSchoolTime.Minute, 0);
                model._endTime           = editParams.Item.EndTimeInSchoolTime.TimeOfDay;
                model.SelectedTimeOption = model.TimeOption_Custom;
                break;

            case DataItemMegaItem.TimeOptions.DuringClass:
                model.SelectedTimeOption = model.TimeOption_DuringClass;
                break;

            case DataItemMegaItem.TimeOptions.EndOfClass:
                model.SelectedTimeOption = model.TimeOption_EndOfClass;
                break;

            case DataItemMegaItem.TimeOptions.StartOfClass:
                model.SelectedTimeOption = model.TimeOption_StartOfClass;
                break;
            }

            // We don't want to consider setting the initial time option as the user configuring the time option
            model._userChangedSelectedTimeOption = false;

            return(model);
        }
Beispiel #19
0
        public static AddTaskOrEventViewModel CreateForAdd(BaseViewModel parent, AddParameter addParams)
        {
            AccountDataItem account = parent.FindAncestor <MainWindowViewModel>()?.CurrentAccount;

            if (account == null)
            {
                throw new NullReferenceException("CurrentAccount was null");
            }

            if (addParams.Classes.Count == 0)
            {
                throw new InvalidOperationException("No classes");
            }

            bool     intelligentlyPickDate = true;
            DateTime now = DateTime.Now;

            IList <ViewItemClass> classes = GetClassesWithNoClassClass(addParams.Classes);

            ViewItemClass c = addParams.SelectedClass;

            if (c == null)
            {
                if (addParams.Type == TaskOrEventType.Task || addParams.Type == TaskOrEventType.Event)
                {
                    var prevClassIdentifier = NavigationManager.GetPreviousAddItemClass();
                    if (prevClassIdentifier != null)
                    {
                        // Remember user's selection
                        c = classes.FirstOrDefault(i => i.Identifier == prevClassIdentifier);
                    }

                    if (c == null)
                    {
                        // If date is specified
                        if (addParams.DueDate != null)
                        {
                            // If today
                            if (addParams.DueDate.Value.Date == now.Date)
                            {
                                // Pick currently going on class
                                c = PowerPlannerApp.GetClosestClassBasedOnSchedule(now, account, addParams.Classes);
                            }

                            // If there wasn't a class going on (or wasn't today), pick first class on that day
                            if (c == null)
                            {
                                c = PowerPlannerApp.GetFirstClassOnDay(addParams.DueDate.Value, account, addParams.Classes);
                            }
                        }

                        // Otherwise
                        else
                        {
                            // Intelligently pick based on schedule
                            c = PowerPlannerApp.GetClosestClassBasedOnSchedule(now, account, addParams.Classes);
                        }
                    }

                    if (c == null)
                    {
                        // If there wasn't a class and we're just doing the dummy pick first,
                        // don't intelligently pick class date
                        intelligentlyPickDate = false;
                        c = classes.First();
                    }
                }
                else
                {
                    // Tasks don't have classes
                    intelligentlyPickDate = false;
                }
            }

            DateTime date;

            if (addParams.DueDate != null)
            {
                date = addParams.DueDate.Value;
            }
            else
            {
                var prevDate = NavigationManager.GetPreviousAddItemDate();
                if (prevDate != null)
                {
                    date = prevDate.Value;
                }
                else
                {
                    DateTime?nextClassDate = null;

                    if (intelligentlyPickDate)
                    {
                        nextClassDate = PowerPlannerApp.GetNextClassDate(account, c);
                    }

                    if (nextClassDate != null)
                    {
                        date = nextClassDate.Value;
                    }
                    else
                    {
                        date = DateTime.Today;
                    }
                }
            }

            return(new AddTaskOrEventViewModel(parent)
            {
                Account = account,
                State = OperationState.Adding,
                AddParams = addParams,
                Classes = classes,
                Date = date.Date,
                Type = addParams.Type,
                IsClassPickerVisible = !addParams.HideClassPicker,
                IsWeightCategoryPickerVisible = true,
                ImageAttachments = new ObservableCollection <BaseEditingImageAttachmentViewModel>(),
                IsInDifferentTimeZone = parent.FindAncestorOrSelf <MainScreenViewModel>().CurrentAccount.IsInDifferentTimeZone,
                Class = c // Assign class last, since it also assigns weight categories, and updates time options from remembered times
            });
        }
        private static void UpdateDayOfNotification(Guid localAccountId, BaseViewItemHomeworkExam item, DateTime dayOfReminderTime, Context context, NotificationManager notificationManager, List <StatusBarNotification> existingNotifs, bool fromForeground)
        {
            ViewItemClass c = item.GetClassOrNull();

            if (c == null)
            {
                return;
            }

            string tag      = localAccountId.ToString() + ";" + item.Identifier.ToString();
            var    existing = existingNotifs.FirstOrDefault(i => i.Tag == tag);

            // If the reminder has already been sent and the notification doesn't exist,
            // that means the user dismissed it, so don't show it again
            if (item.HasSentReminder && existing == null)
            {
                return;
            }

            // If there's no existing notification, and the updated time is greater than the desired reminder time,
            // then it was edited after the notification should have been sent, so don't notify, since user was already
            // aware of this item (by the fact that they were editing it)
            if (existing == null && item.Updated.ToLocalTime() > dayOfReminderTime)
            {
                return;
            }

            if (existing == null && fromForeground)
            {
                return;
            }

            const string EXTRA_UNIQUE_ID = "UniqueId";
            string       extraUniqueId   = (item.Name + ";" + c.Name).GetHashCode().ToString();

            // If there's an existing, and it hasn't changed, do nothing
            if (existing != null && existing.Notification.Extras.GetString(EXTRA_UNIQUE_ID).Equals(extraUniqueId))
            {
                return;
            }

            BaseArguments launchArgs;

            if (item is ViewItemHomework)
            {
                launchArgs = new ViewHomeworkArguments()
                {
                    LocalAccountId = localAccountId,
                    ItemId         = item.Identifier,
                    LaunchSurface  = LaunchSurface.Toast
                };
            }
            else
            {
                launchArgs = new ViewExamArguments()
                {
                    LocalAccountId = localAccountId,
                    ItemId         = item.Identifier,
                    LaunchSurface  = LaunchSurface.Toast
                };
            }

            var    builder = CreateReminderBuilder(context, localAccountId, launchArgs);
            Bundle b       = new Bundle();

            b.PutString(EXTRA_UNIQUE_ID, extraUniqueId);
            builder.SetExtras(b);
            builder.SetContentTitle(item.Name);
            builder.SetChannelId(GetChannelIdForDayOf(localAccountId));
            string subtitle = item.GetSubtitleOrNull();

            if (subtitle != null)
            {
                builder.SetContentText(subtitle);
            }
            notificationManager.Notify(tag, NotificationIds.DAY_OF_NOTIFICATIONS, BuildReminder(builder));
        }
 public void ViewClass(ViewItemClass c)
 {
     MainScreenViewModel.ViewClass(c);
 }
Beispiel #22
0
            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);
                }
            }
Beispiel #23
0
        private async Task LoadBlocking(ViewItemSemester viewItemSemester, bool includeWeights)
        {
            var dataStore = await GetDataStore();

            DataItemClass dataClass;

            DataItemClass[]          dataClasses;
            DataItemSchedule[]       dataSchedules;
            DataItemWeightCategory[] dataWeights;

            using (await Locks.LockDataForReadAsync("ClassViewItemsGroup.LoadBlocking"))
            {
                dataClasses = viewItemSemester.Classes.Select(i => i.DataItem).OfType <DataItemClass>().ToArray();

                var viewClassRef = viewItemSemester.Classes.FirstOrDefault(i => i.Identifier == _classId);
                dataClass = viewClassRef?.DataItem as DataItemClass;

                if (dataClass == null)
                {
                    throw new ClassNotFoundExcetion();
                }

                dataSchedules = viewClassRef.Schedules.Select(i => i.DataItem).OfType <DataItemSchedule>().ToArray();

                if (includeWeights)
                {
                    // Get weights for ALL classes, since we need them for editing purposes when editing item to different class
                    dataWeights = viewItemSemester.Classes.SelectMany(i => i.WeightCategories).Select(i => i.DataItem).OfType <DataItemWeightCategory>().ToArray();
                }
                else
                {
                    dataWeights = null;
                }

                Func <DataItemWeightCategory, ViewItemWeightCategory> createWeight = null;
                if (includeWeights)
                {
                    createWeight = CreateWeight;
                }

                var classItem = new ViewItemClass(
                    dataClass,
                    createScheduleMethod: CreateSchedule,
                    createWeightMethod: createWeight);

                classItem.FilterAndAddChildren(dataSchedules);

                if (includeWeights)
                {
                    classItem.FilterAndAddChildren(dataWeights);
                }

                this.Class = classItem;

                _semester = new ViewItemSemester(dataClass.UpperIdentifier, createClassMethod: CreateClass);

                dataClasses = dataStore.TableClasses.Where(i => i.UpperIdentifier == _semester.Identifier).ToArray();

                _semester.FilterAndAddChildren(dataClasses);

                // Add the weights for the other classes
                if (includeWeights)
                {
                    foreach (var c in _semester.Classes.Where(i => i.Identifier != this.Class.Identifier))
                    {
                        c.FilterAndAddChildren(dataWeights);
                    }
                }
            }

            // If there were no weights in the class, we need to create and add a weight
            if (this.Class.WeightCategories != null && this.Class.WeightCategories.Count == 0)
            {
                TelemetryExtension.Current?.TrackEvent("Error_ClassMissingWeightCategoryAddingDefault");

                DataChanges changes = new DataLayer.DataChanges();
                changes.Add(AccountDataStore.CreateDefaultWeightCategory(this.Class.Identifier));

                await PowerPlannerApp.Current.SaveChanges(changes);
            }
        }
Beispiel #24
0
 private void View_OnEditClassRequested(object sender, ViewItemClass e)
 {
     ViewModel.EditClass(e);
 }
 /// <summary>
 /// Class must already have weights and grades loaded
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="c"></param>
 public ClassWhatIfViewModel(BaseViewModel parent, ViewItemClass c) : base(parent)
 {
     _originalClass = c;
 }
Beispiel #26
0
 public void EditClass(ViewItemClass c)
 {
     ShowPopup(AddClassViewModel.CreateForEdit(this, c));
 }
Beispiel #27
0
 private void EditingAllSchedulesSingleClassControl_OnRequestEditClass(object sender, ViewItemClass e)
 {
     ViewModel.EditClass(e);
 }
 public void EditClass(ViewItemClass c)
 {
     MainScreenViewModel.EditClass(c);
 }
Beispiel #29
0
 private void View_OnAddClassTimeRequested(object sender, ViewItemClass e)
 {
     ViewModel.AddTime(e);
 }
 public ConfigureClassGradesListViewModel(BaseViewModel parent, ViewItemClass c) : base(parent)
 {
     Class = c;
 }