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)); }
private IObservable <Unit> LoadSelectedPage(AlbumCellViewModel viewModel) { return(ViewStackService.PushPage(new AlbumViewModel(viewModel.FacebookAlbum.Id))); }