Exemplo n.º 1
0
        private void InitializeViews()
        {
            base.TranslatesAutoresizingMaskIntoConstraints = false;
            base.BackgroundColor = new UIColor(247f / 255f, 1);

            // [ [labelName] [labelDates] ]
            // [ [class] [credits] [gpa]  ]
            // [ stackViewClasses         ]
            // [ buttonOpenSemester       ]

            // stackView
            // + viewNameAndDates
            //   + labelName
            //   + labelDates
            // + stackViewClassesTable
            //   + viewClassesTableHeader
            //     + labelHeaderClass
            //     + labelHeaderCredits
            //     + labelHeaderGpa
            //   + stackViewClasses
            //   + viewClassesTableFooter
            //     + labelTotal
            //     + labelTotalCredits
            //     + labelTotalGpa
            // + buttonAddSemester

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

            // Name and dates
            var viewNameAndDates = new UIControl()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            viewNameAndDates.TouchUpInside += new WeakEventHandler(delegate { OnRequestEditSemester?.Invoke(this, DataContext as ViewItemSemester); }).Handler;
            {
                var labelName = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
                BindingHost.SetLabelTextBinding(labelName, nameof(ViewItemSemester.Name));
                viewNameAndDates.AddSubview(labelName);

                var labelDates = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Font          = UIFont.PreferredCaption2,
                    TextColor     = UIColor.DarkGray,
                    Lines         = 0,
                    TextAlignment = UITextAlignment.Right
                };
                BindingHost.SetLabelTextBinding(labelDates, nameof(ViewItemSemester.Start), delegate
                {
                    return(SemesterToSemesterViewStartEndStringConverter.Convert(DataContext as ViewItemSemester));
                });
                viewNameAndDates.AddSubview(labelDates);

                viewNameAndDates.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[labelName]->=6-[labelDates]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                                        "labelName", labelName,
                                                                                        "labelDates", labelDates)));
                labelName.StretchHeight(viewNameAndDates);
                labelDates.StretchHeight(viewNameAndDates);
            }
            stackView.AddArrangedSubview(viewNameAndDates);
            viewNameAndDates.StretchWidth(stackView);

            // Table
            var classesTouchContainer = new UIControl()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            classesTouchContainer.TouchUpInside += new WeakEventHandler(delegate { OnRequestOpenSemester?.Invoke(this, DataContext as ViewItemSemester); }).Handler;
            {
                var stackViewClassesTable = new UIStackView()
                {
                    Axis = UILayoutConstraintAxis.Vertical,
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
                {
                    // Table header
                    var viewClassesTableHeader = new UIView()
                    {
                        TranslatesAutoresizingMaskIntoConstraints = false
                    };
                    {
                        var labelHeaderClass = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            Text      = "Class",
                            Font      = UIFont.PreferredCaption2,
                            TextColor = UIColor.DarkGray
                        };
                        viewClassesTableHeader.AddSubview(labelHeaderClass);

                        var labelHeaderCredits = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            Font          = UIFont.PreferredCaption2,
                            Text          = "Credits",
                            TextColor     = UIColor.DarkGray,
                            TextAlignment = UITextAlignment.Right
                        };
                        viewClassesTableHeader.AddSubview(labelHeaderCredits);

                        var labelHeaderGpa = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            Font          = UIFont.PreferredCaption2,
                            Text          = "GPA",
                            TextColor     = UIColor.DarkGray,
                            TextAlignment = UITextAlignment.Right
                        };
                        viewClassesTableHeader.AddSubview(labelHeaderGpa);

                        viewClassesTableHeader.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[labelHeaderClass]->=6-[labelHeaderCredits(50)]-6-[labelHeaderGpa(50)]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                                                      "labelHeaderClass", labelHeaderClass,
                                                                                                      "labelHeaderCredits", labelHeaderCredits,
                                                                                                      "labelHeaderGpa", labelHeaderGpa)));
                        labelHeaderClass.StretchHeight(viewClassesTableHeader);
                        labelHeaderCredits.StretchHeight(viewClassesTableHeader);
                        labelHeaderGpa.StretchHeight(viewClassesTableHeader);
                    }
                    stackViewClassesTable.AddArrangedSubview(viewClassesTableHeader);
                    viewClassesTableHeader.StretchWidth(stackViewClassesTable);

                    // Classes stack view
                    var stackViewClasses = new UIStackView()
                    {
                        Axis = UILayoutConstraintAxis.Vertical,
                        TranslatesAutoresizingMaskIntoConstraints = false
                    };
                    _itemsSourceClasses = new BareUIStackViewItemsSourceAdapter <UIClassView>(stackViewClasses);
                    stackViewClassesTable.AddArrangedSubview(stackViewClasses);
                    stackViewClasses.StretchWidth(stackViewClassesTable);

                    // Totals
                    var viewClassesTableFooter = new UIView()
                    {
                        TranslatesAutoresizingMaskIntoConstraints = false
                    };
                    {
                        var labelTotal = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            Text = "Total",
                            Font = UIFont.PreferredFootnote
                        };
                        viewClassesTableFooter.AddSubview(labelTotal);

                        var labelTotalCredits = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            TextAlignment = UITextAlignment.Right,
                            Font          = UIFont.PreferredFootnote
                        };
                        BindingHost.SetLabelTextBinding <double>(labelTotalCredits, nameof(ViewItemSemester.CreditsEarned), (credits) =>
                        {
                            return(CreditsToStringConverter.Convert(credits));
                        });
                        viewClassesTableFooter.AddSubview(labelTotalCredits);

                        var labelTotalGpa = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            TextAlignment = UITextAlignment.Right,
                            Font          = UIFont.PreferredFootnote
                        };
                        BindingHost.SetLabelTextBinding <double>(labelTotalGpa, nameof(ViewItemSemester.GPA), (gpa) =>
                        {
                            return(GpaToStringConverter.Convert(gpa));
                        });
                        viewClassesTableFooter.AddSubview(labelTotalGpa);

                        viewClassesTableFooter.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[labelTotal]->=6-[labelTotalCredits(50)]-6-[labelTotalGpa(50)]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                                                      "labelTotal", labelTotal,
                                                                                                      "labelTotalCredits", labelTotalCredits,
                                                                                                      "labelTotalGpa", labelTotalGpa)));
                        labelTotal.StretchHeight(viewClassesTableFooter);
                        labelTotalCredits.StretchHeight(viewClassesTableFooter);
                        labelTotalGpa.StretchHeight(viewClassesTableFooter);
                    }
                    stackViewClassesTable.AddArrangedSubview(viewClassesTableFooter);
                    viewClassesTableFooter.StretchWidth(stackViewClassesTable);
                }
                classesTouchContainer.Add(stackViewClassesTable);
                stackViewClassesTable.StretchWidthAndHeight(classesTouchContainer);
            }
            stackView.AddArrangedSubview(classesTouchContainer);
            classesTouchContainer.StretchWidth(stackView);

            // Add semester button
            var buttonOpenSemester = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            buttonOpenSemester.SetTitle("Open Semester", UIControlState.Normal);
            buttonOpenSemester.TouchUpInside += new WeakEventHandler(ButtonOpenSemester_TouchUpInside).Handler;
            stackView.AddArrangedSubview(buttonOpenSemester);
            buttonOpenSemester.StretchWidth(stackView);

            base.AddSubview(stackView);
            stackView.StretchWidthAndHeight(this, top: 6, bottom: 6, left: 8, right: 8);
        }
Exemplo n.º 2
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();
        }