示例#1
0
 private IObservable <Unit> cancel()
 => FeedbackText.FirstAsync()
 .Select(string.IsNullOrEmpty)
 .SelectMany(isEmpty => isEmpty
             ? Observable.Return(true)
             : dialogService.ConfirmDestructiveAction(ActionType.DiscardFeedback))
 .DoIf(shouldBeClosed => shouldBeClosed, _ => navigationService.Close(this, false))
 .SelectUnit();
        private async Task <bool> close()
        {
            if (isDirty)
            {
                var shouldDiscard = await dialogService.ConfirmDestructiveAction(ActionType.DiscardNewTimeEntry);

                if (!shouldDiscard)
                {
                    return(false);
                }
            }

            await navigationService.Close(this);

            return(true);
        }
示例#3
0
        public SendFeedbackViewModel(
            IMvxNavigationService navigationService,
            IInteractorFactory interactorFactory,
            IDialogService dialogService,
            ISchedulerProvider schedulerProvider
            )
        {
            Ensure.Argument.IsNotNull(interactorFactory, nameof(interactorFactory));
            Ensure.Argument.IsNotNull(navigationService, nameof(navigationService));
            Ensure.Argument.IsNotNull(dialogService, nameof(dialogService));
            Ensure.Argument.IsNotNull(schedulerProvider, nameof(schedulerProvider));

            IsFeedbackEmpty = FeedbackText
                              .Select(text => string.IsNullOrEmpty(text))
                              .DistinctUntilChanged()
                              .StartWith(true)
                              .AsDriver(schedulerProvider);

            SendEnabled = Observable.CombineLatest(
                IsFeedbackEmpty,
                isLoading.AsObservable(),
                (isEmpty, isLoading) => !isEmpty && !isLoading
                )
                          .AsDriver(schedulerProvider);

            CloseButtonTapped
            .WithLatestFrom(IsFeedbackEmpty, (_, isEmpty) => isEmpty)
            .SelectMany(isEmpty =>
            {
                if (isEmpty)
                {
                    return(Observable.Return(true));
                }
                return(dialogService.ConfirmDestructiveAction(ActionType.DiscardFeedback));
            })
            .Where(shouldDiscard => shouldDiscard)
            .Do(_ =>
            {
                navigationService.Close(this, false);
            })
            .Subscribe()
            .DisposedBy(disposeBag);

            ErrorViewTapped
            .Do(e => errorViewVisible.OnNext(false))
            .Subscribe()
            .DisposedBy(disposeBag);

            SendButtonTapped
            .WithLatestFrom(FeedbackText, (_, text) => text)
            .Do(_ =>
            {
                isLoading.OnNext(true);
                errorViewVisible.OnNext(false);
            })
            .SelectMany(text => interactorFactory
                        .SendFeedback(text)
                        .Execute()
                        .Materialize()
                        )
            .Do(notification =>
            {
                isLoading.OnNext(false);
                switch (notification.Kind)
                {
                case NotificationKind.OnError:
                    errorViewVisible.OnNext(true);
                    break;

                default:
                    navigationService.Close(this, true);
                    break;
                }
            })
            .Subscribe()
            .DisposedBy(disposeBag);

            ErrorViewVisible = errorViewVisible.AsDriver(true, schedulerProvider);
            IsLoading        = isLoading.AsDriver(false, schedulerProvider);
        }