コード例 #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeadingLabel.Text     = Resources.SelectCalendars;
            DescriptionLabel.Text = Resources.SelectCalendarsDescription;
            DoneButton.SetTitle(Resources.Done, UIControlState.Normal);

            var source = new SelectUserCalendarsTableViewSource(TableView);

            TableView.Source = source;

            DoneButton.Rx()
            .BindAction(ViewModel.Done)
            .DisposedBy(DisposeBag);

            source.Rx().ModelSelected()
            .Subscribe(ViewModel.SelectCalendar.Inputs)
            .DisposedBy(DisposeBag);

            ViewModel.Done.Enabled
            .Subscribe(DoneButton.Rx().Enabled())
            .DisposedBy(DisposeBag);

            ViewModel.Done.Enabled
            .Select(alphaForEnabled)
            .Subscribe(DoneButton.Rx().AnimatedAlpha())
            .DisposedBy(DisposeBag);

            ViewModel.Calendars
            .Subscribe(TableView.Rx().ReloadSections(source))
            .DisposedBy(DisposeBag);
        }
コード例 #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NameTakenErrorLabel.Text  = Resources.NameTakenError;
            TitleLabel.Text           = Resources.NewProject;
            NameTextField.Placeholder = Resources.ProjectName;
            DoneButton.SetTitle(Resources.Create, UIControlState.Normal);

            var heightConverter = new BoolToConstantValueConverter <nfloat>(nameAlreadyTakenHeight, 0);

            var bindingSet = this.CreateBindingSet <EditProjectViewController, EditProjectViewModel>();

            PrivateProjectSwitch.SetState(ViewModel.IsPrivate, false);

            //Commands
            bindingSet.Bind(DoneButton).To(vm => vm.DoneCommand);
            bindingSet.Bind(CloseButton).To(vm => vm.CloseCommand);
            bindingSet.Bind(ColorPickerOpeningView)
            .For(v => v.BindTap())
            .To(vm => vm.PickColorCommand);

            bindingSet.Bind(ClientLabel)
            .For(v => v.BindTap())
            .To(vm => vm.PickClientCommand);

            bindingSet.Bind(WorkspaceLabel)
            .For(v => v.BindTap())
            .To(vm => vm.PickWorkspaceCommand);

            bindingSet.Bind(ProjectNameUsedErrorTextHeight)
            .For(v => v.Constant)
            .To(vm => vm.IsNameAlreadyTaken)
            .WithConversion(heightConverter);

            bindingSet.Bind(PrivateProjectSwitch)
            .For(v => v.BindValueChanged())
            .To(vm => vm.TogglePrivateProjectCommand);

            //State
            bindingSet.Bind(NameTextField).To(vm => vm.Name);
            bindingSet.Bind(WorkspaceLabel).To(vm => vm.WorkspaceName);

            bindingSet.Bind(ColorCircleView)
            .For(v => v.BackgroundColor)
            .To(vm => vm.Color)
            .WithConversion(new MvxNativeColorValueConverter());

            bindingSet.Bind(DoneButton)
            .For(v => v.Enabled)
            .To(vm => vm.SaveEnabled);

            bindingSet.Bind(ClientLabel)
            .For(v => v.AttributedText)
            .To(vm => vm.ClientName)
            .WithConversion(new AddNewAttributedStringConverter(Resources.AddClient, ClientLabel.Font.CapHeight));

            bindingSet.Apply();
        }
コード例 #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            TitleLabel.Text           = Resources.NewProject;
            NameTextField.Placeholder = Resources.ProjectName;
            ErrorLabel.Text           = Resources.ProjectNameTakenError;
            DoneButton.SetTitle(Resources.Create, UIControlState.Normal);
            ProjectNameUsedErrorTextHeight.Constant = 0;

            // Name
            NameTextField.Rx().Text()
            .Subscribe(ViewModel.Name.Accept)
            .DisposedBy(DisposeBag);

            ViewModel.Name
            .Subscribe(NameTextField.Rx().TextObserver())
            .DisposedBy(DisposeBag);

            // Color
            ColorPickerOpeningView.Rx()
            .BindAction(ViewModel.PickColor)
            .DisposedBy(DisposeBag);

            ViewModel.Color
            .Select(color => color.ToNativeColor())
            .Subscribe(ColorCircleView.Rx().BackgroundColor())
            .DisposedBy(DisposeBag);

            // Error
            ViewModel.Error
            .Subscribe(ErrorLabel.Rx().Text())
            .DisposedBy(DisposeBag);

            ViewModel.Error
            .Select(e => string.IsNullOrEmpty(e) ? new nfloat(0) : errorVisibleHeight)
            .Subscribe(ProjectNameUsedErrorTextHeight.Rx().Constant())
            .DisposedBy(DisposeBag);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                ViewModel.Error
                .Select(e => string.IsNullOrEmpty(e) ? desiredIpadHeight : errorVisibleHeight + desiredIpadHeight)
                .Select(h => new CGSize(0, h))
                .Subscribe(this.Rx().PreferredContentSize())
                .DisposedBy(DisposeBag);
            }

            // Workspace
            WorkspaceLabel.Rx()
            .BindAction(ViewModel.PickWorkspace)
            .DisposedBy(DisposeBag);

            ViewModel.WorkspaceName
            .Subscribe(WorkspaceLabel.Rx().Text())
            .DisposedBy(DisposeBag);

            // Client
            ClientLabel.Rx()
            .BindAction(ViewModel.PickClient)
            .DisposedBy(DisposeBag);

            var emptyText = Resources.AddClient.PrependWithAddIcon(ClientLabel.Font.CapHeight);

            ViewModel.ClientName
            .Select(attributedClientName)
            .Subscribe(ClientLabel.Rx().AttributedText())
            .DisposedBy(DisposeBag);

            // Is Private
            PrivateProjectSwitchContainer.Rx().Tap()
            .Select(_ => PrivateProjectSwitch.On)
            .Subscribe(ViewModel.IsPrivate.Accept)
            .DisposedBy(DisposeBag);

            ViewModel.IsPrivate
            .Subscribe(PrivateProjectSwitch.Rx().On())
            .DisposedBy(DisposeBag);

            // Save
            DoneButton.Rx()
            .BindAction(ViewModel.Save)
            .DisposedBy(DisposeBag);

            CloseButton.Rx()
            .BindAction(ViewModel.Close)
            .DisposedBy(DisposeBag);

            NSAttributedString attributedClientName(string clientName)
            {
                if (string.IsNullOrEmpty(clientName))
                {
                    return(emptyText);
                }

                return(new NSAttributedString(clientName));
            }
        }