public ConfigureClassGradesListViewController() { AutomaticallyAdjustsScrollViewInsets = false; // Set title to class name m_classBindingHost.SetBinding(nameof(ViewModel.Class.Name), delegate { Title = ViewModel.Class.Name; }); // Creating a table view programmatically: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW4 // Xamarin: https://developer.xamarin.com/guides/ios/user_interface/controls/tables/populating-a-table-with-data/ _tableView = new BareUIStaticGroupedTableView() { TranslatesAutoresizingMaskIntoConstraints = false }; View.Add(_tableView); _tableView.StretchWidthAndHeight(View); var backButton = new UIBarButtonItem() { Title = "Back" }; backButton.Clicked += new WeakEventHandler <EventArgs>(BackButton_Clicked).Handler; NavigationItem.LeftBarButtonItem = backButton; }
public override void OnViewModelLoadedOverride() { _tableView.Source = new TableViewSource(_tableView, ViewModel); var labelNothingHere = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Lines = 0, Font = UIFont.PreferredCallout, Text = "No tasks! Tap the \"+\" button in the top right to add tasks and events.", TextColor = UIColor.LightGray, TextAlignment = UITextAlignment.Center, Hidden = true }; View.Add(labelNothingHere); labelNothingHere.StretchWidth(View, left: 32, right: 32); labelNothingHere.StretchHeight(View, top: 16, bottom: 16); BindingHost.SetBinding(nameof(ViewModel.HasNoItems), delegate { labelNothingHere.Hidden = !ViewModel.HasNoItems; }); base.OnViewModelLoadedOverride(); }
public ClassDetailsViewController() { Title = "Details"; var labelDetails = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Lines = 0, Font = UIFont.PreferredBody }; BindingHost.SetLabelTextBinding(labelDetails, nameof(ViewModel.Details)); StackView.AddArrangedSubview(labelDetails); labelDetails.StretchWidth(StackView); var labelNothingHere = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Lines = 0, Font = UIFont.PreferredCallout, Text = "Tap the edit button in the top right to add details like the teacher's contact info, office hours, and anything else!", TextColor = UIColor.LightGray, TextAlignment = UITextAlignment.Center }; View.Add(labelNothingHere); labelNothingHere.StretchWidth(View, left: 16, right: 16); labelNothingHere.StretchHeight(View, top: 16, bottom: 16); BindingHost.SetBinding(nameof(ViewModel.Details), delegate { labelNothingHere.Hidden = !string.IsNullOrWhiteSpace(ViewModel.Details); }); }
public override void OnViewModelLoadedOverride() { AddTopSectionDivider(); AddSpacing(8); var label = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Enter your email address to recover your username.", Lines = 0 }; StackView.AddArrangedSubview(label); label.StretchWidth(StackView, left: 16, right: 16); AddSpacing(8); AddDivider(); var textField = new UITextField() { Placeholder = "Email address", AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.Yes, KeyboardType = UIKeyboardType.EmailAddress, ReturnKeyType = UIReturnKeyType.Go, EnablesReturnKeyAutomatically = true }; AddTextField(textField, nameof(ViewModel.Email), firstResponder: true); AddSectionDivider(); var buttonRecover = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonRecover.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { Recover(); }).Handler; buttonRecover.SetTitle("Recover", UIControlState.Normal); StackView.AddArrangedSubview(buttonRecover); buttonRecover.StretchWidth(StackView); buttonRecover.SetHeight(44); AddBottomSectionDivider(); BindingHost.SetBinding(nameof(ViewModel.IsRecoveringUsernames), delegate { if (ViewModel.IsRecoveringUsernames) { ShowLoadingOverlay(false); } else { HideLoadingOverlay(); } }); base.OnViewModelLoadedOverride(); }
public override void OnViewModelLoadedOverride() { AddTopSectionDivider(); AddTextField(new UITextField() { Placeholder = "Username", AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.No, KeyboardType = UIKeyboardType.ASCIICapable, ReturnKeyType = UIReturnKeyType.Next, EnablesReturnKeyAutomatically = true }, nameof(ViewModel.Username), firstResponder: true); AddDivider(); AddTextField(new UITextField() { Placeholder = "Email address", AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.Yes, KeyboardType = UIKeyboardType.EmailAddress, ReturnKeyType = UIReturnKeyType.Go, EnablesReturnKeyAutomatically = true }, nameof(ViewModel.Email)); AddSectionDivider(); var buttonResetPassword = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonResetPassword.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ResetPassword(); }).Handler; buttonResetPassword.SetTitle("Reset password", UIControlState.Normal); StackView.AddArrangedSubview(buttonResetPassword); buttonResetPassword.StretchWidth(StackView); buttonResetPassword.SetHeight(44); AddBottomSectionDivider(); BindingHost.SetBinding(nameof(ViewModel.IsResettingPassword), delegate { if (ViewModel.IsResettingPassword) { ShowLoadingOverlay(false); } else { HideLoadingOverlay(); } }); base.OnViewModelLoadedOverride(); }
public override void OnViewModelAndViewLoadedOverride() { _accountBindingHost = new BindingHost() { BindingObject = ViewModel.CurrentAccount }; InitializeTable(); // Watch for online account changing _accountBindingHost.SetBinding(nameof(ViewModel.CurrentAccount.IsOnlineAccount), OnIsOnlineAccountChanged); base.OnViewModelAndViewLoadedOverride(); }
public ClassDetailsViewController() { Title = "Details"; var textViewDetails = new UITextView() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredBody, Editable = false, ScrollEnabled = false, // Link detection: http://iosdevelopertips.com/user-interface/creating-clickable-hyperlinks-from-a-url-phone-number-or-address.html DataDetectorTypes = UIDataDetectorType.All }; // Lose the padding: https://stackoverflow.com/questions/746670/how-to-lose-margin-padding-in-uitextview textViewDetails.TextContainerInset = UIEdgeInsets.Zero; textViewDetails.TextContainer.LineFragmentPadding = 0; BindingHost.SetTextViewTextBinding(textViewDetails, nameof(ViewModel.Details)); StackView.AddArrangedSubview(textViewDetails); textViewDetails.StretchWidth(StackView); var labelNothingHere = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Lines = 0, Font = UIFont.PreferredCallout, Text = "Tap the edit button in the top right to add details like the teacher's contact info, office hours, and anything else!", TextColor = UIColor.LightGray, TextAlignment = UITextAlignment.Center }; View.Add(labelNothingHere); labelNothingHere.StretchWidth(View, left: 16, right: 16); labelNothingHere.StretchHeight(View, top: 16, bottom: 16); BindingHost.SetBinding(nameof(ViewModel.Details), delegate { labelNothingHere.Hidden = !string.IsNullOrWhiteSpace(ViewModel.Details); }); }
public UIGradeCell(string cellId) : base(cellId) { var graySideBar = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = UIColor.FromWhiteAlpha(180 / 255f, 1) }; ContentView.AddSubview(graySideBar); graySideBar.SetWidth(8); graySideBar.PinToLeft(ContentView); graySideBar.StretchHeight(ContentView); _completionBar = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; ContentView.AddSubview(_completionBar); _completionBar.SetWidth(8); _completionBar.PinToLeft(ContentView); ContentView.AddConstraint(NSLayoutConstraint.Create( _completionBar, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.CenterY, 1, 0)); _stackView = new UIStackView() { TranslatesAutoresizingMaskIntoConstraints = false, Axis = UILayoutConstraintAxis.Vertical }; var titleAndGrade = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; { _labelTitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredCaption1 }; BindingHost.SetLabelTextBinding(_labelTitle, nameof(DataContext.Name)); titleAndGrade.Add(_labelTitle); _labelTitle.StretchHeight(titleAndGrade); _labelGrade = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredCaption2.Bold() }; BindingHost.SetLabelTextBinding(_labelGrade, nameof(DataContext.GradeSubtitle)); titleAndGrade.Add(_labelGrade); _labelGrade.StretchHeight(titleAndGrade); titleAndGrade.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[title][grade]-16-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, "title", _labelTitle, "grade", _labelGrade)); // Don't let grade compress, the title should be the one that shrinks _labelGrade.SetContentCompressionResistancePriority(501, UILayoutConstraintAxis.Horizontal); _labelTitle.SetContentCompressionResistancePriority(499, UILayoutConstraintAxis.Horizontal); // Don't let the grade unnecessarily expand either _labelGrade.SetContentHuggingPriority(501, UILayoutConstraintAxis.Horizontal); } _stackView.AddArrangedSubview(titleAndGrade); titleAndGrade.StretchWidth(_stackView); _labelDescription = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredCaption1, TextColor = UIColor.DarkGray }; BindingHost.SetLabelTextBinding(_labelDescription, nameof(DataContext.Details)); _stackView.AddArrangedSubview(_labelDescription); _labelDescription.StretchWidth(_stackView); ContentView.AddSubview(_stackView); _stackView.StretchWidthAndHeight(ContentView, left: 16, top: 8, bottom: 8); BindingHost.SetBinding(nameof(DataContext.IsDropped), delegate { if (_constraintCompletionBarHeight != null) { ContentView.RemoveConstraint(_constraintCompletionBarHeight); } nfloat multiplier = 1; if (DataContext.IsDropped) { multiplier = 0; } _constraintCompletionBarHeight = NSLayoutConstraint.Create( _completionBar, NSLayoutAttribute.Height, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Height, multiplier, 0); ContentView.AddConstraint(_constraintCompletionBarHeight); }); }
public override void OnViewModelLoadedOverride() { _navButtonEditDetails = new UIBarButtonItem(UIBarButtonSystemItem.Edit) { Title = "Edit details" }; _navButtonEditDetails.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.EditClassWithDetails(); }).Handler; _navButtonEditTimes = new UIBarButtonItem(UIBarButtonSystemItem.Edit) { Title = "Edit times" }; _navButtonEditTimes.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.EditTimes(); }).Handler; _navButtonAddTask = new UIBarButtonItem(UIBarButtonSystemItem.Add) { Title = "Add task" }; _navButtonAddTask.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.TasksViewModel.Add(); }).Handler; _navButtonAddEvent = new UIBarButtonItem(UIBarButtonSystemItem.Add) { Title = "Add event" }; _navButtonAddEvent.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.EventsViewModel.Add(); }).Handler; _navButtonAddGrade = new UIBarButtonItem(UIBarButtonSystemItem.Add) { Title = "Add grade" }; _navButtonAddGrade.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.GradesViewModel.Add(); }).Handler; _detailsViewController = new ClassDetailsViewController() { ViewModel = ViewModel.DetailsViewModel }; _timesViewController = new ClassTimesViewController() { ViewModel = ViewModel.TimesViewModel }; _tasksViewController = new ClassTasksOrEventsViewController() { Title = "Tasks", ViewModel = ViewModel.TasksViewModel }; _eventsViewController = new ClassTasksOrEventsViewController() { Title = "Events", ViewModel = ViewModel.EventsViewModel }; _gradesViewController = new ClassGradesViewController() { ViewModel = ViewModel.GradesViewModel }; int initialPageIndex = ViewModel.InitialPage != null ? (int)ViewModel.InitialPage : 0; initialPageIndex--; // Subtract one since don't have the overview view if (initialPageIndex < 0) { initialPageIndex = 0; } _pageMenuController = new CAPSPageMenuController(new UIViewController[] { _detailsViewController, _timesViewController, _tasksViewController, _eventsViewController, _gradesViewController }, new CAPSPageMenuConfiguration() { SelectedMenuItemLabelColor = ColorResources.PowerPlannerAccentBlue, SelectionIndicatorColor = ColorResources.PowerPlannerAccentBlue }, initialPageIndex); _pageMenuController.View.TranslatesAutoresizingMaskIntoConstraints = false; AddChildViewController(_pageMenuController); ContentView.Add(_pageMenuController.View); _pageMenuController.View.StretchWidthAndHeight(ContentView); switch (ViewModel.InitialPage) { case ClassViewModel.ClassPages.Times: UpdatePage(_timesViewController); break; case ClassViewModel.ClassPages.Tasks: UpdatePage(_tasksViewController); break; case ClassViewModel.ClassPages.Events: UpdatePage(_eventsViewController); break; case ClassViewModel.ClassPages.Grades: UpdatePage(_gradesViewController); break; default: UpdatePage(_detailsViewController); break; } _pageMenuController.SelectionChanged += new WeakEventHandler <CAPSPageMenuSelectionChangedEventArgs>(_pageMenuController_SelectionChanged).Handler; _classBindingHost.BindingObject = ViewModel.ViewItemsGroupClass.Class; _classBindingHost.SetBinding <string>(nameof(ViewItemClass.Name), (name) => { Title = name; }); BackButtonText = "Back"; base.OnViewModelLoadedOverride(); }
public override void OnViewModelLoadedOverride() { AddTopSectionDivider(); _errorContainer = new BareUIVisibilityContainer() { TranslatesAutoresizingMaskIntoConstraints = false, IsVisible = false }; { var stackViewIncorrect = new UIStackView() { Axis = UILayoutConstraintAxis.Vertical }; stackViewIncorrect.AddArrangedSubview(new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }.SetHeight(8)); _labelError = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Error", Lines = 0, TextColor = UIColor.Red }; stackViewIncorrect.AddArrangedSubview(_labelError); _labelError.StretchWidth(stackViewIncorrect, left: 16, right: 16); stackViewIncorrect.AddArrangedSubview(new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }.SetHeight(8)); AddDivider(stackViewIncorrect); _errorContainer.Child = stackViewIncorrect; } StackView.AddArrangedSubview(_errorContainer); _errorContainer.StretchWidth(StackView); var textField = new UITextField() { Placeholder = "New username", AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.No, KeyboardType = UIKeyboardType.ASCIICapable, ReturnKeyType = UIReturnKeyType.Done }; textField.AddTarget(new WeakEventHandler <EventArgs>(delegate { _errorContainer.IsVisible = false; }).Handler, UIControlEvent.EditingChanged); AddTextField(textField, nameof(ViewModel.Username), firstResponder: true); AddSectionDivider(); var buttonContinue = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonContinue.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.Update(); }).Handler; buttonContinue.SetTitle("Update Username", UIControlState.Normal); StackView.AddArrangedSubview(buttonContinue); buttonContinue.StretchWidth(StackView); buttonContinue.SetHeight(44); AddBottomSectionDivider(); ViewModel.ActionError += new WeakEventHandler <string>(ViewModel_ActionError).Handler; BindingHost.SetBinding(nameof(ViewModel.IsUpdatingUsername), delegate { IsLoadingOverlayVisible = ViewModel.IsUpdatingUsername; }); base.OnViewModelLoadedOverride(); }
public override void OnViewModelLoadedOverride() { bool isTask = ViewModel.Item.Type == TaskOrEventType.Task; BindingHost.SetBinding <string>(nameof(ViewModel.PageTitle), (t) => Title = StringWithCapitals(t)); var buttonEdit = new UIBarButtonItem(UIBarButtonSystemItem.Edit); buttonEdit.Clicked += new WeakEventHandler(delegate { ViewModel.Edit(); }).Handler; var buttonMore = new UIBarButtonItem(UIImage.FromBundle("MenuVerticalIcon").ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIBarButtonItemStyle.Plain, new WeakEventHandler(ButtonMore_Clicked).Handler); NavItem.RightBarButtonItems = new UIBarButtonItem[] { buttonMore, buttonEdit }; int bottomSliderHeight = isTask ? CIRCLE_BUTTON_HEIGHT + 16 + 16 : 0; _scrollView = new UIScrollView() { TranslatesAutoresizingMaskIntoConstraints = false, ShowsHorizontalScrollIndicator = false }; base.ContentView.AddSubview(_scrollView); _scrollView.StretchWidthAndHeight(base.ContentView, bottom: bottomSliderHeight); _stackView = new UIStackView() { TranslatesAutoresizingMaskIntoConstraints = false, Axis = UILayoutConstraintAxis.Vertical }; _scrollView.AddSubview(_stackView); _stackView.ConfigureForVerticalScrolling(_scrollView, top: 16, bottom: 16, left: 16, right: 16); _itemBindingHost = new BindingHost() { BindingObject = ViewModel.Item }; _classBindingHost = new BindingHost(); _itemBindingHost.SetBinding(nameof(ViewItemTaskOrEvent.Class), delegate { _classBindingHost.BindingObject = ViewModel.Item.Class; }); var labelTitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredTitle3, Lines = 0 }; _itemBindingHost.SetLabelTextBinding(labelTitle, nameof(ViewModel.Item.Name)); _stackView.AddArrangedSubview(labelTitle); labelTitle.StretchWidth(_stackView); _stackView.AddArrangedSubview(new UIView().SetHeight(4)); var labelSubtitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredSubheadline, Lines = 0 }; _itemBindingHost.SetLabelTextBinding(labelSubtitle, nameof(ViewItemTaskOrEvent.Subtitle)); _classBindingHost.SetBinding <byte[]>(nameof(ViewItemClass.Color), (color) => { labelSubtitle.TextColor = BareUIHelper.ToColor(color); }); _stackView.AddArrangedSubview(labelSubtitle); labelSubtitle.StretchWidth(_stackView); _stackView.AddArrangedSubview(new UIView().SetHeight(4)); _stackView.AddSpacing(12); var textViewDetails = new UITextView() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredBody, TextColor = UIColorCompat.SecondaryLabelColor, Editable = false, ScrollEnabled = false, // Link detection: http://iosdevelopertips.com/user-interface/creating-clickable-hyperlinks-from-a-url-phone-number-or-address.html DataDetectorTypes = UIDataDetectorType.All }; // Lose the padding: https://stackoverflow.com/questions/746670/how-to-lose-margin-padding-in-uitextview textViewDetails.TextContainerInset = UIEdgeInsets.Zero; textViewDetails.TextContainer.LineFragmentPadding = 0; _itemBindingHost.SetTextViewTextBinding(textViewDetails, nameof(ViewItemTaskOrEvent.Details)); _stackView.AddArrangedSubview(textViewDetails); textViewDetails.StretchWidth(_stackView); if (ViewModel.IsUnassigedMode) { var buttonAddGrade = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonAddGrade.SetTitle("Add Grade", UIControlState.Normal); buttonAddGrade.SetTitleColor(new UIColor(1, 1), UIControlState.Normal); buttonAddGrade.BackgroundColor = ColorResources.PowerPlannerAccentBlue; buttonAddGrade.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.AddGrade(); }).Handler; base.ContentView.Add(buttonAddGrade); // https://stackoverflow.com/questions/46344381/ios-11-layout-guidance-about-safe-area-for-iphone-x if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] { buttonAddGrade.LeftAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.LeftAnchor, 16), buttonAddGrade.RightAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.RightAnchor, -16), buttonAddGrade.BottomAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.BottomAnchor, -16) }); } else { buttonAddGrade.StretchWidth(base.ContentView, left: 16, right: 16); buttonAddGrade.PinToBottom(base.ContentView, bottom: 16); } } else { var completionSliderVisibilityContainer = new BareUIVisibilityContainer() { TranslatesAutoresizingMaskIntoConstraints = false }; { var completionSliderContainer = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; { _completionSlider = new UISlider() { TranslatesAutoresizingMaskIntoConstraints = false, MaxValue = 1, MinValue = 0, MinimumTrackTintColor = UIColor.FromRGB(42 / 255f, 222 / 255f, 42 / 255f), ThumbTintColor = UIColor.FromRGB(42 / 255f, 222 / 255f, 42 / 255f) }; _itemBindingHost.SetSliderBinding(_completionSlider, nameof(ViewItemTaskOrEvent.PercentComplete)); _completionSlider.TouchUpInside += new WeakEventHandler(CompletionSlider_ValueCommitted).Handler; _completionSlider.TouchUpOutside += new WeakEventHandler(CompletionSlider_ValueCommitted).Handler; completionSliderContainer.Add(_completionSlider); _completionSlider.StretchHeight(completionSliderContainer); _completionSlider.StretchWidth(completionSliderContainer, left: CIRCLE_BUTTON_HEIGHT + 8, right: CIRCLE_BUTTON_HEIGHT + 8); var incompleteImageContainer = new UIControl() { TranslatesAutoresizingMaskIntoConstraints = false }; { _incompleteImageView = new UIImageView() { TranslatesAutoresizingMaskIntoConstraints = false, ContentMode = UIViewContentMode.ScaleAspectFit, TintColor = UIColor.LightGray }; incompleteImageContainer.Add(_incompleteImageView); _incompleteImageView.StretchHeight(incompleteImageContainer); _incompleteImageView.SetWidth(CIRCLE_BUTTON_HEIGHT); _incompleteImageView.PinToLeft(incompleteImageContainer); } incompleteImageContainer.TouchUpInside += new WeakEventHandler(delegate { _completionSlider.Value = 0; ViewModel.SetPercentComplete(0); UpdateSliderImages(); }).Handler; completionSliderContainer.Add(incompleteImageContainer); incompleteImageContainer.StretchHeight(completionSliderContainer); incompleteImageContainer.PinToLeft(completionSliderContainer); incompleteImageContainer.SetWidth(CIRCLE_BUTTON_HEIGHT); var completeImageContainer = new UIControl() { TranslatesAutoresizingMaskIntoConstraints = false }; { _completeImageView = new UIImageView() { TranslatesAutoresizingMaskIntoConstraints = false, ContentMode = UIViewContentMode.ScaleAspectFit, TintColor = UIColor.LightGray }; completeImageContainer.Add(_completeImageView); _completeImageView.StretchHeight(completeImageContainer); _completeImageView.SetWidth(CIRCLE_BUTTON_HEIGHT); _completeImageView.PinToRight(completeImageContainer); } completeImageContainer.TouchUpInside += new WeakEventHandler(delegate { _completionSlider.Value = 1; ViewModel.SetPercentComplete(1); UpdateSliderImages(); }).Handler; completionSliderContainer.Add(completeImageContainer); completeImageContainer.StretchHeight(completionSliderContainer); completeImageContainer.PinToRight(completionSliderContainer); completeImageContainer.SetWidth(CIRCLE_BUTTON_HEIGHT); _completionSlider.ValueChanged += new WeakEventHandler(delegate { UpdateSliderImages(); }).Handler; } completionSliderContainer.SetHeight(CIRCLE_BUTTON_HEIGHT); completionSliderVisibilityContainer.Child = completionSliderContainer; } BindingHost.SetVisibilityBinding(completionSliderVisibilityContainer, nameof(ViewModel.IsCompletionSliderVisible)); base.ContentView.Add(completionSliderVisibilityContainer); // https://stackoverflow.com/questions/46344381/ios-11-layout-guidance-about-safe-area-for-iphone-x if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] { completionSliderVisibilityContainer.LeftAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.LeftAnchor, 16), completionSliderVisibilityContainer.RightAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.RightAnchor, -16), completionSliderVisibilityContainer.BottomAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.BottomAnchor, -16) }); } else { completionSliderVisibilityContainer.StretchWidth(base.ContentView, left: 16, right: 16); completionSliderVisibilityContainer.PinToBottom(base.ContentView, bottom: 16); } _itemBindingHost.SetBinding(nameof(ViewItemTaskOrEvent.PercentComplete), UpdateSliderImages); } base.OnViewModelLoadedOverride(); }
public ViewGradeViewController() { Title = "View Grade"; var buttonEdit = new UIBarButtonItem(UIBarButtonSystemItem.Edit); buttonEdit.Clicked += new WeakEventHandler(delegate { ViewModel.Edit(); }).Handler; var buttonDelete = new UIBarButtonItem(UIBarButtonSystemItem.Trash); buttonDelete.Clicked += new WeakEventHandler(ButtonDelete_Clicked).Handler; NavItem.RightBarButtonItems = new UIBarButtonItem[] { buttonDelete, buttonEdit }; var labelTitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredTitle3, Lines = 0 }; _itemBindingHost.SetLabelTextBinding(labelTitle, nameof(ViewModel.Grade.Name)); StackView.AddArrangedSubview(labelTitle); labelTitle.StretchWidth(StackView); StackView.AddArrangedSubview(new UIView().SetHeight(4)); var labelSubtitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredSubheadline, Lines = 0 }; _itemBindingHost.SetLabelTextBinding(labelSubtitle, nameof(ViewItemGrade.GradeSubtitle)); _classBindingHost.SetBinding <byte[]>(nameof(ViewItemClass.Color), (color) => { labelSubtitle.TextColor = BareUIHelper.ToColor(color); }); StackView.AddArrangedSubview(labelSubtitle); labelSubtitle.StretchWidth(StackView); StackView.AddArrangedSubview(new UIView().SetHeight(4)); var labelDate = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredSubheadline, TextColor = UIColor.DarkGray }; _itemBindingHost.SetBinding <DateTime>(nameof(ViewItemGrade.Date), (date) => { labelDate.Text = date.ToString("d"); }); StackView.AddArrangedSubview(labelDate); labelDate.StretchWidth(StackView); StackView.AddArrangedSubview(new UIView().SetHeight(4)); StackView.AddSpacing(12); var textViewDetails = new UITextView() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredBody, TextColor = UIColor.DarkGray, Editable = false, ScrollEnabled = false, // Link detection: http://iosdevelopertips.com/user-interface/creating-clickable-hyperlinks-from-a-url-phone-number-or-address.html DataDetectorTypes = UIDataDetectorType.All }; // Lose the padding: https://stackoverflow.com/questions/746670/how-to-lose-margin-padding-in-uitextview textViewDetails.TextContainerInset = UIEdgeInsets.Zero; textViewDetails.TextContainer.LineFragmentPadding = 0; _itemBindingHost.SetTextViewTextBinding(textViewDetails, nameof(ViewItemGrade.Details)); StackView.AddArrangedSubview(textViewDetails); textViewDetails.StretchWidth(StackView); }
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(); }
public override void OnViewModelLoadedOverride() { _navButtonEditDetails = new UIBarButtonItem(UIBarButtonSystemItem.Edit) { Title = "Edit details" }; _navButtonEditDetails.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.EditClassWithDetails(); }).Handler; _navButtonEditTimes = new UIBarButtonItem(UIBarButtonSystemItem.Edit) { Title = "Edit times" }; _navButtonEditTimes.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.EditTimes(); }).Handler; _navButtonAddHomework = new UIBarButtonItem(UIBarButtonSystemItem.Add) { Title = "Add task" }; _navButtonAddHomework.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.HomeworkViewModel.Add(); }).Handler; _navButtonAddExam = new UIBarButtonItem(UIBarButtonSystemItem.Add) { Title = "Add event" }; _navButtonAddExam.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.ExamsViewModel.Add(); }).Handler; _navButtonAddGrade = new UIBarButtonItem(UIBarButtonSystemItem.Add) { Title = "Add grade" }; _navButtonAddGrade.Clicked += new WeakEventHandler <EventArgs>(delegate { ViewModel.GradesViewModel.Add(); }).Handler; _detailsViewController = new ClassDetailsViewController() { ViewModel = ViewModel.DetailsViewModel }; _timesViewController = new ClassTimesViewController() { ViewModel = ViewModel.TimesViewModel }; _homeworkViewController = new ClassHomeworkOrExamsViewController() { Title = "Tasks", ViewModel = ViewModel.HomeworkViewModel }; _examsViewController = new ClassHomeworkOrExamsViewController() { Title = "Events", ViewModel = ViewModel.ExamsViewModel }; _gradesViewController = new ClassGradesViewController() { ViewModel = ViewModel.GradesViewModel }; _pageMenuController = new CAPSPageMenuController(new UIViewController[] { _detailsViewController, _timesViewController, _homeworkViewController, _examsViewController, _gradesViewController }, new CAPSPageMenuConfiguration() { SelectedMenuItemLabelColor = ColorResources.PowerPlannerAccentBlue, SelectionIndicatorColor = ColorResources.PowerPlannerAccentBlue }); _pageMenuController.SelectionChanged += new WeakEventHandler <CAPSPageMenuSelectionChangedEventArgs>(_pageMenuController_SelectionChanged).Handler; _pageMenuController.View.TranslatesAutoresizingMaskIntoConstraints = false; AddChildViewController(_pageMenuController); ContentView.Add(_pageMenuController.View); _pageMenuController.View.StretchWidthAndHeight(ContentView); UpdatePage(_detailsViewController); _classBindingHost.BindingObject = ViewModel.ViewItemsGroupClass.Class; _classBindingHost.SetBinding <string>(nameof(ViewItemClass.Name), (name) => { Title = name; }); BackButtonText = "Back"; base.OnViewModelLoadedOverride(); }
public override void OnViewModelLoadedOverride() { AddTopSectionDivider(); AddTextField(new UITextField() { Placeholder = "Username", AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.No, KeyboardType = UIKeyboardType.ASCIICapable, ReturnKeyType = UIReturnKeyType.Next, EnablesReturnKeyAutomatically = true }, nameof(ViewModel.Username), firstResponder: true); AddDivider(); AddTextField(new UITextField() { Placeholder = "Email address (for recovery purposes)", AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.Yes, KeyboardType = UIKeyboardType.EmailAddress, ReturnKeyType = UIReturnKeyType.Next, EnablesReturnKeyAutomatically = true }, nameof(ViewModel.Email)); AddDivider(); AddTextField(new UITextField() { Placeholder = "Password", SecureTextEntry = true, ReturnKeyType = UIReturnKeyType.Next, EnablesReturnKeyAutomatically = true }, nameof(ViewModel.Password)); AddDivider(); AddTextField(new UITextField() { Placeholder = "Confirm password", SecureTextEntry = true, ReturnKeyType = UIReturnKeyType.Go }, nameof(ViewModel.ConfirmPassword)); AddSectionDivider(); var buttonCreateAccount = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonCreateAccount.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { CreateAccount(); }).Handler; buttonCreateAccount.SetTitle("Create Account", UIControlState.Normal); StackView.AddArrangedSubview(buttonCreateAccount); buttonCreateAccount.StretchWidth(StackView); buttonCreateAccount.SetHeight(44); AddDivider(fullWidth: true); if (ViewModel.IsCreateLocalAccountVisible) { var bottomView = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = ColorResources.InputSectionDividers }; { var buttonCreateLocalAccount = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredCaption1 }; buttonCreateLocalAccount.TouchUpInside += new WeakEventHandler(ButtonCreateLocalAccount_TouchUpInside).Handler; buttonCreateLocalAccount.SetTitle("No internet? Create offline account", UIControlState.Normal); bottomView.Add(buttonCreateLocalAccount); buttonCreateLocalAccount.PinToRight(bottomView, right: 16); buttonCreateLocalAccount.StretchHeight(bottomView, top: 8); } StackView.AddArrangedSubview(bottomView); bottomView.StretchWidth(StackView); } BindingHost.SetBinding(nameof(ViewModel.IsCreatingOnlineAccount), delegate { if (ViewModel.IsCreatingOnlineAccount) { ShowLoadingOverlay(loadingText: "Creating account..."); } else { HideLoadingOverlay(); } }); base.OnViewModelLoadedOverride(); }
public override void OnViewModelLoadedOverride() { AddTopSectionDivider(); AddSpacing(8); var label = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Your online account's username or password has changed. Please log back in to continue using your online account.", Lines = 0 }; StackView.AddArrangedSubview(label); label.StretchWidth(StackView, left: 16, right: 16); AddSpacing(8); AddDivider(); _errorContainer = new BareUIVisibilityContainer() { TranslatesAutoresizingMaskIntoConstraints = false, IsVisible = false }; { var stackViewIncorrect = new UIStackView() { Axis = UILayoutConstraintAxis.Vertical }; stackViewIncorrect.AddArrangedSubview(new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }.SetHeight(8)); _labelError = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Error", Lines = 0, TextColor = UIColor.Red }; stackViewIncorrect.AddArrangedSubview(_labelError); _labelError.StretchWidth(stackViewIncorrect, left: 16, right: 16); stackViewIncorrect.AddArrangedSubview(new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }.SetHeight(8)); AddDivider(stackViewIncorrect); _errorContainer.Child = stackViewIncorrect; } StackView.AddArrangedSubview(_errorContainer); _errorContainer.StretchWidth(StackView); var textFieldUsername = new UITextField() { Placeholder = "Username", AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.No, KeyboardType = UIKeyboardType.ASCIICapable, ReturnKeyType = UIReturnKeyType.Next }; textFieldUsername.AddTarget(new WeakEventHandler <EventArgs>(delegate { _errorContainer.IsVisible = false; }).Handler, UIControlEvent.EditingChanged); AddTextField(textFieldUsername, nameof(ViewModel.Username)); AddDivider(); var textFieldPassword = new UITextField() { Placeholder = "Password", SecureTextEntry = true, ReturnKeyType = UIReturnKeyType.Done }; textFieldPassword.AddTarget(new WeakEventHandler <EventArgs>(delegate { _errorContainer.IsVisible = false; }).Handler, UIControlEvent.EditingChanged); AddTextField(textFieldPassword, nameof(ViewModel.Password), firstResponder: true); AddSectionDivider(); var buttonLogin = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonLogin.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.LogIn(); }).Handler; buttonLogin.SetTitle("Log In", UIControlState.Normal); StackView.AddArrangedSubview(buttonLogin); buttonLogin.StretchWidth(StackView); buttonLogin.SetHeight(44); AddDivider(fullWidth: true); var forgotViews = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = ColorResources.InputSectionDividers }; { var leftSpacer = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; forgotViews.Add(leftSpacer); var rightSpacer = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; forgotViews.Add(rightSpacer); var buttonForgotUsername = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false, HorizontalAlignment = UIControlContentHorizontalAlignment.Right, Font = UIFont.PreferredCaption1 }; buttonForgotUsername.TouchUpInside += new WeakEventHandler(delegate { ViewModel.ForgotUsername(); }).Handler; buttonForgotUsername.SetTitle("Forgot Username", UIControlState.Normal); forgotViews.Add(buttonForgotUsername); buttonForgotUsername.StretchHeight(forgotViews); var verticalDivider = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = UIColor.FromWhiteAlpha(0.7f, 1) }; forgotViews.Add(verticalDivider); verticalDivider.StretchHeight(forgotViews, top: 16, bottom: 16); var buttonForgotPassword = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false, HorizontalAlignment = UIControlContentHorizontalAlignment.Left, Font = UIFont.PreferredCaption1 }; buttonForgotPassword.TouchUpInside += new WeakEventHandler(delegate { ViewModel.ForgotPassword(); }).Handler; buttonForgotPassword.SetTitle("Forgot Password", UIControlState.Normal); forgotViews.Add(buttonForgotPassword); buttonForgotPassword.StretchHeight(forgotViews); forgotViews.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[leftSpacer][forgotUsername]-8-[verticalDivider(1)]-8-[forgotPassword][rightSpacer(==leftSpacer)]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary( "forgotUsername", buttonForgotUsername, "verticalDivider", verticalDivider, "forgotPassword", buttonForgotPassword, "leftSpacer", leftSpacer, "rightSpacer", rightSpacer))); } StackView.AddArrangedSubview(forgotViews); forgotViews.StretchWidth(StackView); forgotViews.SetHeight(44); BindingHost.SetBinding(nameof(ViewModel.Error), delegate { if (string.IsNullOrWhiteSpace(ViewModel.Error)) { _errorContainer.IsVisible = false; } else { _errorContainer.IsVisible = true; _labelError.Text = ViewModel.Error; } }); BindingHost.SetBinding(nameof(ViewModel.IsLoggingIn), delegate { IsLoadingOverlayVisible = ViewModel.IsLoggingIn; }); base.OnViewModelLoadedOverride(); }
public override void OnViewModelLoadedOverride() { base.OnViewModelLoadedOverride(); AddTopSectionDivider(); _errorContainer = new BareUIVisibilityContainer() { TranslatesAutoresizingMaskIntoConstraints = false, IsVisible = false }; { var stackViewIncorrect = new UIStackView() { Axis = UILayoutConstraintAxis.Vertical }; stackViewIncorrect.AddArrangedSubview(new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }.SetHeight(8)); _labelError = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Error", Lines = 0, TextColor = UIColor.Red }; stackViewIncorrect.AddArrangedSubview(_labelError); _labelError.StretchWidth(stackViewIncorrect, left: 16, right: 16); stackViewIncorrect.AddArrangedSubview(new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }.SetHeight(8)); AddDivider(stackViewIncorrect); _errorContainer.Child = stackViewIncorrect; } StackView.AddArrangedSubview(_errorContainer); _errorContainer.StretchWidth(StackView); var textField = new UITextField() { Placeholder = "Provide your email", AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.Yes, KeyboardType = UIKeyboardType.EmailAddress, ReturnKeyType = UIReturnKeyType.Done }; textField.AddTarget(new WeakEventHandler <EventArgs>(delegate { _errorContainer.IsVisible = false; }).Handler, UIControlEvent.EditingChanged); AddTextField(textField, nameof(ViewModel.Email), firstResponder: true); AddSectionDivider(); var buttonConvert = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonConvert.TouchUpInside += new WeakEventHandler <EventArgs>(async delegate { ShowLoadingOverlay(); await ViewModel.CreateOnlineAccountAsync(); HideLoadingOverlay(); }).Handler; buttonConvert.SetTitle("Convert to Online Account", UIControlState.Normal); StackView.AddArrangedSubview(buttonConvert); buttonConvert.StretchWidth(StackView); buttonConvert.SetHeight(44); var mergeExistingContainer = new UIStackView() { Axis = UILayoutConstraintAxis.Vertical }; { mergeExistingContainer.AddSectionDivider(); mergeExistingContainer.AddSpacing(16); var labelMergeExistingExplanation = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = PowerPlannerResources.GetString("Settings_ConvertToOnline_TextBlockConfirmMergeExisting.Text"), Lines = 0, TextColor = UIColor.Red }; mergeExistingContainer.AddArrangedSubview(labelMergeExistingExplanation); labelMergeExistingExplanation.StretchWidth(mergeExistingContainer, left: 16, right: 16); mergeExistingContainer.AddSpacing(16); mergeExistingContainer.AddDivider(); var buttonContinue = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false, TintColor = UIColor.Red }; buttonContinue.TouchUpInside += new WeakEventHandler <EventArgs>(async delegate { ShowLoadingOverlay(); await ViewModel.MergeExisting(); HideLoadingOverlay(); }).Handler; buttonContinue.SetTitle(PowerPlannerResources.GetString("Settings_ConfirmIdentityPage_ButtonContinue.Content"), UIControlState.Normal); mergeExistingContainer.AddArrangedSubview(buttonContinue); buttonContinue.StretchWidth(mergeExistingContainer); buttonContinue.SetHeight(44); mergeExistingContainer.AddDivider(); var buttonCancel = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonCancel.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.CancelMergeExisting(); }).Handler; buttonCancel.SetTitle(PowerPlannerResources.GetString("Buttons_Cancel.Content"), UIControlState.Normal); mergeExistingContainer.AddArrangedSubview(buttonCancel); buttonCancel.StretchWidth(mergeExistingContainer); buttonCancel.SetHeight(44); } AddUnderVisiblity(mergeExistingContainer, nameof(ViewModel.ShowConfirmMergeExisting)); AddBottomSectionDivider(); BindingHost.SetBinding(nameof(ViewModel.Error), delegate { if (string.IsNullOrWhiteSpace(ViewModel.Error)) { _errorContainer.IsVisible = false; } else { _errorContainer.IsVisible = true; _labelError.Text = ViewModel.Error; } }); base.OnViewModelLoadedOverride(); }
public ViewGradeViewController() { Title = "View Grade"; var buttonEdit = new UIBarButtonItem(UIBarButtonSystemItem.Edit); buttonEdit.Clicked += new WeakEventHandler(delegate { ViewModel.Edit(); }).Handler; var buttonDelete = new UIBarButtonItem(UIBarButtonSystemItem.Trash); buttonDelete.Clicked += new WeakEventHandler(ButtonDelete_Clicked).Handler; NavItem.RightBarButtonItems = new UIBarButtonItem[] { buttonDelete, buttonEdit }; var labelTitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredTitle3, Lines = 0 }; _itemBindingHost.SetLabelTextBinding(labelTitle, nameof(ViewModel.Grade.Name)); StackView.AddArrangedSubview(labelTitle); labelTitle.StretchWidth(StackView); StackView.AddArrangedSubview(new UIView().SetHeight(4)); var labelSubtitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredSubheadline, Lines = 0 }; _itemBindingHost.SetLabelTextBinding(labelSubtitle, nameof(ViewItemGrade.GradeSubtitle)); _classBindingHost.SetBinding <byte[]>(nameof(ViewItemClass.Color), (color) => { labelSubtitle.TextColor = BareUIHelper.ToColor(color); }); StackView.AddArrangedSubview(labelSubtitle); labelSubtitle.StretchWidth(StackView); StackView.AddArrangedSubview(new UIView().SetHeight(4)); var labelDate = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredSubheadline, TextColor = UIColor.DarkGray }; _itemBindingHost.SetBinding <DateTime>(nameof(ViewItemGrade.Date), (date) => { labelDate.Text = date.ToString("d"); }); StackView.AddArrangedSubview(labelDate); labelDate.StretchWidth(StackView); StackView.AddArrangedSubview(new UIView().SetHeight(4)); var labelDetails = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredCaption1, Lines = 0, TextColor = UIColor.DarkGray }; _itemBindingHost.SetLabelTextBinding(labelDetails, nameof(ViewItemGrade.Details)); StackView.AddArrangedSubview(labelDetails); labelDetails.StretchWidth(StackView); }
public override void OnViewModelLoadedOverride() { bool isHomework = ViewModel.Item is ViewItemHomework; Title = isHomework ? "View Task" : "View Event"; var buttonEdit = new UIBarButtonItem(UIBarButtonSystemItem.Edit); buttonEdit.Clicked += new WeakEventHandler(delegate { ViewModel.Edit(); }).Handler; var buttonDelete = new UIBarButtonItem(UIBarButtonSystemItem.Trash); buttonDelete.Clicked += new WeakEventHandler(ButtonDelete_Clicked).Handler; NavItem.RightBarButtonItems = new UIBarButtonItem[] { buttonDelete, buttonEdit }; int bottomSliderHeight = isHomework ? CIRCLE_BUTTON_HEIGHT + 16 + 16 : 0; _scrollView = new UIScrollView() { TranslatesAutoresizingMaskIntoConstraints = false, ShowsHorizontalScrollIndicator = false }; base.ContentView.AddSubview(_scrollView); _scrollView.StretchWidthAndHeight(base.ContentView, bottom: bottomSliderHeight); _stackView = new UIStackView() { TranslatesAutoresizingMaskIntoConstraints = false, Axis = UILayoutConstraintAxis.Vertical }; _scrollView.AddSubview(_stackView); _stackView.ConfigureForVerticalScrolling(_scrollView, top: 16, bottom: 16, left: 16, right: 16); _itemBindingHost = new BindingHost() { BindingObject = ViewModel.Item }; _classBindingHost = new BindingHost(); _itemBindingHost.SetBinding(nameof(ViewItemHomework.Class), delegate { _classBindingHost.BindingObject = ViewModel.Item.GetClassOrNull(); }); var labelTitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredTitle3, Lines = 0 }; _itemBindingHost.SetLabelTextBinding(labelTitle, nameof(ViewModel.Item.Name)); _stackView.AddArrangedSubview(labelTitle); labelTitle.StretchWidth(_stackView); _stackView.AddArrangedSubview(new UIView().SetHeight(4)); var labelSubtitle = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredSubheadline, Lines = 0 }; _itemBindingHost.SetLabelTextBinding(labelSubtitle, nameof(ViewItemHomework.Subtitle)); _classBindingHost.SetBinding <byte[]>(nameof(ViewItemClass.Color), (color) => { labelSubtitle.TextColor = BareUIHelper.ToColor(color); }); _stackView.AddArrangedSubview(labelSubtitle); labelSubtitle.StretchWidth(_stackView); _stackView.AddArrangedSubview(new UIView().SetHeight(4)); var labelDetails = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredCaption1, Lines = 0, TextColor = UIColor.DarkGray }; _itemBindingHost.SetLabelTextBinding(labelDetails, nameof(ViewItemHomework.Details)); _stackView.AddArrangedSubview(labelDetails); labelDetails.StretchWidth(_stackView); if (ViewModel.IsUnassigedMode) { var buttonConvertToGrade = new UIButton(UIButtonType.System) { TranslatesAutoresizingMaskIntoConstraints = false }; buttonConvertToGrade.SetTitle("Convert To Grade", UIControlState.Normal); buttonConvertToGrade.SetTitleColor(new UIColor(1, 1), UIControlState.Normal); buttonConvertToGrade.BackgroundColor = ColorResources.PowerPlannerAccentBlue; buttonConvertToGrade.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.ConvertToGrade(); }).Handler; base.ContentView.Add(buttonConvertToGrade); // https://stackoverflow.com/questions/46344381/ios-11-layout-guidance-about-safe-area-for-iphone-x if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] { buttonConvertToGrade.LeftAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.LeftAnchor, 16), buttonConvertToGrade.RightAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.RightAnchor, -16), buttonConvertToGrade.BottomAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.BottomAnchor, -16) }); } else { buttonConvertToGrade.StretchWidth(base.ContentView, left: 16, right: 16); buttonConvertToGrade.PinToBottom(base.ContentView, bottom: 16); } } else if (isHomework) { var completionSliderContainer = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; { _completionSlider = new UISlider() { TranslatesAutoresizingMaskIntoConstraints = false, MaxValue = 1, MinValue = 0, MinimumTrackTintColor = UIColor.FromRGB(42 / 255f, 222 / 255f, 42 / 255f), ThumbTintColor = UIColor.FromRGB(42 / 255f, 222 / 255f, 42 / 255f) }; _itemBindingHost.SetSliderBinding(_completionSlider, nameof(ViewItemHomework.PercentComplete)); _completionSlider.TouchUpInside += new WeakEventHandler(CompletionSlider_ValueCommitted).Handler; _completionSlider.TouchUpOutside += new WeakEventHandler(CompletionSlider_ValueCommitted).Handler; completionSliderContainer.Add(_completionSlider); _completionSlider.StretchHeight(completionSliderContainer); _completionSlider.StretchWidth(completionSliderContainer, left: CIRCLE_BUTTON_HEIGHT + 8, right: CIRCLE_BUTTON_HEIGHT + 8); var incompleteImageContainer = new UIControl() { TranslatesAutoresizingMaskIntoConstraints = false }; { _incompleteImageView = new UIImageView() { TranslatesAutoresizingMaskIntoConstraints = false, ContentMode = UIViewContentMode.ScaleAspectFit, TintColor = UIColor.LightGray }; incompleteImageContainer.Add(_incompleteImageView); _incompleteImageView.StretchHeight(incompleteImageContainer); _incompleteImageView.SetWidth(CIRCLE_BUTTON_HEIGHT); _incompleteImageView.PinToLeft(incompleteImageContainer); } incompleteImageContainer.TouchUpInside += new WeakEventHandler(delegate { _completionSlider.Value = 0; ViewModel.SetPercentComplete(0); UpdateSliderImages(); }).Handler; completionSliderContainer.Add(incompleteImageContainer); incompleteImageContainer.StretchHeight(completionSliderContainer); incompleteImageContainer.PinToLeft(completionSliderContainer); incompleteImageContainer.SetWidth(CIRCLE_BUTTON_HEIGHT); var completeImageContainer = new UIControl() { TranslatesAutoresizingMaskIntoConstraints = false }; { _completeImageView = new UIImageView() { TranslatesAutoresizingMaskIntoConstraints = false, ContentMode = UIViewContentMode.ScaleAspectFit, TintColor = UIColor.LightGray }; completeImageContainer.Add(_completeImageView); _completeImageView.StretchHeight(completeImageContainer); _completeImageView.SetWidth(CIRCLE_BUTTON_HEIGHT); _completeImageView.PinToRight(completeImageContainer); } completeImageContainer.TouchUpInside += new WeakEventHandler(delegate { _completionSlider.Value = 1; ViewModel.SetPercentComplete(1); UpdateSliderImages(); }).Handler; completionSliderContainer.Add(completeImageContainer); completeImageContainer.StretchHeight(completionSliderContainer); completeImageContainer.PinToRight(completionSliderContainer); completeImageContainer.SetWidth(CIRCLE_BUTTON_HEIGHT); _completionSlider.ValueChanged += new WeakEventHandler(delegate { UpdateSliderImages(); }).Handler; } base.ContentView.Add(completionSliderContainer); completionSliderContainer.SetHeight(CIRCLE_BUTTON_HEIGHT); // https://stackoverflow.com/questions/46344381/ios-11-layout-guidance-about-safe-area-for-iphone-x if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] { completionSliderContainer.LeftAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.LeftAnchor, 16), completionSliderContainer.RightAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.RightAnchor, -16), completionSliderContainer.BottomAnchor.ConstraintEqualTo(base.ContentView.SafeAreaLayoutGuide.BottomAnchor, -16) }); } else { completionSliderContainer.StretchWidth(base.ContentView, left: 16, right: 16); completionSliderContainer.PinToBottom(base.ContentView, bottom: 16); } _itemBindingHost.SetBinding(nameof(ViewItemHomework.PercentComplete), UpdateSliderImages); } base.OnViewModelLoadedOverride(); }