protected override void UpdateViewBinding() { // 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); }
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); }
public override void AwakeFromNib() { base.AwakeFromNib(); var templateImage = TotalDurationGraph.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); TotalDurationGraph.Image = templateImage; prepareViews(); var colorConverter = new BoolToConstantValueConverter <UIColor>( Color.Reports.Disabled.ToNativeColor(), Color.Reports.TotalTimeActivated.ToNativeColor() ); var durationCombiner = new DurationValueCombiner(); this.DelayBind(() => { var bindingSet = this.CreateBindingSet <ReportsHeaderView, ReportsViewModel>(); //Text bindingSet.Bind(BillablePercentageLabel) .For(v => v.AttributedText) .To(vm => vm.BillablePercentage) .WithConversion(new ReportPercentageLabelValueConverter()); bindingSet.Bind(TotalDurationLabel) .For(v => v.Text) .ByCombining(durationCombiner, vm => vm.TotalTime, vm => vm.DurationFormat); //Loading chart bindingSet.Bind(LoadingPieChartView) .For(v => v.BindVisibilityWithFade()) .To(vm => vm.IsLoading); bindingSet.Bind(LoadingCardView) .For(v => v.BindVisibilityWithFade()) .To(vm => vm.IsLoading); //Pretty stuff bindingSet.Bind(PieChartView) .For(v => v.Segments) .To(vm => vm.GroupedSegments); bindingSet.Bind(BillablePercentageView) .For(v => v.Percentage) .To(vm => vm.BillablePercentage); bindingSet.Bind(TotalDurationGraph) .For(v => v.TintColor) .To(vm => vm.TotalTimeIsZero) .WithConversion(colorConverter); bindingSet.Bind(TotalDurationLabel) .For(v => v.TextColor) .To(vm => vm.TotalTimeIsZero) .WithConversion(colorConverter); // 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)) .Subscribe(StartDateLabel.Rx().Text()) .DisposedBy(disposeBag); ViewModel.EndDate .CombineLatest( ViewModel.BarChartViewModel.DateFormat, (endDate, format) => endDate.ToString(format.Short)) .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 bindingSet.Bind(EmptyStateView) .For(v => v.BindVisible()) .To(vm => vm.ShowEmptyState); bindingSet.Apply(); }); }
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); }); }