public override void ViewDidLoad() { base.ViewDidLoad(); StartLabel.Text = Resources.Start; EndLabel.Text = Resources.End; TitleLabel.Text = Resources.StartAndStopTime; SetEndButton.SetTitle(Resources.Stop, UIControlState.Normal); SaveButton.SetTitle(Resources.Save, UIControlState.Normal); prepareViews(); // Actions SaveButton.Rx() .BindAction(ViewModel.Save) .DisposedBy(disposeBag); CloseButton.Rx() .BindAction(ViewModel.Close) .DisposedBy(disposeBag); // Start and stop date/time ViewModel.StartTimeString .Subscribe(StartTimeLabel.Rx().Text()) .DisposedBy(disposeBag); ViewModel.StartDateString .Subscribe(StartDateLabel.Rx().Text()) .DisposedBy(disposeBag); ViewModel.StopTimeString .Subscribe(EndTimeLabel.Rx().Text()) .DisposedBy(disposeBag); ViewModel.StopDateString .Subscribe(EndDateLabel.Rx().Text()) .DisposedBy(disposeBag); // Editing start and end time StartView.Rx() .BindAction(ViewModel.EditStartTime) .DisposedBy(disposeBag); EndView.Rx() .BindAction(ViewModel.EditStopTime) .DisposedBy(disposeBag); SetEndButton.Rx() .BindAction(ViewModel.EditStopTime) .DisposedBy(disposeBag); // Visibility ViewModel.IsRunning .Subscribe(running => { SetEndButton.Hidden = !running; EndTimeLabel.Hidden = running; EndDateLabel.Hidden = running; }) .DisposedBy(disposeBag); // Stard and end colors ViewModel.IsEditingStartTime .Select(editingStartTime => editingStartTime ? Color.EditDuration.EditedTime.ToNativeColor() : Color.EditDuration.NotEditedTime.ToNativeColor() ) .Subscribe(color => { StartTimeLabel.TextColor = color; StartDateLabel.TextColor = color; }) .DisposedBy(disposeBag); ViewModel.IsEditingStopTime .Select(editingStartTime => editingStartTime ? Color.EditDuration.EditedTime.ToNativeColor() : Color.EditDuration.NotEditedTime.ToNativeColor() ) .Subscribe(color => { EndTimeLabel.TextColor = color; EndDateLabel.TextColor = color; }) .DisposedBy(disposeBag); // Date picker ViewModel.IsEditingTime .Subscribe(DatePickerContainer.Rx().AnimatedIsVisible()) .DisposedBy(disposeBag); DatePicker.Rx().Date() .Subscribe(ViewModel.ChangeActiveTime.Inputs) .DisposedBy(disposeBag); var startTime = ViewModel.IsEditingStartTime .Where(CommonFunctions.Identity) .SelectMany(_ => ViewModel.StartTime); var stopTime = ViewModel.IsEditingStopTime .Where(CommonFunctions.Identity) .SelectMany(_ => ViewModel.StopTime); Observable.Merge(startTime, stopTime) .Subscribe(v => DatePicker.SetDate(v.ToNSDate(), false)) .DisposedBy(disposeBag); ViewModel.IsEditingStartTime .Where(CommonFunctions.Identity) .SelectMany(_ => ViewModel.StartTime) .Subscribe(v => DatePicker.SetDate(v.ToNSDate(), false)) .DisposedBy(disposeBag); ViewModel.MinimumDateTime .Subscribe(v => DatePicker.MinimumDate = v.ToNSDate()) .DisposedBy(disposeBag); ViewModel.MaximumDateTime .Subscribe(v => DatePicker.MaximumDate = v.ToNSDate()) .DisposedBy(disposeBag); ViewModel.TimeFormat .Subscribe(v => DatePicker.Locale = v.IsTwentyFourHoursFormat ? new NSLocale("en_GB") : new NSLocale("en_US")) .DisposedBy(disposeBag); // DurationInput ViewModel.IsEditingTime .Invert() .Subscribe(DurationInput.Rx().Enabled()) .DisposedBy(disposeBag); ViewModel.Duration .Subscribe(v => DurationInput.Duration = v) .DisposedBy(disposeBag); ViewModel.DurationString .Subscribe(v => DurationInput.FormattedDuration = v) .DisposedBy(disposeBag); DurationInput.Rx().Duration() .Subscribe(ViewModel.ChangeDuration.Inputs) .DisposedBy(disposeBag); // The wheel ViewModel.IsEditingTime .Invert() .Subscribe(v => WheelView.UserInteractionEnabled = v) .DisposedBy(disposeBag); ViewModel.MinimumStartTime .Subscribe(v => WheelView.MinimumStartTime = v) .DisposedBy(disposeBag); ViewModel.MaximumStartTime .Subscribe(v => WheelView.MaximumStartTime = v) .DisposedBy(disposeBag); ViewModel.MinimumStopTime .Subscribe(v => WheelView.MinimumEndTime = v) .DisposedBy(disposeBag); ViewModel.MaximumStopTime .Subscribe(v => WheelView.MaximumEndTime = v) .DisposedBy(disposeBag); ViewModel.StartTime .Subscribe(v => WheelView.StartTime = v) .DisposedBy(disposeBag); ViewModel.StopTime .Subscribe(v => WheelView.EndTime = v) .DisposedBy(disposeBag); ViewModel.IsRunning .Subscribe(v => WheelView.IsRunning = v) .DisposedBy(disposeBag); WheelView.Rx().StartTime() .Subscribe(ViewModel.ChangeStartTime.Inputs) .DisposedBy(disposeBag); WheelView.Rx().EndTime() .Subscribe(ViewModel.ChangeStopTime.Inputs) .DisposedBy(disposeBag); // Interaction observables for analytics var editingStart = Observable.Merge( StartView.Rx().Tap().SelectValue(true), EndView.Rx().Tap().SelectValue(false) ); var dateComponentChanged = DatePicker.Rx().DateComponent() .WithLatestFrom(editingStart, (_, isStart) => isStart ? EditTimeSource.BarrelStartDate : EditTimeSource.BarrelStopDate ); var timeComponentChanged = DatePicker.Rx().TimeComponent() .WithLatestFrom(editingStart, (_, isStart) => isStart ? EditTimeSource.BarrelStartTime : EditTimeSource.BarrelStopTime ); var durationInputChanged = DurationInput.Rx().Duration() .SelectValue(EditTimeSource.NumpadDuration); Observable.Merge( dateComponentChanged, timeComponentChanged, WheelView.TimeEdited, durationInputChanged ) .Distinct() .Subscribe(ViewModel.TimeEditedWithSource) .DisposedBy(disposeBag); }
public override void ViewDidLoad() { base.ViewDidLoad(); startTimeChangingSubscription = ViewModel.StartTimeChanging.Subscribe(startTimeChanging); prepareViews(); var durationCombiner = new DurationValueCombiner(); var timeCombiner = new DateTimeOffsetTimeFormatValueCombiner(TimeZoneInfo.Local); var dateCombiner = new DateTimeOffsetDateFormatValueCombiner(TimeZoneInfo.Local, useLongFormat: false); var timeFormatToLocaleConverter = new TimeFormatToLocaleValueConverter(); var inverseBoolConverter = new BoolToConstantValueConverter <bool>(false, true); var editedTimeLabelColorConverter = new BoolToConstantValueConverter <UIColor>( Color.EditDuration.EditedTime.ToNativeColor(), Color.EditDuration.NotEditedTime.ToNativeColor()); var bindingSet = this.CreateBindingSet <EditDurationViewController, EditDurationViewModel>(); //Commands bindingSet.Bind(SaveButton).To(vm => vm.SaveCommand); bindingSet.Bind(CloseButton).To(vm => vm.CloseCommand); //Start and stop date/time bindingSet.Bind(StartTimeLabel) .ByCombining(timeCombiner, vm => vm.StartTime, vm => vm.TimeFormat); bindingSet.Bind(StartDateLabel) .ByCombining(dateCombiner, vm => vm.StartTime, vm => vm.DateFormat); bindingSet.Bind(EndTimeLabel) .ByCombining(timeCombiner, vm => vm.StopTime, vm => vm.TimeFormat); bindingSet.Bind(EndDateLabel) .ByCombining(dateCombiner, vm => vm.StopTime, vm => vm.DateFormat); //Editing start and end time bindingSet.Bind(StartView) .For(v => v.BindTap()) .To(vm => vm.EditStartTimeCommand); bindingSet.Bind(EndView) .For(v => v.BindTap()) .To(vm => vm.EditStopTimeCommand); bindingSet.Bind(SetEndButton) .For(v => v.BindVisibility()) .To(vm => vm.IsRunning) .WithConversion(inverseBoolConverter); bindingSet.Bind(SetEndButton) .To(vm => vm.EditStopTimeCommand); //Visibility bindingSet.Bind(EndTimeLabel) .For(v => v.BindVisibility()) .To(vm => vm.IsRunning); bindingSet.Bind(EndDateLabel) .For(v => v.BindVisibility()) .To(vm => vm.IsRunning); //Stard and end colors bindingSet.Bind(StartTimeLabel) .For(v => v.TextColor) .To(vm => vm.IsEditingStartTime) .WithConversion(editedTimeLabelColorConverter); bindingSet.Bind(StartDateLabel) .For(v => v.TextColor) .To(vm => vm.IsEditingStartTime) .WithConversion(editedTimeLabelColorConverter); bindingSet.Bind(EndTimeLabel) .For(v => v.TextColor) .To(vm => vm.IsEditingStopTime) .WithConversion(editedTimeLabelColorConverter); bindingSet.Bind(EndDateLabel) .For(v => v.TextColor) .To(vm => vm.IsEditingStopTime) .WithConversion(editedTimeLabelColorConverter); //Date picker bindingSet.Bind(DatePickerContainer) .For(v => v.BindAnimatedVisibility()) .To(vm => vm.IsEditingTime); bindingSet.Bind(DatePicker) .For(v => v.BindDateTimeOffset()) .To(vm => vm.EditedTime); bindingSet.Bind(DatePicker) .For(v => v.MaximumDate) .To(vm => vm.MaximumDateTime); bindingSet.Bind(DatePicker) .For(v => v.MinimumDate) .To(vm => vm.MinimumDateTime); bindingSet.Bind(DatePicker) .For(v => v.Locale) .To(vm => vm.TimeFormat) .WithConversion(timeFormatToLocaleConverter); //The wheel bindingSet.Bind(DurationInput) .For(v => v.UserInteractionEnabled) .To(vm => vm.IsEditingTime) .WithConversion(inverseBoolConverter); bindingSet.Bind(DurationInput) .For(v => v.Duration) .To(vm => vm.Duration); bindingSet.Bind(DurationInput) .For(v => v.FormattedDuration) .ByCombining(durationCombiner, vm => vm.Duration, vm => vm.DurationFormat); bindingSet.Bind(WheelView) .For(v => v.UserInteractionEnabled) .To(vm => vm.IsEditingTime) .WithConversion(inverseBoolConverter); bindingSet.Bind(WheelView) .For(v => v.MaximumStartTime) .To(vm => vm.MaximumStartTime); bindingSet.Bind(WheelView) .For(v => v.MinimumStartTime) .To(vm => vm.MinimumStartTime); bindingSet.Bind(WheelView) .For(v => v.MaximumEndTime) .To(vm => vm.MaximumStopTime); bindingSet.Bind(WheelView) .For(v => v.MinimumEndTime) .To(vm => vm.MinimumStopTime); bindingSet.Bind(WheelView) .For(v => v.StartTime) .To(vm => vm.StartTime); bindingSet.Bind(WheelView) .For(v => v.EndTime) .To(vm => vm.StopTime); bindingSet.Bind(WheelView) .For(v => v.IsRunning) .To(vm => vm.IsRunning); bindingSet.Apply(); // Interaction observables for analytics var editingStart = Observable.Merge( StartView.Rx().Tap().Select(true), EndView.Rx().Tap().Select(false) ); var dateComponentChanged = DatePicker.Rx().DateComponent() .WithLatestFrom(editingStart, (_, isStart) => isStart ? EditTimeSource.BarrelStartDate : EditTimeSource.BarrelStopDate ); var timeComponentChanged = DatePicker.Rx().TimeComponent() .WithLatestFrom(editingStart, (_, isStart) => isStart ? EditTimeSource.BarrelStartTime : EditTimeSource.BarrelStopTime ); var durationInputChanged = Observable .FromEventPattern(e => DurationInput.DurationChanged += e, e => DurationInput.DurationChanged -= e) .Select(EditTimeSource.NumpadDuration); Observable.Merge( dateComponentChanged, timeComponentChanged, WheelView.TimeEdited, durationInputChanged ) .Distinct() .Subscribe(ViewModel.TimeEditedWithSource) .DisposedBy(disposeBag); }