public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            prepareViews();

            calendarSizeDisposable = CalendarContainer.AddObserver(boundsKey, NSKeyValueObservingOptions.New, onCalendarSizeChanged);

            source                  = new ReportsTableViewSource(ReportsTableView, ViewModel);
            source.OnScroll        += onReportsTableScrolled;
            ReportsTableView.Source = source;

            bool areThereEnoughWorkspaces(ICollection <(string ItemName, IThreadSafeWorkspace Item)> workspaces) => workspaces.Count > 1;

            bool isWorkspaceNameTooLong(string workspaceName)
            {
                var attributes = new UIStringAttributes {
                    Font = WorkspaceLabel.Font
                };
                var size = new NSString(workspaceName).GetSizeUsingAttributes(attributes);

                return(size.Width >= maximumWorkspaceNameLabelWidth);
            };

            //Text
            this.Bind(ViewModel.WorkspaceNameObservable, WorkspaceLabel.Rx().Text());
            this.Bind(ViewModel.CurrentDateRangeStringObservable, titleButton.Rx().Title());

            //Visibility
            this.Bind(ViewModel.WorkspacesObservable.Select(areThereEnoughWorkspaces), WorkspaceButton.Rx().IsVisible());
            this.Bind(ViewModel.WorkspaceNameObservable.Select(isWorkspaceNameTooLong), WorkspaceFadeView.Rx().FadeRight());

            //Commands
            this.BindVoid(titleButton.Rx().Tap(), ViewModel.ToggleCalendar);
            this.BindVoid(ReportsTableView.Rx().Tap(), ViewModel.HideCalendar);
            this.Bind(WorkspaceButton.Rx().Tap(), ViewModel.SelectWorkspace);

            var bindingSet = this.CreateBindingSet <ReportsViewController, ReportsViewModel>();

            bindingSet.Bind(source).To(vm => vm.Segments);

            bindingSet.Apply();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            prepareViews();

            calendarSizeDisposable = CalendarContainer.AddObserver(boundsKey, NSKeyValueObservingOptions.New, onCalendarSizeChanged);

            source                  = new ReportsTableViewSource(ReportsTableView, ViewModel);
            source.OnScroll        += onReportsTableScrolled;
            ReportsTableView.Source = source;

            bool areThereEnoughWorkspaces(ICollection <(string ItemName, IThreadSafeWorkspace Item)> workspaces) => workspaces.Count > 1;

            bool isWorkspaceNameTooLong(string workspaceName)
            {
                var attributes = new UIStringAttributes {
                    Font = WorkspaceLabel.Font
                };
                var size = new NSString(workspaceName).GetSizeUsingAttributes(attributes);

                return(size.Width >= maximumWorkspaceNameLabelWidth);
            };

            //Text
            ViewModel.WorkspaceNameObservable
            .Subscribe(WorkspaceLabel.Rx().Text())
            .DisposedBy(DisposeBag);

            ViewModel.CurrentDateRangeStringObservable
            .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(ViewModel.ToggleCalendar)
            .DisposedBy(DisposeBag);

            ReportsTableView.Rx().Tap()
            .Subscribe(ViewModel.HideCalendar)
            .DisposedBy(DisposeBag);

            WorkspaceButton.Rx()
            .BindAction(ViewModel.SelectWorkspace)
            .DisposedBy(DisposeBag);

            ViewModel.SegmentsObservable
            .Subscribe(segments => source.ItemsSource = segments)
            .DisposedBy(DisposeBag);
        }
示例#3
0
        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();
            }
        }
示例#4
0
        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();
            }
        }