Esempio n. 1
0
 void LoadSelectedPage(UpcomingMoviesCellViewModel viewModel)
 {
     HostScreen
     .Router
     .Navigate
     .Execute(new MovieDetailViewModel(viewModel.Movie))
     .Subscribe();
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UpcomingMoviesListViewModel"/> class.
        /// </summary>
        /// <param name="mainThreadScheduler">The scheduler to use for main thread operations.</param>
        /// <param name="taskPoolScheduler">The scheduler to use for task pool operations.</param>
        /// <param name="movieService">The service to use to retrieve movie information.</param>
        /// <param name="hostScreen">The screen to use for routing operations.</param>
        public UpcomingMoviesListViewModel(
            IScheduler mainThreadScheduler = null,
            IScheduler taskPoolScheduler   = null,
            IMovieService movieService     = null,
            IScreen hostScreen             = null)
            : base("Upcoming Movies", mainThreadScheduler, taskPoolScheduler, hostScreen)
        {
            IMovieService movieService1 = movieService ?? Locator.Current.GetService <IMovieService>();

            LoadMovies    = ReactiveCommand.CreateFromObservable <int, Unit>(count => movieService1.LoadUpcomingMovies(count));
            OpenAboutView = ReactiveCommand.CreateFromObservable <Unit, IRoutableViewModel>(_ => HostScreen
                                                                                            .Router
                                                                                            .Navigate
                                                                                            .Execute(new AboutViewModel(mainThreadScheduler, taskPoolScheduler, hostScreen)));

            movieService1
            .UpcomingMovies
            .Connect()
            .SubscribeOn(TaskPoolScheduler)
            .ObserveOn(TaskPoolScheduler)
            .Transform(movie => new UpcomingMoviesCellViewModel(movie), (o, n) => o = new UpcomingMoviesCellViewModel(n))
            .DisposeMany()
            .ObserveOn(MainThreadScheduler)
            .Bind(out _movies)
            .Subscribe();

            LoadMovies.Subscribe();
            OpenAboutView.Subscribe();

            this
            .WhenAnyValue(x => x.SelectedItem)
            .Where(x => x != null)
            .SelectMany(x => HostScreen
                        .Router
                        .Navigate
                        .Execute(new MovieDetailViewModel(x.Movie)))
            .Subscribe();

            LoadMovies
            .ThrownExceptions
            .ObserveOn(MainThreadScheduler)
            .SelectMany(ex => ShowAlert.Handle(new AlertViewModel("Oops", ex.Message, "Ok")))
            .Subscribe();

            _isRefreshing =
                LoadMovies
                .IsExecuting
                .ToProperty(this, x => x.IsRefreshing, true);

            this
            .WhenAnyValue(x => x.ItemAppearing)
            .Select(item =>
            {
                int offset = -1;

                var itemIndex = Movies.IndexOf(item);
                if (itemIndex == Movies.Count - 8)
                {
                    offset = Movies.Count;
                }

                return(offset);
            })
            .Where(index => index > 0)
            .InvokeCommand(LoadMovies);
        }