Exemple #1
0
 public AlbumViewModel(SynoItem album)
 {
     this.Album             = album;
     this.Tracks            = new ObservableCollection <TrackViewModel>();
     SelectedCommand        = new DelegateCommand(OnSelected);
     SelectAllOrNoneCommand = new DelegateCommand(OnSelectAllOrNone, () => this.Tracks.Count > 0);
 }
Exemple #2
0
        public ArtistPanoramaViewModel(SynoItem artist, IEnumerable <AlbumViewModel> albums, int activePanelIndex, ISearchService searchService, IEventAggregator eventAggregator, IPageSwitchingService pageSwitchingService, INotificationService notificationService)
        {
            if (searchService == null)
            {
                throw new ArgumentNullException("searchService");
            }

            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }

            if (pageSwitchingService == null)
            {
                throw new ArgumentNullException("pageSwitchingService");
            }

            if (artist == null)
            {
                throw new ArgumentNullException("artist");
            }
            if (albums == null)
            {
                throw new ArgumentNullException("albums");
            }

            PlayLastCommand           = new DelegateCommand(OnPlayLast);
            PlayCommand               = new DelegateCommand(OnPlay);
            CurrentArtistItemIndex    = activePanelIndex;
            _searchService            = searchService;
            this._notificationService = notificationService;

            // TODO : Use IoC or Factory or whatever, but something to be able to inject our own implementation
            _panoramaItemSwitchingService = new PanoramaItemSwitchingService();

            _panoramaItemSwitchingService.ActiveItemChangeRequested += (s, e) => CurrentArtistItemIndex = e.NewItemIndex;
            _eventAggregator      = eventAggregator;
            _pageSwitchingService = pageSwitchingService;
            this.ArtistAlbums     = new ObservableCollection <AlbumViewModel>();
            foreach (var albumViewModel in albums)
            {
                this.ArtistAlbums.Add(albumViewModel);
            }

            this.ArtistAlbums.CollectionChanged += StartMonitoringElements;
            foreach (var album in this.ArtistAlbums)
            {
                album.PropertyChanged += UpdateBusyness;
            }

            ShowPlayQueueCommand = new DelegateCommand(OnShowPlayQueue);
            _artist    = artist;
            ArtistName = _artist.Title;
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchResultItemViewModel"/> class.
 /// </summary>
 /// <param name="itemInfo">The item info.</param>
 /// <param name="eventAggregator">The event aggregator.</param>
 /// <param name="pageSwitchingService">The page switching service.</param>
 /// <param name="urlParameterToObjectsPlateHeater"></param>
 public SearchResultItemViewModel(SynoItem itemInfo, IEventAggregator eventAggregator, IPageSwitchingService pageSwitchingService, IUrlParameterToObjectsPlateHeater urlParameterToObjectsPlateHeater)
 {
     if (itemInfo == null)
     {
         throw new ArgumentNullException("itemInfo");
     }
     ItemSelectedCommand               = new DelegateCommand(OnItemSelected);
     ItemInfo                          = itemInfo;
     _eventAggregator                  = eventAggregator;
     _pageSwitchingService             = pageSwitchingService;
     _urlParameterToObjectsPlateHeater = urlParameterToObjectsPlateHeater;
 }
        private void OnArtistPanoramaViewLoaded(object sender, RoutedEventArgs e)
        {
            // the page is an humble object, and the navigatorService, its sole dependency.
            var navigator = IoC.Container.Get <INavigatorService>();

            navigator.ActivateNavigationService(NavigationService, true);

            if (DataContext == null)
            {
                var artistTicket       = NavigationContext.QueryString["artistTicket"];
                var artistAlbumsTicket = NavigationContext.QueryString["albumsListTicket"];

                if (_newPageInstance && State.ContainsKey(ArtistPanoramaViewCurrentArtist))
                {
                    _artist = (SynoItem)this.State[ArtistPanoramaViewCurrentArtist];
                }
                else
                {
                    _artist = (SynoItem)navigator.UrlParameterToObjectsPlateHeater.GetObjectForTicket(artistTicket);
                }

                IEnumerable <SynoItem>       artistItems = null;
                IEnumerable <AlbumViewModel> albumViewModels;
                if (_newPageInstance && State.ContainsKey(ArtistPanoramaViewItems))
                {
                    throw new NotImplementedException("deal with the viewmodels not with the synoitems anymore here");
                    artistItems = (IEnumerable <SynoItem>) this.State[ArtistPanoramaViewItems];
                    //artistPanoramaViewModel.BuildArtistItems(_artistItems);
                }
                else
                {
                    //artistPanoramaViewModel.QueryAndBuildArtistItems();
                    albumViewModels = (IEnumerable <AlbumViewModel>)navigator.UrlParameterToObjectsPlateHeater.GetObjectForTicket(artistAlbumsTicket);
                }
                var albumTicket = NavigationContext.QueryString["albumTicket"];

                int artistPanoramaViewActivePanelIndex = 0;

                if (_newPageInstance && State.ContainsKey(ArtistPanoramaViewCurrentArtist))
                {
                    artistPanoramaViewActivePanelIndex = (int)this.State[ArtistPanoramaViewActivePanelIndex];
                }
                else
                {
                    var album = (AlbumViewModel)navigator.UrlParameterToObjectsPlateHeater.GetObjectForTicket(albumTicket);
                    artistPanoramaViewActivePanelIndex = albumViewModels.ToList().IndexOf(album);
                }
                ArtistPanoramaViewModel artistPanoramaViewModel = IoC.Container.Get <ArtistPanoramaViewModelFactory>().Create(this._artist, albumViewModels, artistPanoramaViewActivePanelIndex);

                DataContext = artistPanoramaViewModel;
            }
        }
        private void GetSimilarArtistsAsync(SynoItem artist)
        {
            // TODO : Look on last.fm
            LastFmApi api = new LastFmApi();
            var       t   = api.GetSimilarArtistsAsync(artist.Title);

            t.ContinueWith(o =>
            {
                SimilarArtists.Clear();
                foreach (var lastFmArtist in o.Result)
                {
                    // FIXME : USe a factory.
                    SimilarArtists.Add(new ArtistViewModel(lastFmArtist.Name, lastFmArtist.Mbid, lastFmArtist.Url, lastFmArtist.Match, lastFmArtist.Images));
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var navigator = IoC.Container.Get <INavigatorService>();

            navigator.ActivateNavigationService(NavigationService, true);

            if (DataContext == null)
            {
                var viewModelFactory = IoC.Container.Get <ArtistDetailViewModelFactory>();

                string ticket = this.NavigationContext.QueryString["artistTicket"];

                SynoItem artist = (SynoItem)navigator.UrlParameterToObjectsPlateHeater.GetObjectForTicket(ticket);

                DataContext = viewModelFactory.Create(artist);
            }
        }
 public ArtistDetailViewModel(SynoItem artist, ISearchService searchService, AlbumViewModelFactory albumViewModelFactory, INavigatorService navigatorSevice, IPageSwitchingService pageSwitchingService, ITrackViewModelFactory trackViewModelFactory)
 {
     if (trackViewModelFactory == null)
     {
         throw new ArgumentNullException("trackViewModelFactory");
     }
     this.Albums            = new ObservableCollection <AlbumViewModel>();
     this.ArtistName        = artist.Title;
     this.SimilarArtists    = new ObservableCollection <IArtistViewModel>();
     this._searchService    = searchService;
     _albumViewModelFactory = albumViewModelFactory;
     _navigatorSevice       = navigatorSevice;
     _pageSwitchingService  = pageSwitchingService;
     _trackViewModelFactory = trackViewModelFactory;
     this.PopulateAlbumsAsync(artist);
     GetSimilarArtistsAsync(artist);
 }
        public void GetTracksForAlbum(SynoItem album, Action <IEnumerable <SynoTrack>, long, SynoItem> callback)
        {
            List <SynoTrack> tracks = new List <SynoTrack>();

            tracks.Add(new SynoTrack {
                Album = "Alice", Artist = "Tom Waits", Title = "Alice"
            });
            tracks.Add(new SynoTrack {
                Album = "Alice", Artist = "Tom Waits", Title = "Flower's grave"
            });
            tracks.Add(new SynoTrack {
                Album = "Alice", Artist = "Tom Waits", Title = "Kommeniedzuspedt"
            });
            tracks.Add(new SynoTrack {
                Album = "Alice", Artist = "Tom Waits", Title = "Poor Edward"
            });
            tracks.Add(new SynoTrack {
                Album = "Alice", Artist = "Tom Waits", Title = "Bacarole"
            });
            tracks.Add(new SynoTrack {
                Album = "Alice", Artist = "Tom Waits", Title = "Fawn"
            });
            callback(tracks, tracks.Count, album);
        }
        private void PopulateAlbumsAsync(SynoItem artist)
        {
            // TODO : request albums.

            _searchService.GetAlbumsForArtist(artist, GetAlbumsForArtistCallback);
        }
        //public ArtistPanoramaViewModel Create(SynoItem artist, IEnumerable<SynoItem> artistItems)
        //{
        //    ArtistPanoramaViewModel artistPanoramaViewModel = new ArtistPanoramaViewModel(this._searchService, this._eventAggregator, this._pageSwitchingService, artist, this._notificationService);
        //    artistPanoramaViewModel.BuildArtistItems(artistItems);
        //    return artistPanoramaViewModel;
        //}
        public ArtistPanoramaViewModel Create(SynoItem artist, IEnumerable <AlbumViewModel> albumViewModels, int artistPanoramaViewActivePanelIndex)
        {
            var artistPanoramaViewModel = new ArtistPanoramaViewModel(artist, albumViewModels, artistPanoramaViewActivePanelIndex, this._searchService, this._eventAggregator, this._pageSwitchingService, this._notificationService);

            return(artistPanoramaViewModel);
        }
 public ArtistDetailViewModel Create(SynoItem artist)
 {
     return(new ArtistDetailViewModel(artist, _searchService, _albumViewModelFactory, this._navigatorSevice, this._pageSwitchingService, this._session));
 }
        private void GetAlbumsForArtistCallback(IEnumerable <SynoItem> albums, long totalAlbumsCount, SynoItem artist)
        {
            foreach (var album in albums)
            {
                AlbumViewModel albumViewModel = _albumViewModelFactory.Create(album);

                // prepare an empty track list
                albumViewModel.Tracks.Clear();

                // album is busy because its tracks are getting loaded.
                albumViewModel.IsBusy = true;

                _searchService.GetTracksForAlbum(album, (synoTracks, count, containingAlbum) =>
                {
                    // Note - would it work, based on the synoitem instead of the ItemID ?
                    // Note - we rely on the fact that there each album is only present once in the artists discography ( based on its ItemID ) otherwise, it crashes !
                    var currentAlbumViewModel = Albums.Single(a => a.Album.ItemID == containingAlbum.ItemID);
                    currentAlbumViewModel.Tracks.Clear();
                    foreach (var track in synoTracks)
                    {
                        // track guid is empty for now : it will be filled when the track gets added to the playqueue
                        currentAlbumViewModel.Tracks.Add(this._trackViewModelFactory.Create(Guid.Empty, track, this._pageSwitchingService));
                    }
                    currentAlbumViewModel.IsBusy = false;
                });

                // TODO : Register Selected event and on event handler : Load the album's tracks and navigate to its index in the artist's albums panorama.
                // Note : So far, the viewmodels are never removed from the list : that means we don't need to unregister that event. If this changes,
                // then it will be necessary to enregister the event for each view model removed from the collection.
                albumViewModel.Selected += (s, e) =>
                {
                    string albumId = ((AlbumViewModel)s).Album.ItemID;
                    _navigatorSevice.UrlParameterToObjectsPlateHeater.RegisterObject(albumId, s);
                    _navigatorSevice.UrlParameterToObjectsPlateHeater.RegisterObject(artist.ItemID, artist);
                    Guid albumsListTicket = Guid.NewGuid();
                    _navigatorSevice.UrlParameterToObjectsPlateHeater.RegisterObject(albumsListTicket.ToString(), this.Albums);
                    _pageSwitchingService.NavigateToArtistPanorama(artist.ItemID, albumId, albumsListTicket.ToString());
                };
                Albums.Add(albumViewModel);
            }
        }
Exemple #13
0
 // Eventaggregator needs to be moved to .ctor
 public SearchResultItemViewModel Create(SynoItem result, IEventAggregator eventAggregator, IPageSwitchingService pageSwitchingService)
 {
     return(new SearchResultItemViewModel(result, eventAggregator, pageSwitchingService, _urlParameterToObjectsPlateHeater));
 }
Exemple #14
0
 public AlbumViewModel Create(SynoItem album)
 {
     return(new AlbumViewModel(album));
 }
Exemple #15
0
 public void GetTracksForAlbum(SynoItem album, Action <IEnumerable <SynoTrack>, long, SynoItem> callback)
 {
     _audioStationSession.GetTracksForAlbum(album, callback, OnOperationReturnedWithError);
 }
Exemple #16
0
 public void GetAlbumsForArtist(SynoItem artist, Action <IEnumerable <SynoItem>, long, SynoItem> callback)
 {
     // an artist id looks like that (item_id): musiclib_music_aa/852502
     _audioStationSession.GetAlbumsForArtist(artist, callback, OnOperationReturnedWithError);
 }
Exemple #17
0
        public void GetAlbumsForArtist(SynoItem artist, Action <IEnumerable <SynoItem>, long, SynoItem> callback)
        {
            var results = new List <SynoItem>();

            // All music
            results.Add(new SynoItem
            {
                AlbumArtUrl = "11-18-04.jpg",
                Icon        = "icon_container.png",
                IsContainer = true,
                IsTrack     = false,
                ItemID      = "musiclib_music_artist",
                ItemPid     = "musiclib_music_aa/852502",
                Sequence    = 0,
                Support     = false,
                Title       = "All Music"
            });

            results.Add(new SynoItem
            {
                AlbumArtUrl = "11-18-04.jpg",
                Icon        = "icon_container.png",
                IsContainer = true,
                IsTrack     = false,
                ItemID      = "musiclib_music_aa/852502/852502",
                ItemPid     = "musiclib_music_aa/852502",
                Sequence    = 1,
                Support     = false,
                Title       = "Bleach"
            });

            results.Add(new SynoItem
            {
                AlbumArtUrl = "11-18-04.jpg",
                Icon        = "icon_container.png",
                IsContainer = true,
                IsTrack     = false,
                ItemID      = "musiclib_music_aa/852502/852553",
                ItemPid     = "musiclib_music_aa/852502",
                Sequence    = 2,
                Support     = false,
                Title       = "From the Muddy Banks of the Wi"
            });

            results.Add(new SynoItem
            {
                AlbumArtUrl = "11-18-04.jpg",
                Icon        = "icon_container.png",
                IsContainer = true,
                IsTrack     = false,
                ItemID      = "musiclib_music_aa/852502/852529",
                ItemPid     = "musiclib_music_aa/852502",
                Sequence    = 3,
                Support     = false,
                Title       = "In Utero"
            });

            results.Add(new SynoItem
            {
                AlbumArtUrl = "11-18-04.jpg",
                Icon        = "icon_container.png",
                IsContainer = true,
                IsTrack     = false,
                ItemID      = "musiclib_music_aa/852502/852515",
                ItemPid     = "musiclib_music_aa/852502",
                Sequence    = 4,
                Support     = false,
                Title       = "MTV Unplugged In New York"
            });

            results.Add(new SynoItem
            {
                AlbumArtUrl = "11-18-04.jpg",
                Icon        = "icon_container.png",
                IsContainer = true,
                IsTrack     = false,
                ItemID      = "musiclib_music_aa/852502/885030",
                ItemPid     = "musiclib_music_aa/852502",
                Sequence    = 5,
                Support     = false,
                Title       = "Nevermind"
            });

            callback(results, 6, artist);
        }