Esempio n. 1
0
        protected override void UpdateView()
        {
            overview.Item = Item;
            barChart.Item = Item;

            //Loading chart
            Item.GroupedSegmentsObservable
            .Select(segments => segments == null)
            .Subscribe(LoadingPieChartView.Rx().IsVisibleWithFade())
            .DisposedBy(disposeBag);

            //Pretty stuff
            Item.GroupedSegmentsObservable
            .Subscribe(groupedSegments => PieChartView.Segments = groupedSegments)
            .DisposedBy(disposeBag);

            Item.IsLoadingObservable
            .Select(CommonFunctions.Invert)
            .Subscribe(BarChartContainerView.Rx().IsVisible())
            .DisposedBy(disposeBag);

            //Visibility
            Item.ShowEmptyStateObservable
            .Subscribe(EmptyStateView.Rx().IsVisible())
            .DisposedBy(disposeBag);
        }
Esempio n. 2
0
        protected override void UpdateView()
        {
            //Text
            var reportPercentageConverter = new ReportPercentageLabelValueConverter();

            Item.BillablePercentageObservable
            .Select(reportPercentageConverter.Convert)
            .Subscribe(BillablePercentageLabel.Rx().AttributedText())
            .DisposedBy(disposeBag);

            Item.TotalTimeObservable
            .CombineLatest(Item.DurationFormatObservable,
                           (totalTime, durationFormat) => totalTime.ToFormattedString(durationFormat))
            .Subscribe(TotalDurationLabel.Rx().Text())
            .DisposedBy(disposeBag);

            //Loading chart
            Item.IsLoadingObservable
            .Subscribe(LoadingPieChartView.Rx().IsVisibleWithFade())
            .DisposedBy(disposeBag);

            Item.IsLoadingObservable
            .Subscribe(LoadingOverviewView.Rx().IsVisibleWithFade())
            .DisposedBy(disposeBag);

            //Pretty stuff
            Item.GroupedSegmentsObservable
            .Subscribe(groupedSegments => PieChartView.Segments = groupedSegments)
            .DisposedBy(disposeBag);

            Item.BillablePercentageObservable
            .Subscribe(percentage => BillablePercentageView.Percentage = percentage)
            .DisposedBy(disposeBag);

            var totalDurationColorObservable = Item.TotalTimeIsZeroObservable
                                               .Select(isZero => isZero
                    ? Foundation.MvvmCross.Helper.Color.Reports.Disabled.ToNativeColor()
                    : Foundation.MvvmCross.Helper.Color.Reports.TotalTimeActivated.ToNativeColor());

            totalDurationColorObservable
            .Subscribe(TotalDurationGraph.Rx().TintColor())
            .DisposedBy(disposeBag);

            totalDurationColorObservable
            .Subscribe(TotalDurationLabel.Rx().TextColor())
            .DisposedBy(disposeBag);

            // Bar chart
            Item.WorkspaceHasBillableFeatureEnabled
            .Subscribe(ColorsLegendContainerView.Rx().IsVisible())
            .DisposedBy(disposeBag);

            Item.StartDate
            .CombineLatest(
                Item.BarChartViewModel.DateFormat,
                (startDate, format) => startDate.ToString(format.Short, CultureInfo.InvariantCulture))
            .Subscribe(StartDateLabel.Rx().Text())
            .DisposedBy(disposeBag);

            Item.EndDate
            .CombineLatest(
                Item.BarChartViewModel.DateFormat,
                (endDate, format) => endDate.ToString(format.Short, CultureInfo.InvariantCulture))
            .Subscribe(EndDateLabel.Rx().Text())
            .DisposedBy(disposeBag);

            Item.BarChartViewModel.MaximumHoursPerBar
            .Select(hours => $"{hours} h")
            .Subscribe(MaximumHoursLabel.Rx().Text())
            .DisposedBy(disposeBag);

            Item.BarChartViewModel.MaximumHoursPerBar
            .Select(hours => $"{hours / 2} h")
            .Subscribe(HalfHoursLabel.Rx().Text())
            .DisposedBy(disposeBag);

            Item.BarChartViewModel.HorizontalLegend
            .Where(legend => legend == null)
            .Subscribe((DateTimeOffset[] _) =>
            {
                HorizontalLegendStackView.Subviews.ForEach(subview => subview.RemoveFromSuperview());
                StartDateLabel.Hidden = false;
                EndDateLabel.Hidden   = false;
            })
            .DisposedBy(disposeBag);

            Item.BarChartViewModel.HorizontalLegend
            .Where(legend => legend != null)
            .CombineLatest(Item.BarChartViewModel.DateFormat, createHorizontalLegendLabels)
            .Do(_ =>
            {
                StartDateLabel.Hidden = true;
                EndDateLabel.Hidden   = true;
            })
            .Subscribe(HorizontalLegendStackView.Rx().ArrangedViews())
            .DisposedBy(disposeBag);

            Item.BarChartViewModel.Bars
            .Select(createBarViews)
            .Subscribe(BarsStackView.Rx().ArrangedViews())
            .DisposedBy(disposeBag);

            var spacingObservable = Item.BarChartViewModel.Bars
                                    .CombineLatest(updateLayout, (bars, _) => bars)
                                    .Select(bars => BarsStackView.Frame.Width / bars.Length * barChartSpacingProportion);

            spacingObservable
            .Subscribe(BarsStackView.Rx().Spacing())
            .DisposedBy(disposeBag);

            spacingObservable
            .Subscribe(HorizontalLegendStackView.Rx().Spacing())
            .DisposedBy(disposeBag);

            Item.IsLoadingObservable
            .Select(CommonFunctions.Invert)
            .Subscribe(BarChartContainerView.Rx().IsVisible())
            .DisposedBy(disposeBag);

            //Visibility
            Item.ShowEmptyStateObservable
            .Subscribe(EmptyStateView.Rx().IsVisible())
            .DisposedBy(disposeBag);
        }
