Exemplo n.º 1
0
        public AlbumListViewModel(IFacebookPhotoService photoService = null, IViewStackService viewStackService = null)
            : base(viewStackService)
        {
            photoService = photoService ?? Locator.Current.GetService <IFacebookPhotoService>();

            LoadAlbums = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var albumData = await photoService.GetAlbumsAsync(Config.Constants.FACEBOOK_PAGE_ID, Config.Constants.FACEBOOK_PAGE_ACCESS_TOKEN, default(CancellationToken));

                var viewModels = new List <AlbumCellViewModel>(albumData.Data.Count);
                foreach (var model in albumData.Data)
                {
                    var vm = new AlbumCellViewModel(model);
                    viewModels.Add(vm);
                }

                return(viewModels);
            });

            _albums = LoadAlbums
                      .SubscribeOn(RxApp.TaskpoolScheduler)
                      .ToProperty(this, vm => vm.Albums, scheduler: RxApp.MainThreadScheduler);

            this
            .WhenAnyValue(vm => vm.SelectedItem)
            .Where(x => x != null)
            .SelectMany(x => LoadSelectedPage(x))
            .Subscribe();

            LoadAlbums
            .ThrownExceptions
            .Subscribe(ex => this.Log().WarnException("Failed to load albums", ex));
        }
Exemplo n.º 2
0
        public ArtistDetailViewModel(Artist artist)
        {
            Artist = artist;

            PopularSongs = new ReactiveList <Track> ();
            Albums       = new ReactiveList <Album> ();
            Playlists    = new ReactiveList <Playlist> ();

            var artistAvailable = this.WhenAnyValue(vm => vm.Artist)
                                  .Select(val => val != null);

            LoadPopularSongs = ReactiveCommand.CreateAsyncTask(artistAvailable, _ => Artist.MediaProvider.GetPopularTracks(Artist));
            LoadAlbums       = ReactiveCommand.CreateAsyncTask(artistAvailable, _ => Artist.MediaProvider.GetAlbums(Artist));
            LoadPlaylists    = ReactiveCommand.CreateAsyncTask(artistAvailable, _ => Artist.MediaProvider.GetPlaylists(Artist));

            LoadPopularSongs.Subscribe(tracks => {
                using (PopularSongs.SuppressChangeNotifications()) {
                    PopularSongs.Clear();
                    PopularSongs.AddRange(tracks);
                }
            });

            LoadAlbums.Subscribe(albums => {
                using (Albums.SuppressChangeNotifications()) {
                    Albums.Clear();
                    Albums.AddRange(albums);
                }
            });

            LoadPlaylists.Subscribe(playlists => {
                using (Playlists.SuppressChangeNotifications()) {
                    Playlists.Clear();
                    Playlists.AddRange(playlists);
                }
            });
        }