Exemple #1
0
        private void prepareViews()
        {
            //This is needed for the ImageView.TintColor bindings to work
            BillableButton.SetImage(
                BillableButton.ImageForState(UIControlState.Normal)
                .ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate),
                UIControlState.Normal
                );

            TimeLabel.Font = TimeLabel.Font.GetMonospacedDigitFont();

            var stringAttributes = new CTStringAttributes(
                new UIStringAttributes {
                ForegroundColor = Color.StartTimeEntry.Placeholder.ToNativeColor()
            }.Dictionary
                );

            DescriptionTextField.TintColor             = Color.StartTimeEntry.Cursor.ToNativeColor();
            DescriptionTextField.AttributedPlaceholder =
                new NSAttributedString(Resources.StartTimeEntryPlaceholder, stringAttributes);

            DescriptionTextField.BecomeFirstResponder();
        }
        void ReleaseDesignerOutlets()
        {
            if (AddProjectOnboardingBubble != null)
            {
                AddProjectOnboardingBubble.Dispose();
                AddProjectOnboardingBubble = null;
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if (AddProjectBubbleLabel != null)
            {
                AddProjectBubbleLabel.Dispose();
                AddProjectBubbleLabel = null;
            }
        }
        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);
        }
Exemple #4
0
        void ReleaseDesignerOutlets()
        {
            if (BillableButton != null)
            {
                BillableButton.Dispose();
                BillableButton = null;
            }

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

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

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

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

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

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

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

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

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

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