public AgendaViewController()
        {
            Title = GetTitle();
            HideBackButton();

            NavItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add)
            {
                Title = "Add item"
            };
            NavItem.RightBarButtonItem.Clicked += new WeakEventHandler <EventArgs>(ButtonAddItem_Clicked).Handler;

            _tableView = new UITableView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                SeparatorInset = UIEdgeInsets.Zero
            };
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                // Stretch to full width even on iPad
                _tableView.CellLayoutMarginsFollowReadableWidth = false;
            }
            _tableView.TableFooterView = new UIView(); // Eliminate extra separators on bottom of view
            ContentView.Add(_tableView);
            _tableView.StretchWidthAndHeight(ContentView);

            MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate
            {
                _tableView.ContentInset = new UIEdgeInsets(0, 0, MainScreenViewController.TAB_BAR_HEIGHT, 0);
            });
        }
Esempio n. 2
0
        public override void OnViewModelLoadedOverride()
        {
            var buttonAdd = new UIBarButtonItem(UIBarButtonSystemItem.Add);

            buttonAdd.Clicked         += new WeakEventHandler <EventArgs>(delegate { ViewModel.AddClass(); }).Handler;
            NavItem.RightBarButtonItem = buttonAdd;

            _labelNoClasses = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text          = "Tap \"+\" to add your first class!",
                Font          = UIFont.PreferredCallout,
                TextAlignment = UITextAlignment.Center
            };
            ContentView.Add(_labelNoClasses);
            _labelNoClasses.StretchWidthAndHeight(ContentView, left: 16, top: 16, right: 16, bottom: 16);

            _tableViewClasses = new UITableView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                // Stretch to full width even on iPad
                _tableViewClasses.CellLayoutMarginsFollowReadableWidth = false;
            }
            _tableViewClasses.TableFooterView = new UIView(); // Eliminate extra separators on bottom of view
            var tableViewClassesSource = new BareUITableViewSource <UIClassView>(_tableViewClasses, ViewModel.MainScreenViewModel.Classes);

            tableViewClassesSource.ItemSelected += new WeakEventHandler <object>(TableViewClassesSource_ItemSelected).Handler;
            _tableViewClasses.Source             = tableViewClassesSource;
            ContentView.Add(_tableViewClasses);
            _tableViewClasses.StretchWidthAndHeight(ContentView);

            MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate
            {
                _tableViewClasses.ContentInset = new UIEdgeInsets(0, 0, MainScreenViewController.TAB_BAR_HEIGHT, 0);
            });

            ViewModel.MainScreenViewModel.Classes.CollectionChanged += new WeakEventHandler <NotifyCollectionChangedEventArgs>(Classes_CollectionChanged).Handler;
            UpdateNoClassesVisual();

            base.OnViewModelLoadedOverride();
        }
        public AgendaViewController()
        {
            this.AutomaticallyAdjustsScrollViewInsets = false;

            _tableView = new UITableView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                SeparatorInset = UIEdgeInsets.Zero
            };
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                // Stretch to full width even on iPad
                _tableView.CellLayoutMarginsFollowReadableWidth = false;
            }
            _tableView.TableFooterView = new UIView(); // Eliminate extra separators on bottom of view
            View.Add(_tableView);
            _tableView.StretchWidthAndHeight(View);

            MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate
            {
                _tableView.ContentInset = new UIEdgeInsets(0, 0, MainScreenViewController.TAB_BAR_HEIGHT, 0);
            });
        }
        public override void OnViewModelLoadedOverride()
        {
            var cal = new MyCalendarView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                DisplayMonth = ViewModel.DisplayMonth
            };

            cal.SetSemester(ViewModel.SemesterItemsViewGroup.Semester);
            cal.Provider             = new MyDataProvider(ViewModel.SemesterItemsViewGroup, cal);
            cal.DateClicked         += new WeakEventHandler <DateTime>(Cal_DateClicked).Handler;
            cal.DisplayMonthChanged += new WeakEventHandler <DateTime>(Cal_DisplayMonthChanged).Handler;

            View.Add(cal);
            cal.StretchWidth(base.View);
            cal.PinToTop(base.View);

            MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate
            {
                cal.RemovePinToBottom(base.View).PinToBottom(base.View, (int)MainScreenViewController.TAB_BAR_HEIGHT);
            });

            base.OnViewModelLoadedOverride();
        }
        public override void OnViewModelAndViewLoadedOverride()
        {
            base.OnViewModelAndViewLoadedOverride();

            var scheduleView = new UIScheduleView(ViewModel)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            ContentView.Add(scheduleView);
            scheduleView.StretchWidthAndHeight(ContentView);

            var toolbar = new UIToolbar()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            ContentView.Add(toolbar);
            toolbar.StretchWidth(ContentView);
            toolbar.SetHeight(44);
            _labelDateRange = new UILabel()
            {
                BackgroundColor = UIColor.Clear,
                Font            = UIFont.PreferredCallout
            };
            _labelYearAndWeekContainer = new UIView();
            _labelYearAndWeek          = new UILabel()
            {
                Font            = UIFont.PreferredCaption1,
                TextColor       = UIColor.Gray,
                BackgroundColor = UIColor.Clear
            };
            _labelYearAndWeekContainer.Add(_labelYearAndWeek);
            BindingHost.SetBindings(new string[]
            {
                nameof(ViewModel.DisplayStartDate),
                nameof(ViewModel.DisplayEndDate),
                nameof(ViewModel.CurrentWeek),
                nameof(ViewModel.HasTwoWeekSchedule)
            }, UpdateToolbarLabels);
            toolbar.Items = new UIBarButtonItem[]
            {
                new UIBarButtonItem(_labelDateRange),
                new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace)
                {
                    Width = 6
                },
                new UIBarButtonItem(_labelYearAndWeekContainer),
                new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                new UIBarButtonItem(UIImage.FromBundle("ToolbarBack"), UIBarButtonItemStyle.Plain, new WeakEventHandler(delegate { ViewModel.PreviousWeek(); }).Handler),
                new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace)
                {
                    Width = 20
                },
                new UIBarButtonItem(UIImage.FromBundle("ToolbarForward"), UIBarButtonItemStyle.Plain, new WeakEventHandler(delegate { ViewModel.NextWeek(); }).Handler)
            };
            MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate
            {
                toolbar.RemovePinToBottom(ContentView).PinToBottom(ContentView, (int)MainScreenViewController.TAB_BAR_HEIGHT);
            });

            ViewModel.PropertyChanged += new WeakEventHandler <PropertyChangedEventArgs>(ViewModel_PropertyChanged).Handler;
            UpdateLayoutMode();
        }
        private void UpdateLayoutMode()
        {
            // Clean up from previous state
            if (_prevLayoutMode != null)
            {
                // If for some reason state didn't change, do nothing
                if (_prevLayoutMode.Value == ViewModel.LayoutMode)
                {
                    return;
                }

                // On iOS we make these the same, so ignore changes between them
                if ((_prevLayoutMode.Value == ScheduleViewModel.LayoutModes.FullEditing || _prevLayoutMode.Value == ScheduleViewModel.LayoutModes.SplitEditing) &&
                    (ViewModel.LayoutMode == ScheduleViewModel.LayoutModes.FullEditing || ViewModel.LayoutMode == ScheduleViewModel.LayoutModes.SplitEditing))
                {
                    return;
                }

                switch (_prevLayoutMode.Value)
                {
                case ScheduleViewModel.LayoutModes.SplitEditing:
                case ScheduleViewModel.LayoutModes.FullEditing:
                    _editingView.RemoveFromSuperview();
                    break;

                case ScheduleViewModel.LayoutModes.Welcome:
                    _welcomeView.RemoveFromSuperview();
                    break;
                }
            }

            _prevLayoutMode = ViewModel.LayoutMode;

            if (ViewModel.LayoutMode == ScheduleViewModel.LayoutModes.Normal)
            {
                NavItem.RightBarButtonItem = _editButton;
                Title = "Schedule";
            }
            else if (ViewModel.LayoutMode == ScheduleViewModel.LayoutModes.SplitEditing ||
                     ViewModel.LayoutMode == ScheduleViewModel.LayoutModes.FullEditing)
            {
                if (_editingView == null)
                {
                    _editingView = new UIScrollView()
                    {
                        TranslatesAutoresizingMaskIntoConstraints = false,
                        ShowsHorizontalScrollIndicator            = false,
                        BackgroundColor = UIColor.White
                    };
                    var actualEditingView = new UIScheduleEditingView(ViewModel);
                    _editingView.Add(actualEditingView);
                    actualEditingView.ConfigureForVerticalScrolling(_editingView, top: 16, bottom: 16);

                    MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate
                    {
                        _editingView.ContentInset = new UIEdgeInsets(0, 0, MainScreenViewController.TAB_BAR_HEIGHT, 0);
                    });
                }

                ContentView.Add(_editingView);
                _editingView.StretchWidthAndHeight(ContentView);

                NavItem.RightBarButtonItem = _doneButton;
                Title = "Edit Schedule";
            }
            else
            {
                if (_welcomeView == null)
                {
                    _welcomeView = new UIView()
                    {
                        TranslatesAutoresizingMaskIntoConstraints = false,
                        BackgroundColor = UIColor.White
                    };
                    {
                        // New user
                        var topSpacer = new UIView()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false
                        };
                        _welcomeView.Add(topSpacer);
                        topSpacer.StretchWidth(_welcomeView);

                        var bottomSpacer = new UIView()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false
                        };
                        _welcomeView.Add(bottomSpacer);
                        bottomSpacer.StretchWidth(_welcomeView);

                        var title = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            Text = "Welcome to Power Planner!",
                            AdjustsFontSizeToFitWidth = true,
                            Font          = UIFont.PreferredTitle3,
                            TextAlignment = UITextAlignment.Center
                        };
                        _welcomeView.Add(title);
                        title.StretchWidth(_welcomeView, left: 16, right: 16);

                        var subtitle = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            Text          = "To get started, add your classes and schedule!",
                            Lines         = 0,
                            Font          = UIFont.PreferredCaption1,
                            TextAlignment = UITextAlignment.Center
                        };
                        _welcomeView.Add(subtitle);
                        subtitle.StretchWidth(_welcomeView, left: 16, right: 16);

                        var buttonAddClass = new UIButton(UIButtonType.System)
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false
                        };
                        buttonAddClass.SetTitle("Add Class", UIControlState.Normal);
                        buttonAddClass.SetTitleColor(new UIColor(1, 1), UIControlState.Normal);
                        buttonAddClass.BackgroundColor = ColorResources.PowerPlannerAccentBlue;
                        buttonAddClass.TouchUpInside  += new WeakEventHandler <EventArgs>(delegate { ViewModel.AddClass(); }).Handler;
                        _welcomeView.Add(buttonAddClass);
                        buttonAddClass.StretchWidth(_welcomeView, left: 16, right: 16);
                        buttonAddClass.SetMaxWidth(250);

                        _welcomeView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[topSpacer(==bottomSpacer)][title]-8-[subtitle]-16-[buttonAddClass][bottomSpacer]-32-|", NSLayoutFormatOptions.DirectionLeadingToTrailing,
                                                                                        "topSpacer", topSpacer,
                                                                                        "title", title,
                                                                                        "subtitle", subtitle,
                                                                                        "buttonAddClass", buttonAddClass,
                                                                                        "bottomSpacer", bottomSpacer));

                        // Returning user (we add on top so it remains clickable
                        if (ViewModel.IsReturningUserVisible)
                        {
                            var returningUser = new UILabel()
                            {
                                TranslatesAutoresizingMaskIntoConstraints = false,
                                Text = PowerPlannerResources.GetString("SchedulePage_TextBlockReturningUser.Text"),
                                Font = UIFont.PreferredCaption1
                            };
                            _welcomeView.Add(returningUser);
                            returningUser.StretchWidth(_welcomeView, left: 16, right: 16);

                            var buttonLogIn = PowerPlannerUIHelper.CreatePowerPlannerBlueButton("Log In");
                            buttonLogIn.TranslatesAutoresizingMaskIntoConstraints = false;
                            buttonLogIn.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.LogIn(); }).Handler;
                            _welcomeView.Add(buttonLogIn);
                            buttonLogIn.PinToLeft(_welcomeView, left: 16);

                            _welcomeView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-16-[returningUser]-8-[buttonLogIn]", NSLayoutFormatOptions.DirectionLeadingToTrailing,
                                                                                            "returningUser", returningUser,
                                                                                            "buttonLogIn", buttonLogIn));
                        }
                    }
                }

                // Display the welcome view on top of everything, including on top of the nav bar
                ContentView.Add(_welcomeView);
                _welcomeView.StretchWidth(ContentView);

                NavItem.RightBarButtonItem = null;
                Title = "Edit Schedule";

                MainScreenViewController.ListenToTabBarHeightChanged(ref _welcomeViewTabBarHeightListener, delegate
                {
                    _welcomeView.StretchHeight(ContentView, top: 0, bottom: (float)MainScreenViewController.TAB_BAR_HEIGHT);
                });
            }
        }