Esempio n. 3
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            TotalTitleLabel.Text        = Resources.Total.ToUpper();
            BillableTitleLabel.Text     = Resources.Billable.ToUpper();
            ClockedHoursTitleLabel.Text = Resources.ClockedHours.ToUpper();
            BillableLegendLabel.Text    = Resources.Billable.ToUpper();
            NonBillableLegendLabel.Text = Resources.NonBillable.ToUpper();

            var templateImage = TotalDurationGraph.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);

            TotalDurationGraph.Image = templateImage;

            prepareViews();

            this.DelayBind(() =>
            {
                //Text
                var reportPercentageConverter = new ReportPercentageLabelValueConverter();
                ViewModel.BillablePercentageObservable
                .Select(reportPercentageConverter.Convert)
                .Subscribe(BillablePercentageLabel.Rx().AttributedText())
                .DisposedBy(disposeBag);

                ViewModel.TotalTimeObservable
                .CombineLatest(ViewModel.DurationFormatObservable,
                               (totalTime, durationFormat) => totalTime.ToFormattedString(durationFormat))
                .Subscribe(TotalDurationLabel.Rx().Text())
                .DisposedBy(disposeBag);

                //Loading chart
                ViewModel.IsLoadingObservable
                .Subscribe(LoadingPieChartView.Rx().IsVisibleWithFade())
                .DisposedBy(disposeBag);

                ViewModel.IsLoadingObservable
                .Subscribe(LoadingOverviewView.Rx().IsVisibleWithFade())
                .DisposedBy(disposeBag);

                //Pretty stuff
                ViewModel.GroupedSegmentsObservable
                .Subscribe(groupedSegments => PieChartView.Segments = groupedSegments)
                .DisposedBy(disposeBag);

                ViewModel.BillablePercentageObservable
                .Subscribe(percentage => BillablePercentageView.Percentage = percentage)
                .DisposedBy(disposeBag);

                var totalDurationColorObservable = ViewModel.TotalTimeIsZeroObservable
                                                   .Select(isZero => isZero
                        ? Foundation.MvvmCross.Helper.Color.Reports.Disabled.ToNativeColor()
                        : Foundation.MvvmCross.Helper.Color.Reports.TotalTimeActivated.ToNativeColor());

                totalDurationColorObservable
                .Subscribe(TotalDurationGraph.Rx().TintColor())
                .DisposedBy(disposeBag);

                totalDurationColorObservable
                .Subscribe(TotalDurationLabel.Rx().TextColor())
                .DisposedBy(disposeBag);
                // Bar chart

                if (ViewModel == null)
                {
                    throw new InvalidOperationException($"The {nameof(ViewModel)} value must be set for {nameof(ReportsHeaderView)} before defining bindings.");
                }

                ViewModel.WorkspaceHasBillableFeatureEnabled
                .Subscribe(ColorsLegendContainerView.Rx().IsVisible())
                .DisposedBy(disposeBag);

                ViewModel.StartDate
                .CombineLatest(
                    ViewModel.BarChartViewModel.DateFormat,
                    (startDate, format) => startDate.ToString(format.Short, CultureInfo.InvariantCulture))
                .Subscribe(StartDateLabel.Rx().Text())
                .DisposedBy(disposeBag);

                ViewModel.EndDate
                .CombineLatest(
                    ViewModel.BarChartViewModel.DateFormat,
                    (endDate, format) => endDate.ToString(format.Short, CultureInfo.InvariantCulture))
                .Subscribe(EndDateLabel.Rx().Text())
                .DisposedBy(disposeBag);

                ViewModel.BarChartViewModel.MaximumHoursPerBar
                .Select(hours => $"{hours} h")
                .Subscribe(MaximumHoursLabel.Rx().Text())
                .DisposedBy(disposeBag);

                ViewModel.BarChartViewModel.MaximumHoursPerBar
                .Select(hours => $"{hours / 2} h")
                .Subscribe(HalfHoursLabel.Rx().Text())
                .DisposedBy(disposeBag);

                ViewModel.BarChartViewModel.HorizontalLegend
                .Where(legend => legend == null)
                .Subscribe((DateTimeOffset[] _) =>
                {
                    HorizontalLegendStackView.Subviews.ForEach(subview => subview.RemoveFromSuperview());
                    StartDateLabel.Hidden = false;
                    EndDateLabel.Hidden   = false;
                })
                .DisposedBy(disposeBag);

                ViewModel.BarChartViewModel.HorizontalLegend
                .Where(legend => legend != null)
                .CombineLatest(ViewModel.BarChartViewModel.DateFormat, createHorizontalLegendLabels)
                .Do(_ =>
                {
                    StartDateLabel.Hidden = true;
                    EndDateLabel.Hidden   = true;
                })
                .Subscribe(HorizontalLegendStackView.Rx().ArrangedViews())
                .DisposedBy(disposeBag);

                ViewModel.BarChartViewModel.Bars
                .Select(createBarViews)
                .Subscribe(BarsStackView.Rx().ArrangedViews())
                .DisposedBy(disposeBag);

                var spacingObservable = ViewModel.BarChartViewModel.Bars
                                        .CombineLatest(updateLayout, (bars, _) => bars)
                                        .Select(bars => BarsStackView.Frame.Width / bars.Length * barChartSpacingProportion);

                spacingObservable
                .Subscribe(BarsStackView.Rx().Spacing())
                .DisposedBy(disposeBag);

                spacingObservable
                .Subscribe(HorizontalLegendStackView.Rx().Spacing())
                .DisposedBy(disposeBag);

                ViewModel.IsLoadingObservable
                .Select(CommonFunctions.Invert)
                .Subscribe(BarChartContainerView.Rx().IsVisible())
                .DisposedBy(disposeBag);

                //Visibility
                ViewModel.ShowEmptyStateObservable
                .Subscribe(EmptyStateView.Rx().IsVisible())
                .DisposedBy(disposeBag);
            });
        }