Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var source = new SelectUserCalendarsTableViewSource(TableView, ViewModel.Calendars);

            TableView.Source = source;

            this.Bind(DoneButton.Rx().Tap(), ViewModel.DoneAction);
            this.Bind(source.ItemSelected, ViewModel.SelectCalendarAction);
            this.Bind(ViewModel.DoneAction.Enabled, DoneButton.Rx().Enabled());
            this.Bind(ViewModel.DoneAction.Enabled.Select(alphaForEnabled), DoneButton.Rx().AnimatedAlpha());
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AddProjectBubbleLabel.Text = Resources.AddProjectBubbleText;

            prepareViews();
            prepareOnboarding();

            var source = new StartTimeEntryTableViewSource(SuggestionsTableView);

            SuggestionsTableView.Source = source;

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

            ViewModel.Suggestions
            .Subscribe(SuggestionsTableView.Rx().ReloadSections(source))
            .DisposedBy(DisposeBag);

            source.ToggleTasks
            .Subscribe(ViewModel.ToggleTasks.Inputs)
            .DisposedBy(DisposeBag);

            TimeInput.Rx().Duration()
            .Subscribe(ViewModel.SetRunningTime.Inputs)
            .DisposedBy(DisposeBag);

            //Text

            ViewModel.DisplayedTime
            .Subscribe(TimeLabel.Rx().Text())
            .DisposedBy(DisposeBag);

            Placeholder.Text = ViewModel.PlaceholderText;

            // Buttons
            UIColor booleanToColor(bool b) => b
                ? Colors.StartTimeEntry.ActiveButton.ToNativeColor()
                : Colors.StartTimeEntry.InactiveButton.ToNativeColor();

            ViewModel.IsBillable
            .Select(booleanToColor)
            .Subscribe(BillableButton.Rx().TintColor())
            .DisposedBy(DisposeBag);

            ViewModel.IsSuggestingTags
            .Select(booleanToColor)
            .Subscribe(TagsButton.Rx().TintColor())
            .DisposedBy(DisposeBag);

            ViewModel.IsSuggestingProjects
            .Select(booleanToColor)
            .Subscribe(ProjectsButton.Rx().TintColor())
            .DisposedBy(DisposeBag);

            //Visibility
            ViewModel.IsBillableAvailable
            .Select(b => b ? (nfloat)42 : 0)
            .Subscribe(BillableButtonWidthConstraint.Rx().Constant())
            .DisposedBy(DisposeBag);

            // Actions
            CloseButton.Rx().Tap()
            .Subscribe(ViewModel.CloseWithDefaultResult)
            .DisposedBy(DisposeBag);

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

            ViewModel.Done.Elements
            .Subscribe(IosDependencyContainer.Instance.IntentDonationService.DonateStartTimeEntry)
            .DisposedBy(DisposeBag);

            BillableButton.Rx()
            .BindAction(ViewModel.ToggleBillable)
            .DisposedBy(DisposeBag);

            StartDateButton.Rx()
            .BindAction(ViewModel.SetStartDate)
            .DisposedBy(DisposeBag);

            DateTimeButton.Rx()
            .BindAction(ViewModel.ChangeTime)
            .DisposedBy(DisposeBag);

            TagsButton.Rx()
            .BindAction(ViewModel.ToggleTagSuggestions)
            .DisposedBy(DisposeBag);

            ProjectsButton.Rx()
            .BindAction(ViewModel.ToggleProjectSuggestions)
            .DisposedBy(DisposeBag);

            // Reactive
            ViewModel.TextFieldInfo
            .DistinctUntilChanged()
            .Subscribe(onTextFieldInfo)
            .DisposedBy(DisposeBag);

            DescriptionTextView.Rx().AttributedText()
            .Select(attributedString => attributedString.Length == 0)
            .Subscribe(isDescriptionEmptySubject)
            .DisposedBy(DisposeBag);

            Observable.CombineLatest(
                DescriptionTextView.Rx().AttributedText().SelectUnit(),
                DescriptionTextView.Rx().CursorPosition().SelectUnit()
                )
            .Select(_ => DescriptionTextView.AttributedText)     // Programatically changing the text doesn't send an event, that's why we do this, to get the last version of the text
            .Do(updatePlaceholder)
            .Select(text => text.AsSpans((int)DescriptionTextView.SelectedRange.Location).ToIImmutableList())
            .Subscribe(ViewModel.SetTextSpans.Inputs)
            .DisposedBy(DisposeBag);
        }
Exemplo n.º 4
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));
            }
        }