public MovieDetailsPageViewModel(
            IRxStore <AppState> store,
            IMoviesService moviesService,
            INavigationService navigationService)
        {
            _store             = store;
            _moviesService     = moviesService;
            _navigationService = navigationService;

            CurrentMovie = _store.AsObservable()
                           .Select(x => x.Movies.CurrentMovie)
                           .ToReadOnlyReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe);

            Functions = _store.AsObservable().Select(x => x.Movies)
                        .Where(x => x.CurrentMovie != null)
                        .Select(x => x.CurrentMovie.Functions)
                        .ToReadOnlyReactiveProperty();

            BuyTicketCommand = new[] { Function.SetValidateNotifyError(f => f == null ? "You should pick a function" : null)
                                       .ObserveHasErrors }
            .CombineLatestValuesAreAllFalse()
            .ToReactiveCommand();

            BuyTicketCommand.Subscribe(OnBuyTicket);
        }
Exemple #2
0
        public PremierePageViewModel(
            IRxStore <AppState> store,
            IMoviesService service,
            INavigationService navigationService)
        {
            _store             = store;
            _service           = service;
            _navigationService = navigationService;

            Movies = _store.AsObservable().Select(x => x.Movies)
                     .Select(x => x.Movies)
                     .ToReadOnlyReactiveProperty();

            GoToMovieCommand = new Command(OnGoToMovie);
        }
Exemple #3
0
        public TicketsPageViewModel(
            IMoviesService moviesService,
            IRxStore <AppState> store)
        {
            _moviesService = moviesService;
            _store         = store;

            Tickets = store.AsObservable()
                      .Select(x => x.Tickets)
                      .Select(x => x.Tickets)
                      .ToReadOnlyReactiveProperty();

            TestCommand = new ReactiveCommand();

            TestCommand.Subscribe(() => { Test = Guid.NewGuid().ToString().Replace("-", ""); });
        }
Exemple #4
0
        public LoginPageViewModel(
            IRxStore <AppState> store,
            ILoginService loginService,
            INavigationService navigationService)
        {
            _navigationService = navigationService;

            var stateObservable = store.AsObservable().Select(x => x.Auth);

            User = new ReactiveProperty <string>(string.Empty)
                   .SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "Invalid value" : null);;
            Password = new ReactiveProperty <string>(string.Empty)
                       .SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "Invalid value" : null);;

            var validateObservable = new[] { User.ObserveHasErrors, User.ObserveHasErrors }
            .CombineLatestValuesAreAllFalse();

            var isNotLoading = stateObservable
                               .Select(s => s.LoginStatus != LoginStatus.LoginStarted);

            LoginCommand = validateObservable.Merge(isNotLoading)
                           .ToReactiveCommand()
                           .WithSubscribe(async() =>
            {
                var loginAction = loginService.LoginAsync(User.Value, Password.Value);
                var resp        = await store.Dispatch(loginAction);
                if (!resp.IsTokenError)
                {
                    await _navigationService.GoToHome();
                }
            });

            IsLoading = stateObservable
                        .Select(s => s.LoginStatus == LoginStatus.LoginStarted)
                        .ToReadOnlyReactiveProperty();

            ErrorMessage = stateObservable
                           .Select(s => s.Error).ToReadOnlyReactiveProperty();

            HasError = stateObservable
                       .Select(s => s.LoginStatus == LoginStatus.LoginError)
                       .ToReadOnlyReactiveProperty();
        }
Exemple #5
0
        public MenuViewModel(
            INavigationService navigationService,
            IRxStore <AppState> store)
        {
            _navigationService = navigationService;
            _store             = store;
            Menus = new[]
            {
                new MenuItem {
                    Description = "Premiere", Option = MenuOptions.Premiere
                },
                new MenuItem {
                    Description = "Tickets", Option = MenuOptions.Tickets
                }
            };
            GoToCommand   = new ReactiveCommand <MenuItem>();
            LogoutCommand = new ReactiveCommand();

            GoToCommand.Subscribe(OnGoTo);
            LogoutCommand.Subscribe(Logout);
        }