public override void OnViewModelLoadedOverride()
        {
            AddTopSectionDivider();

            AddSpacing(8);
            var label = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text  = "Are you sure you want to delete your account?",
                Lines = 0
            };

            StackView.AddArrangedSubview(label);
            label.StretchWidth(StackView, left: 16, right: 16);
            AddSpacing(8);

            AddDivider();

            var switchDeleteOnline = new BareUISwitch()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Header = "Delete online account"
            };

            BindingHost.SetSwitchBinding(switchDeleteOnline, nameof(ViewModel.DeleteOnlineAccountToo));
            StackView.AddArrangedSubview(switchDeleteOnline);
            switchDeleteOnline.StretchWidth(StackView);
            switchDeleteOnline.SetHeight(44);

            AddSectionDivider();

            var buttonDelete = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TintColor = UIColor.Red
            };

            buttonDelete.TouchUpInside += new WeakEventHandler <EventArgs>(async delegate
            {
                try
                {
                    ShowLoadingOverlay();
                    await ViewModel.DeleteAsync();
                }
                catch { }

                HideLoadingOverlay();
            }).Handler;
            buttonDelete.SetTitle("Yes, Delete Account", UIControlState.Normal);
            StackView.AddArrangedSubview(buttonDelete);
            buttonDelete.StretchWidth(StackView);
            buttonDelete.SetHeight(44);

            AddBottomSectionDivider();

            base.OnViewModelLoadedOverride();
        }
Example #2
0
        private void AddSwitch(string header, string bindingName)
        {
            var container = new BareUISwitch()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Header = header
            };

            BindingHost.SetSwitchBinding(container, bindingName);
            StackView.AddArrangedSubview(container);
            container.StretchWidth(StackView);
            container.SetHeight(44);
        }