Esempio n. 7
0
        public override void OnViewModelLoadedOverride()
        {
            _loadingIndicator.StopAnimating();
            _loadingIndicator.RemoveFromSuperview();
            _loadingIndicator = null;

            _schoolBindingHost = new BindingHost()
            {
                BindingObject = ViewModel.YearsViewItemsGroup.School
            };

            var overallText = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Font = UIFont.PreferredTitle1,
                AdjustsFontSizeToFitWidth = true,
                Lines = 1
            };
            Action updateOverallText = delegate
            {
                overallText.Text = "Overall: " + GpaToStringConverter.Convert(ViewModel.YearsViewItemsGroup.School.GPA, includeGpa: true) + " / " + CreditsToStringConverter.Convert(ViewModel.YearsViewItemsGroup.School.CreditsEarned, includeCredits: true);
            };

            _schoolBindingHost.SetBinding(nameof(ViewModel.YearsViewItemsGroup.School.GPA), updateOverallText);
            _schoolBindingHost.SetBinding(nameof(ViewModel.YearsViewItemsGroup.School.CreditsEarned), updateOverallText);
            StackView.AddArrangedSubview(overallText);
            overallText.StretchWidth(StackView);

            StackView.AddArrangedSubview(new UIView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            }.SetHeight(16));

            var stackViewYears = new UIStackView()
            {
                Axis = UILayoutConstraintAxis.Vertical,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 16
            };

            _itemsSourceYears = new BareUIStackViewItemsSourceAdapter <UIYearView>(stackViewYears);
            _itemsSourceYears.OnViewCreated += _itemsSourceYears_OnViewCreated;
            _itemsSourceYears.ItemsSource    = ViewModel.YearsViewItemsGroup.School.Years;
            StackView.AddArrangedSubview(stackViewYears);
            stackViewYears.StretchWidth(StackView);

            StackView.AddSpacing(16);

            var buttonAddYear = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            buttonAddYear.SetTitle("Add Year", UIControlState.Normal);
            buttonAddYear.TouchUpInside += new WeakEventHandler(delegate { ViewModel.AddYear(); }).Handler;
            StackView.AddArrangedSubview(buttonAddYear);
            buttonAddYear.StretchWidth(StackView);

            MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate
            {
                _scrollView.ContentInset = new UIEdgeInsets(0, 0, MainScreenViewController.TAB_BAR_HEIGHT, 0);
            });

            base.OnViewModelLoadedOverride();
        }