Пример #1
0
        protected override void UpdateViewBinding()
        {
            //Text
            Item.BillablePercentageObservable
            .Select(billableFormattedString)
            .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.BillablePercentageObservable
            .CombineLatest(Item.TotalTimeObservable,
                           (totalTime, percentage) => totalTime == null || percentage == null)
            .Subscribe(LoadingOverviewView.Rx().IsVisibleWithFade())
            .DisposedBy(disposeBag);

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

            var totalDurationColorObservable = Item.TotalTimeIsZeroObservable
                                               .Select(isZero => isZero
                    ? Colors.Reports.Disabled.ToNativeColor()
                    : Colors.Reports.TotalTimeActivated.ToNativeColor());

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

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

            NSAttributedString billableFormattedString(float?value)
            {
                var isDisabled  = value == null;
                var actualValue = isDisabled ? 0 : value.Value;

                var percentage = $"{actualValue.ToString("0.00")}%";

                var attributes = isDisabled ? disabledAttributes : normalAttributes;

                return(new NSAttributedString(percentage, attributes));
            }

            LayoutIfNeeded();
        }
Пример #2
0
        void ReleaseDesignerOutlets()
        {
            if (BillablePercentageLabel != null)
            {
                BillablePercentageLabel.Dispose();
                BillablePercentageLabel = null;
            }

            if (BillablePercentageView != null)
            {
                BillablePercentageView.Dispose();
                BillablePercentageView = null;
            }

            if (BillableTitleLabel != null)
            {
                BillableTitleLabel.Dispose();
                BillableTitleLabel = null;
            }

            if (LoadingOverviewView != null)
            {
                LoadingOverviewView.Dispose();
                LoadingOverviewView = null;
            }

            if (OverviewCardView != null)
            {
                OverviewCardView.Dispose();
                OverviewCardView = null;
            }

            if (TotalDurationGraph != null)
            {
                TotalDurationGraph.Dispose();
                TotalDurationGraph = null;
            }

            if (TotalDurationLabel != null)
            {
                TotalDurationLabel.Dispose();
                TotalDurationLabel = null;
            }

            if (TotalTitleLabel != null)
            {
                TotalTitleLabel.Dispose();
                TotalTitleLabel = null;
            }
        }
Пример #3
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);
        }
Пример #4
0
        void ReleaseDesignerOutlets()
        {
            if (BarChartCardView != null)
            {
                BarChartCardView.Dispose();
                BarChartCardView = null;
            }

            if (BarChartContainerView != null)
            {
                BarChartContainerView.Dispose();
                BarChartContainerView = null;
            }

            if (BarsStackView != null)
            {
                BarsStackView.Dispose();
                BarsStackView = null;
            }

            if (BillableLegendLabel != null)
            {
                BillableLegendLabel.Dispose();
                BillableLegendLabel = null;
            }

            if (BillablePercentageLabel != null)
            {
                BillablePercentageLabel.Dispose();
                BillablePercentageLabel = null;
            }

            if (BillablePercentageView != null)
            {
                BillablePercentageView.Dispose();
                BillablePercentageView = null;
            }

            if (BillableTitleLabel != null)
            {
                BillableTitleLabel.Dispose();
                BillableTitleLabel = null;
            }

            if (ClockedHoursTitleLabel != null)
            {
                ClockedHoursTitleLabel.Dispose();
                ClockedHoursTitleLabel = null;
            }

            if (EmptyStateView != null)
            {
                EmptyStateView.Dispose();
                EmptyStateView = null;
            }

            if (EndDateLabel != null)
            {
                EndDateLabel.Dispose();
                EndDateLabel = null;
            }

            if (HalfHoursLabel != null)
            {
                HalfHoursLabel.Dispose();
                HalfHoursLabel = null;
            }

            if (HorizontalLegendStackView != null)
            {
                HorizontalLegendStackView.Dispose();
                HorizontalLegendStackView = null;
            }

            if (LoadingOverviewView != null)
            {
                LoadingOverviewView.Dispose();
                LoadingOverviewView = null;
            }

            if (LoadingPieChartView != null)
            {
                LoadingPieChartView.Dispose();
                LoadingPieChartView = null;
            }

            if (MaximumHoursLabel != null)
            {
                MaximumHoursLabel.Dispose();
                MaximumHoursLabel = null;
            }

            if (NonBillableLegendLabel != null)
            {
                NonBillableLegendLabel.Dispose();
                NonBillableLegendLabel = null;
            }

            if (OverviewCardView != null)
            {
                OverviewCardView.Dispose();
                OverviewCardView = null;
            }

            if (PieChartView != null)
            {
                PieChartView.Dispose();
                PieChartView = null;
            }

            if (StartDateLabel != null)
            {
                StartDateLabel.Dispose();
                StartDateLabel = null;
            }

            if (TotalDurationGraph != null)
            {
                TotalDurationGraph.Dispose();
                TotalDurationGraph = null;
            }

            if (TotalDurationLabel != null)
            {
                TotalDurationLabel.Dispose();
                TotalDurationLabel = null;
            }

            if (TotalTitleLabel != null)
            {
                TotalTitleLabel.Dispose();
                TotalTitleLabel = null;
            }

            if (ColorsLegendContainerView != null)
            {
                ColorsLegendContainerView.Dispose();
                ColorsLegendContainerView = null;
            }
        }
Пример #5
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);
            });
        }