Example #3
0
        protected override ModalEditViewController CreateModalEditViewController(UIViewController parent)
        {
            var scrollView = new UIScrollView()
            {
                // Note that only height matters, the width values will be overwritten
                Frame = new CoreGraphics.CGRect(0, 0, 0, 340)
            };

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

            scrollView.AddSubview(stackView);
            stackView.ConfigureForVerticalScrolling(scrollView, top: 8, bottom: 16);

            _switches = new Tuple <DayOfWeek, BareUISwitch> [7];

            DayOfWeek day = DayOfWeek.Monday;

            for (int i = 0; i < _switches.Length; i++, day = (DayOfWeek)(((int)day + 1) % 7))
            {
                var daySwitch = new BareUISwitch()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Header = DateTools.ToLocalizedString(day)
                };
                _switches[i] = new Tuple <DayOfWeek, BareUISwitch>(day, daySwitch);
                stackView.AddArrangedSubview(daySwitch);
                daySwitch.StretchWidth(stackView);
                daySwitch.SetHeight(44);

                if (i != _switches.Length - 1)
                {
                    stackView.AddDivider();
                }
            }

            return(new ModalEditViewController(scrollView, HeaderText, parent));
        }
        public override void OnViewModelLoadedOverride()
        {
            Title = ViewModel.State == AddHomeworkViewModel.OperationState.Adding ?
                    ViewModel.Type == AddHomeworkViewModel.ItemType.Homework ? "Add Task" : "Add Event"
                : ViewModel.Type == AddHomeworkViewModel.ItemType.Homework ? "Edit Task" : "Edit Event";

            AddTopSectionDivider();

            AddTextField(new UITextField()
            {
                Placeholder   = "Name",
                ReturnKeyType = UIReturnKeyType.Done,
                EnablesReturnKeyAutomatically = true
            }, nameof(ViewModel.Name), firstResponder: ViewModel.State == AddHomeworkViewModel.OperationState.Adding);

            AddDivider();

            var dateContainer = new UIStackView()
            {
                Axis = UILayoutConstraintAxis.Vertical
            };

            {
                var datePicker = new BareUIInlineDatePicker(this, left: 16, right: 16)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
                BindingHost.SetDateBinding(datePicker, nameof(ViewModel.Date));
                dateContainer.AddArrangedSubview(datePicker);
                datePicker.StretchWidth(dateContainer);
                datePicker.SetHeight(44);

                AddDivider(dateContainer);
            }
            AddUnderVisiblity(dateContainer, nameof(ViewModel.IsDatePickerVisible));

            var classContainer = new UIStackView()
            {
                Axis = UILayoutConstraintAxis.Vertical
            };

            {
                var pickerClass = new BareUIInlinePickerView(this, left: 16, right: 16)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HeaderText          = "Class",
                    ItemToViewConverter = ConvertClassToInlineView
                };
                BindingHost.SetItemsSourceBinding(pickerClass, nameof(ViewModel.Classes));
                BindingHost.SetSelectedItemBinding(pickerClass, nameof(ViewModel.Class));
                classContainer.AddArrangedSubview(pickerClass);
                pickerClass.StretchWidth(classContainer);
                pickerClass.SetHeight(44);

                AddDivider(classContainer);
            }
            AddUnderVisiblity(classContainer, nameof(ViewModel.IsClassPickerVisible));

            var gradeWeightContainer = new UIStackView()
            {
                Axis = UILayoutConstraintAxis.Vertical
            };

            {
                var pickerGradeWeight = new BareUIInlinePickerView(this, left: 16, right: 16)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HeaderText = "Grade Category"
                };
                BindingHost.SetItemsSourceBinding(pickerGradeWeight, nameof(ViewModel.WeightCategories));
                BindingHost.SetSelectedItemBinding(pickerGradeWeight, nameof(ViewModel.SelectedWeightCategory));
                gradeWeightContainer.AddArrangedSubview(pickerGradeWeight);
                pickerGradeWeight.StretchWidth(gradeWeightContainer);
                pickerGradeWeight.SetHeight(44);

                AddDivider(gradeWeightContainer);
            }
            AddUnderVisiblity(gradeWeightContainer, nameof(ViewModel.IsWeightCategoryPickerVisible));

            var pickerTime = new BareUIInlinePickerView(this, left: 16, right: 16)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                HeaderText = "Time"
            };

            BindingHost.SetItemsSourceBinding(pickerTime, nameof(ViewModel.TimeOptions));
            BindingHost.SetSelectedItemBinding(pickerTime, nameof(ViewModel.SelectedTimeOption));
            StackView.AddArrangedSubview(pickerTime);
            pickerTime.StretchWidth(StackView);
            pickerTime.SetHeight(44);

            var stackViewPickerCustomTime = new UIStackView()
            {
                Axis = UILayoutConstraintAxis.Vertical
            };

            AddDivider(stackViewPickerCustomTime);
            if (ViewModel.Type == AddHomeworkViewModel.ItemType.Homework)
            {
                var pickerDueTime = new BareUIInlineTimePicker(this, left: 16, right: 16)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HeaderText = "Due Time"
                };
                BindingHost.SetTimeBinding(pickerDueTime, nameof(ViewModel.StartTime));
                stackViewPickerCustomTime.AddArrangedSubview(pickerDueTime);
                pickerDueTime.StretchWidth(stackViewPickerCustomTime);
                pickerDueTime.SetHeight(44);
            }
            else
            {
                var pickerStartTime = new BareUIInlineTimePicker(this, left: 16, right: 16)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HeaderText = "Start Time"
                };
                BindingHost.SetTimeBinding(pickerStartTime, nameof(ViewModel.StartTime));
                stackViewPickerCustomTime.AddArrangedSubview(pickerStartTime);
                pickerStartTime.StretchWidth(stackViewPickerCustomTime);
                pickerStartTime.SetHeight(44);

                AddDivider(stackViewPickerCustomTime);

                var pickerEndTime = new BareUIInlineTimePicker(this, left: 16, right: 16)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HeaderText = "End Time"
                };
                BindingHost.SetTimeBinding(pickerEndTime, nameof(ViewModel.EndTime));
                stackViewPickerCustomTime.AddArrangedSubview(pickerEndTime);
                pickerEndTime.StretchWidth(stackViewPickerCustomTime);
                pickerEndTime.SetHeight(44);
            }
            var pickerCustomTimeContainer = new BareUIVisibilityContainer()
            {
                Child = stackViewPickerCustomTime
            };

            BindingHost.SetVisibilityBinding(pickerCustomTimeContainer, nameof(ViewModel.IsStartTimePickerVisible));
            StackView.AddArrangedSubview(pickerCustomTimeContainer);
            pickerCustomTimeContainer.StretchWidth(StackView);

            AddSectionDivider();

            var detailsView = new BareUITextView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder = "Details"
            };

            BindingHost.SetTextViewTextBinding(detailsView.TextView, nameof(ViewModel.Details));
            StackView.AddArrangedSubview(detailsView);
            detailsView.StretchWidth(StackView);
            detailsView.SetHeight(130);

            if (ViewModel.IsRepeatsVisible)
            {
                AddSectionDivider();

                var switchRepeats = new BareUISwitch()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Header = PowerPlannerResources.GetString("RepeatingEntry_CheckBoxRepeats.Content")
                };
                BindingHost.SetSwitchBinding(switchRepeats, nameof(ViewModel.Repeats));
                StackView.AddArrangedSubview(switchRepeats);
                switchRepeats.StretchWidth(StackView);
                switchRepeats.SetHeight(44);

                StackView.AddUnderLazyVisibility(BindingHost, nameof(ViewModel.Repeats), delegate
                {
                    var recurrenceContainer = new UIStackView()
                    {
                        Axis = UILayoutConstraintAxis.Vertical
                    };
                    {
                        recurrenceContainer.AddDivider();

                        var tryForFreeContainer = new UIStackView()
                        {
                            Axis = UILayoutConstraintAxis.Vertical
                        };
                        {
                            tryForFreeContainer.AddSpacing(16);
                            var tryForFreeLabel = new UILabel()
                            {
                                TranslatesAutoresizingMaskIntoConstraints = false,
                                Text      = PowerPlannerResources.GetString("RepeatingEntry_TextBlockTryForFree.Text"),
                                Font      = UIFont.PreferredCaption1,
                                TextColor = UIColor.Red,
                                Lines     = 0
                            };
                            tryForFreeContainer.AddArrangedSubview(tryForFreeLabel);
                            tryForFreeLabel.StretchWidth(tryForFreeContainer, left: 16, right: 16);
                            tryForFreeContainer.AddSpacing(16);

                            tryForFreeContainer.AddDivider();
                        }
                        recurrenceContainer.AddUnderVisiblity(tryForFreeContainer, BindingHost, nameof(ViewModel.ShowRepeatingPremiumTrial));

                        var mustUpgradeContainer = new UIStackView()
                        {
                            Axis = UILayoutConstraintAxis.Vertical
                        };
                        {
                            mustUpgradeContainer.AddSpacing(16);
                            var mustUpgradeLabel = new UILabel()
                            {
                                TranslatesAutoresizingMaskIntoConstraints = false,
                                Text      = PowerPlannerResources.GetString("RepeatingEntry_TextBlockMustUpgrade.Text"),
                                Font      = UIFont.PreferredCaption1,
                                TextColor = UIColor.Red,
                                Lines     = 0
                            };
                            mustUpgradeContainer.AddArrangedSubview(mustUpgradeLabel);
                            mustUpgradeLabel.StretchWidth(mustUpgradeContainer, left: 16, right: 16);
                            mustUpgradeContainer.AddSpacing(8);

                            var buttonUpgrade = PowerPlannerUIHelper.CreatePowerPlannerBlueButton(PowerPlannerResources.GetString("Settings_UpgradeToPremium_ButtonUpgrade.Content"));
                            buttonUpgrade.TranslatesAutoresizingMaskIntoConstraints = false;
                            buttonUpgrade.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.UpgradeToPremiumForRepeating(); }).Handler;
                            mustUpgradeContainer.AddArrangedSubview(buttonUpgrade);
                            buttonUpgrade.StretchWidth(mustUpgradeContainer, left: 16, right: 16);
                            mustUpgradeContainer.AddSpacing(16);

                            mustUpgradeContainer.AddDivider();
                        }
                        recurrenceContainer.AddUnderVisiblity(mustUpgradeContainer, BindingHost, nameof(ViewModel.ShowRepeatingMustUpgradeToPremium));

                        var recurrenceView = new UIRecurrenceView(this)
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            ViewModel = ViewModel.RecurrenceControlViewModel
                        };
                        BindingHost.SetIsEnabledBinding(recurrenceView, nameof(ViewModel.IsRepeatingEntryEnabled));
                        recurrenceContainer.AddArrangedSubview(recurrenceView);
                        recurrenceView.StretchWidth(recurrenceContainer);

                        recurrenceContainer.AddDivider();

                        recurrenceContainer.AddSpacing(16);
                        var labelNoteCannotBulkEdit = new UILabel()
                        {
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            Text      = PowerPlannerResources.GetString("RepeatingEntry_TextBlockNoteCannotBulkEdit.Text"),
                            Font      = UIFont.PreferredCaption1,
                            TextColor = UIColor.LightGray,
                            Lines     = 0
                        };
                        recurrenceContainer.AddArrangedSubview(labelNoteCannotBulkEdit);
                        labelNoteCannotBulkEdit.StretchWidth(recurrenceContainer, left: 16, right: 16);
                        recurrenceContainer.AddSpacing(16);
                    }
                    return(recurrenceContainer);
                });
            }

            AddBottomSectionDivider();

            BackButtonText       = "Cancel";
            PositiveNavBarButton = new PopupRightNavBarButtonItem("Save", delegate { Save(); });

            base.OnViewModelLoadedOverride();
        }
        public override void OnViewModelLoadedOverride()
        {
            Title = ViewModel.State == AddGradeViewModel.OperationState.Adding ? "Add Grade" : "Edit Grade";

            AddTopSectionDivider();

            AddTextField(new UITextField()
            {
                Placeholder   = "Name",
                ReturnKeyType = UIReturnKeyType.Done,
                EnablesReturnKeyAutomatically = true
            }, nameof(ViewModel.Name), firstResponder: ViewModel.State == AddGradeViewModel.OperationState.Adding);

            AddDivider();

            base.OnViewModelLoadedOverride();

            // Grade received, grade total, and percent
            var gradesView = new UIView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            {
                var textFieldReceived = new UITextField()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    ReturnKeyType             = UIReturnKeyType.Next,
                    KeyboardType              = UIKeyboardType.DecimalPad,
                    AdjustsFontSizeToFitWidth = true
                                                // TODO: Wire up Next button on keyboard by using ShouldReturn
                };
                BindingHost.SetTextFieldTextBinding <double>(textFieldReceived, nameof(ViewModel.GradeReceived), converter: GradeToTextBoxTextConverter.Convert, backConverter: GradeToTextBoxTextConverter.ConvertBack);
                if (ViewModel.State == AddGradeViewModel.OperationState.Editing && ViewModel.GradeReceived == Grade.UNGRADED)
                {
                    // When assigning grades to tasks, the empty grade becomes the first responder
                    textFieldReceived.BecomeFirstResponder();
                }
                gradesView.Add(textFieldReceived);
                textFieldReceived.StretchHeight(gradesView);

                var labelOutOf = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text = "out of",
                    Font = UIFont.PreferredCaption1
                };
                gradesView.Add(labelOutOf);
                labelOutOf.StretchHeight(gradesView);

                var textFieldTotal = new UITextField()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    ReturnKeyType             = UIReturnKeyType.Next,
                    KeyboardType              = UIKeyboardType.DecimalPad,
                    AdjustsFontSizeToFitWidth = true
                                                // TODO: Wire up Next button on keyboard
                };
                BindingHost.SetTextFieldTextBinding <double>(textFieldTotal, nameof(ViewModel.GradeTotal), converter: GradeToTextBoxTextConverter.Convert, backConverter: GradeToTextBoxTextConverter.ConvertBack);
                gradesView.Add(textFieldTotal);
                textFieldTotal.StretchHeight(gradesView);

                var labelPercent = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Font = UIFont.PreferredBody
                };
                BindingHost.SetLabelTextBinding(labelPercent, nameof(ViewModel.GradePercent));
                gradesView.Add(labelPercent);
                labelPercent.StretchHeight(gradesView);

                gradesView.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[received(46)]-4-[outOf]-4-[total(46)]->=0-[percent]|", NSLayoutFormatOptions.DirectionLeadingToTrailing,
                                                                              "received", textFieldReceived,
                                                                              "outOf", labelOutOf,
                                                                              "total", textFieldTotal,
                                                                              "percent", labelPercent));
            }
            StackView.AddArrangedSubview(gradesView);
            gradesView.StretchWidth(StackView, left: 16, right: 16);
            gradesView.SetHeight(44);

            AddDivider();

            var datePicker = new BareUIInlineDatePicker(this, left: 16, right: 16)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            BindingHost.SetDateBinding(datePicker, nameof(ViewModel.Date));
            StackView.AddArrangedSubview(datePicker);
            datePicker.StretchWidth(StackView);
            datePicker.SetHeight(44);

            AddDivider();

            var pickerGradeWeight = new BareUIInlinePickerView(this, left: 16, right: 16)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                HeaderText = "Weight Category"
            };

            BindingHost.SetItemsSourceBinding(pickerGradeWeight, nameof(ViewModel.WeightCategories));
            BindingHost.SetSelectedItemBinding(pickerGradeWeight, nameof(ViewModel.SelectedWeightCategory));
            StackView.AddArrangedSubview(pickerGradeWeight);
            pickerGradeWeight.StretchWidth(StackView);
            pickerGradeWeight.SetHeight(44);

            AddDivider();

            var container = new BareUISwitch()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Header = "Is Dropped"
            };

            BindingHost.SetSwitchBinding(container, nameof(ViewModel.IsDropped));
            StackView.AddArrangedSubview(container);
            container.StretchWidth(StackView);
            container.SetHeight(44);

            AddDivider();

            var detailsView = new BareUITextView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder = "Details"
            };

            BindingHost.SetTextViewTextBinding(detailsView.TextView, nameof(ViewModel.Details));
            StackView.AddArrangedSubview(detailsView);
            detailsView.StretchWidth(StackView);
            detailsView.SetHeight(130);

            AddBottomSectionDivider();

            BackButtonText       = "Cancel";
            PositiveNavBarButton = new PopupRightNavBarButtonItem("Save", delegate { Save(); });
        }
        public override void OnViewModelLoadedOverride()
        {
            Title = ViewModel.State == AddClassViewModel.OperationState.Adding ? "Add Class" : "Edit Class";

            AddTopSectionDivider();

            AddTextField(new UITextField()
            {
                Placeholder   = "Name",
                ReturnKeyType = UIReturnKeyType.Done,
                EnablesReturnKeyAutomatically = true
            }, nameof(ViewModel.Name), firstResponder: ViewModel.State == AddClassViewModel.OperationState.Adding);

            AddDivider();

            var colorPicker = new BareUIInlineColorPickerView(this, left: 16, right: 16)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                AvailableColors = ColorItem.DefaultColors.Select(i => new BareUIInlineColorPickerView.ColorItem(i.Text, BareUIHelper.ToCGColor(i.Color)))
            };

            StackView.AddArrangedSubview(colorPicker);
            colorPicker.StretchWidth(StackView);
            colorPicker.SetHeight(44);
            BindingHost.SetSelectedColorBinding(colorPicker, nameof(ViewModel.Color));

            AddSectionDivider();

            var partialSemesterSwitch = new BareUISwitch()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Header = "Partial semester class?"
            };

            BindingHost.SetSwitchBinding(partialSemesterSwitch, nameof(ViewModel.IsPartialSemesterClass));
            StackView.AddArrangedSubview(partialSemesterSwitch);
            partialSemesterSwitch.StretchWidth(StackView);
            partialSemesterSwitch.SetHeight(44);

            var stackViewStartEndDates = new UIStackView()
            {
                Axis = UILayoutConstraintAxis.Vertical
            };

            {
                AddDivider(stackViewStartEndDates);

                var startDatePicker = new BareUIInlineDatePicker(this, left: 16, right: 16)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HeaderText = "Start Date"
                };
                BindingHost.SetDateBinding(startDatePicker, nameof(ViewModel.StartDate));
                stackViewStartEndDates.AddArrangedSubview(startDatePicker);
                startDatePicker.StretchWidth(stackViewStartEndDates);
                startDatePicker.SetHeight(44);

                AddDivider(stackViewStartEndDates);

                var endDatePicker = new BareUIInlineDatePicker(this, left: 16, right: 16)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HeaderText = "End Date"
                };
                BindingHost.SetDateBinding(endDatePicker, nameof(ViewModel.EndDate));
                stackViewStartEndDates.AddArrangedSubview(endDatePicker);
                endDatePicker.StretchWidth(stackViewStartEndDates);
                endDatePicker.SetHeight(44);
            }
            AddUnderVisiblity(stackViewStartEndDates, nameof(ViewModel.IsPartialSemesterClass));

            AddSectionDivider();

            if (ViewModel.IncludesEditingDetails)
            {
                var detailsView = new BareUITextView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Placeholder = "Details"
                };
                BindingHost.SetTextViewTextBinding(detailsView.TextView, nameof(ViewModel.Details));
                StackView.AddArrangedSubview(detailsView);
                detailsView.StretchWidth(StackView);
                detailsView.SetHeight(130);

                AddSectionDivider();
            }

            AddDeleteButtonWithConfirmation("Delete Class", ViewModel.Delete, "Delete class?", "Are you sure you want to delete this class and all of its items?");

            AddBottomSectionDivider();

            BackButtonText       = "Cancel";
            PositiveNavBarButton = new PopupRightNavBarButtonItem("Save", delegate { Save(); });

            base.OnViewModelLoadedOverride();
        }