public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection) { base.TraitCollectionDidChange(previousTraitCollection); ReportsTableView.ReloadData(); }
public override void ViewDidLoad() { base.ViewDidLoad(); calendarViewController = ViewControllerLocator.GetViewController(ViewModel.CalendarViewModel) as ReportsCalendarViewController; prepareViews(); OverviewContainerView.AddSubview(overview); overview.Frame = OverviewContainerView.Bounds; overview.Item = ViewModel; BarChartsContainerView.AddSubview(barChart); barChart.Frame = BarChartsContainerView.Bounds; barChart.Item = ViewModel; calendarSizeDisposable = CalendarContainer.AddObserver(boundsKey, NSKeyValueObservingOptions.New, onCalendarSizeChanged); source = new ReportsTableViewSource(ReportsTableView, ViewModel); source.SetItems(ImmutableList <ChartSegment> .Empty); ReportsTableView.ReloadData(); ViewModel.SegmentsObservable .Subscribe(ReportsTableView.Rx().ReloadItems(source)) .DisposedBy(DisposeBag); source.ScrolledWithHeaderOffset .Subscribe(onReportsTableScrolled) .DisposedBy(DisposeBag); ReportsTableView.Source = source; bool areThereEnoughWorkspaces(ICollection <SelectOption <IThreadSafeWorkspace> > workspaces) => workspaces.Count > 1; bool isWorkspaceNameTooLong(string workspaceName) { var attributes = new UIStringAttributes { Font = WorkspaceLabel.Font }; var size = new NSString(workspaceName).GetSizeUsingAttributes(attributes); var maxWidth = TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Regular ? maximumWorkspaceNameLabelWidthRegular : maximumWorkspaceNameLabelWidthCompact; return(size.Width >= maxWidth); }; //Text ViewModel.WorkspaceNameObservable .Subscribe(WorkspaceLabel.Rx().Text()) .DisposedBy(DisposeBag); ViewModel.CurrentDateRange .Subscribe(titleButton.Rx().Title()) .DisposedBy(DisposeBag); //Visibility ViewModel.WorkspacesObservable .Select(areThereEnoughWorkspaces) .Subscribe(WorkspaceButton.Rx().IsVisible()) .DisposedBy(DisposeBag); ViewModel.WorkspaceNameObservable .Select(isWorkspaceNameTooLong) .Subscribe(WorkspaceFadeView.Rx().FadeRight()) .DisposedBy(DisposeBag); //Commands titleButton.Rx().Tap() .Subscribe(toggleCalendar) .DisposedBy(DisposeBag); ReportsTableView.Rx().Tap() .Subscribe(HideCalendar) .DisposedBy(DisposeBag); WorkspaceButton.Rx() .BindAction(ViewModel.SelectWorkspace) .DisposedBy(DisposeBag); void toggleCalendar() { if (calendarIsVisible) { HideCalendar(); return; } if (TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Compact) { ShowCalendar(); return; } ShowPopoverCalendar(); } }
public override void ViewDidLoad() { base.ViewDidLoad(); var separator = NavigationController.NavigationBar.InsertSeparator(); separator.BackgroundColor = ColorAssets.OpaqueSeparator; calendarViewController = ViewControllerLocator.GetViewController(ViewModel.CalendarViewModel) as ReportsCalendarViewController; prepareViews(); OverviewContainerView.AddSubview(overview); overview.Frame = OverviewContainerView.Bounds; overview.Item = ViewModel; BarChartsContainerView.AddSubview(barChart); barChart.Frame = BarChartsContainerView.Bounds; barChart.Item = ViewModel; calendarSizeDisposable = CalendarContainer.AddObserver(boundsKey, NSKeyValueObservingOptions.New, onCalendarSizeChanged); source = new ReportsTableViewSource(ReportsTableView, ViewModel); source.SetItems(ImmutableList <ChartSegment> .Empty); ReportsTableView.ReloadData(); ViewModel.SegmentsObservable .Subscribe(ReportsTableView.Rx().ReloadItems(source)) .DisposedBy(DisposeBag); source.ScrolledWithHeaderOffset .Subscribe(onReportsTableScrolled) .DisposedBy(DisposeBag); ReportsTableView.Source = source; bool areThereEnoughWorkspaces(ICollection <SelectOption <IThreadSafeWorkspace> > workspaces) => workspaces.Count > 1; bool isWorkspaceNameTooLong(string workspaceName) { var attributes = new UIStringAttributes { Font = WorkspaceLabel.Font }; var size = new NSString(workspaceName).GetSizeUsingAttributes(attributes); var maxWidth = TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Regular ? maximumWorkspaceNameLabelWidthRegular : maximumWorkspaceNameLabelWidthCompact; return(size.Width >= maxWidth); }; //Text ViewModel.WorkspaceNameObservable .Subscribe(WorkspaceLabel.Rx().Text()) .DisposedBy(DisposeBag); ViewModel.CurrentDateRange .Subscribe(titleButton.Rx().TitleAdaptive()) .DisposedBy(DisposeBag); ViewModel.CurrentDateRange .Select(range => range == null) .DistinctUntilChanged() .Subscribe(shouldCenter => { if (shouldCenter) { activityIndicator.Frame = activityIndicatorCenteredFrame; } else { activityIndicator.Frame = activityIndicatorLeftAlignedFrame; } }) .DisposedBy(DisposeBag); //Visibility ViewModel.WorkspacesObservable .Select(areThereEnoughWorkspaces) .Do(updateWorkspaceButtonInsets) .Subscribe(WorkspaceButton.Rx().IsVisible()) .DisposedBy(DisposeBag); ViewModel.WorkspaceNameObservable .Select(isWorkspaceNameTooLong) .Subscribe(WorkspaceFadeView.Rx().FadeRight()) .DisposedBy(DisposeBag); ViewModel.IsLoadingObservable .Subscribe(activityIndicator.Rx().IsAnimating()) .DisposedBy(DisposeBag); //Commands titleButton.Rx().Tap() .Subscribe(toggleCalendar) .DisposedBy(DisposeBag); ReportsTableView.Rx().Tap() .Subscribe(HideCalendar) .DisposedBy(DisposeBag); WorkspaceButton.Rx() .BindAction(ViewModel.SelectWorkspace) .DisposedBy(DisposeBag); //Handoff viewDidAppearSubject.AsObservable() .CombineLatest( ViewModel.WorkspaceId, ViewModel.StartDate, ViewModel.EndDate, (_, workspaceId, start, end) => createUserActivity(workspaceId, start, end)) .Subscribe(updateUserActivity); NSUserActivity createUserActivity(long workspaceId, DateTimeOffset start, DateTimeOffset end) { var userActivity = new NSUserActivity(Handoff.Action.Reports); userActivity.EligibleForHandoff = true; userActivity.WebPageUrl = Handoff.Url.Reports(workspaceId, start, end); return(userActivity); } void updateUserActivity(NSUserActivity userActivity) { UserActivity = userActivity; UserActivity.BecomeCurrent(); } void toggleCalendar() { if (calendarIsVisible) { HideCalendar(); return; } if (TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Compact) { ShowCalendar(); return; } ShowPopoverCalendar(); } }