Esempio n. 1
0
        private void OnRecommend(object sender, RoutedEventArgs e)
        {
            Playlist selectedPlaylist = (Playlist)this.NavigationControl.ViewModel.SelectedPlaylist;

            if (selectedPlaylist == null)
            {
                return;
            }

            RecommendationEngine engine = new RecommendationEngine();
            Artist recommendedArtist    = engine.Recommend(SpotifyClientService.Client, selectedPlaylist);

            RecommendationWindow recommendationWindow = new RecommendationWindow(recommendedArtist);
            bool?result = recommendationWindow.ShowDialog();

            if (result != null && result.Value == true)
            {
                ArtistNetworkNodeViewModel targetNodeViewModel = this.AtlasView.ViewModel.FindNode <ArtistNetworkNodeViewModel>(recommendedArtist.ID);

                if (targetNodeViewModel == null)
                {
                    List <Artist> recommendedArtistList = new List <Artist>()
                    {
                        recommendedArtist
                    };
                    AtlasViewOptions options = new AtlasViewOptions(1);
                    this.AtlasView.ViewModel.AddArtistsToHierarchy(recommendedArtistList.AsReadOnly(), options);
                    this.AtlasView.UpdateNetwork();

                    targetNodeViewModel = this.AtlasView.ViewModel.FindNode <ArtistNetworkNodeViewModel>(recommendedArtist.ID);
                }

                targetNodeViewModel.AddTracks();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Event raised when the playist selection has changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPlaylistSelectionChanged(object sender, RoutedEventArgs e)
        {
            if (this.StartUpHelper.Visibility == Visibility.Visible)
            {
                this.StartUpHelper.Visibility                = Visibility.Hidden;
                this.AtlasView.ViewModel.IsVisible           = true;
                this.PlaylistView.ViewModel.ShowTutorialInfo = false;
            }

            NavigationControl   navigationControl   = (NavigationControl)sender;
            NavigationViewModel navigationViewModel = (NavigationViewModel)navigationControl.DataContext;

            if (navigationViewModel.SelectedPlaylist != null)
            {
                _atlasViewMode = AtlasViewMode.PlaylistView;
                IEnumerable <Artist> distinctArtists = navigationViewModel.SelectedPlaylist.Tracks.SelectMany(track => track.Track.Artists).Distinct().Select(artist => artist);

                //Notify the playlist view model that the playlist has been updated.
                this.PlaylistView.ViewModel.UpdatePlaylist(navigationViewModel.SelectedPlaylist);

                AtlasViewOptions options = new AtlasViewOptions(1);
                this.AtlasView.ViewModel.CreatePlaylistHierarchy(distinctArtists.ToList().AsReadOnly(), options);
                this.AtlasView.UpdateNetwork();
            }
            else
            {
                IReadOnlyCollection <Artist> emptyList = new List <Artist>();
                AtlasViewOptions             options   = new AtlasViewOptions(1);
                this.AtlasView.ViewModel.CreatePlaylistHierarchy(emptyList, options);
                this.AtlasView.UpdateNetwork();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Event handler when the search popup is closed.  Adds the artist to the atlas
        /// if there a valid selection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSearchControlPopupClosed(object sender, EventArgs e)
        {
            Artist selectedArtist = this.SearchControlPopup.SelectedItem;

            if (selectedArtist == null)
            {
                return;
            }

            List <Artist> artistList = new List <Artist>()
            {
                selectedArtist
            };
            AtlasViewOptions options = new AtlasViewOptions(1);

            this.AtlasView.ViewModel.AddArtistsToHierarchy(artistList.AsReadOnly(), options);
            this.AtlasView.UpdateNetwork();
        }
Esempio n. 4
0
        /// <summary>
        /// Populates the Atlas with all followed artists.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFollowedArtists(object sender, RoutedEventArgs e)
        {
            //Clear the Atlas, clear the playlist selection too.
            //Show all artists you're following.
            _atlasViewMode = AtlasViewMode.FollowedArtistView;

            //Clear the playlist selection.
            NavigationControl navigationControl = (NavigationControl)sender;

            navigationControl.SelectPlaylist(null);
            OnPlaylistSelectionChanged(navigationControl, e);

            //Add all followed artists to the hierarchy.
            FollowedArtistList followedArtists = SpotifyCacheService.GetFollowedArtists();
            AtlasViewOptions   viewOptions     = new AtlasViewOptions(0);

            this.AtlasView.ViewModel.CreateFollowedArtistHierarchy(followedArtists.ArtistItems.Items.AsReadOnly(), viewOptions);
            this.AtlasView.UpdateNetwork();
        }
Esempio n. 5
0
        /// <summary>
        /// Event handler when the search popup is closed.  Adds the artist to the atlas
        /// if there a valid selection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSearchControlPopupClosed(object sender, EventArgs e)
        {
            Artist selectedArtist = this.SearchControlPopup.SelectedItem;

            if (selectedArtist == null)
                return;

            List<Artist> artistList = new List<Artist>() { selectedArtist };
            AtlasViewOptions options = new AtlasViewOptions(1);
            this.AtlasView.ViewModel.AddArtistsToHierarchy(artistList.AsReadOnly(), options);
            this.AtlasView.UpdateNetwork();
        }
Esempio n. 6
0
        private void OnNewReleases(object sender, RoutedEventArgs e)
        {
            _atlasViewMode = AtlasViewMode.NewReleasesView;

            //Clear the playlist selection.
            NavigationControl navigationControl = (NavigationControl)sender;
            navigationControl.SelectPlaylist(null);
            OnPlaylistSelectionChanged(navigationControl, e);

            List<NewReleaseItem> newsItems = new List<NewReleaseItem>();

            //Add artists that have new releases.
            //System.Threading.Tasks.Task.Run(() =>
            {
                AlbumType filter = AlbumType.Album | AlbumType.Single;
                DateTime cutoff = DateTime.Now.AddMonths(-3); //TODO: Data-drive this setting.
                int maxSuggestions = 1;  //TODO: Data-drive this setting.

                FollowedArtistList followedArtists = SpotifyCacheService.GetFollowedArtists();
    
                foreach (Artist followedArtist in followedArtists.ArtistItems.Items)
                {
                    //Find if there's any new content available from this artist.
                    AlbumInfoList albums = SpotifyClientService.Client.GetArtistAlbums(followedArtist, filter);

                    foreach (AlbumInfo album in albums.Items)
                    {
                        //if (_userCache.SeenNewsItem(album.ID)) continue;

                        Album albumInfo = SpotifyClientService.Client.GetAlbum(album);

                        if (albumInfo.ReleaseDate > cutoff)
                        {
                            newsItems.Add(new NewReleaseItem(followedArtist, albumInfo));
                            if (newsItems.Count >= maxSuggestions)
                                break;
                        }
                        else
                        {
                            //Assume that albums are returned by Spotify by release date, descending.
                            //If we miss the cutoff, skip out.
                            break;
                        }
                    }
                }

                if (newsItems.Any())
                {                    
                    Dispatcher.Invoke(() =>
                    {
                        //Display a popup.
                        //this.NewsFeedPopup.DataContext = new NewsFeedViewModel(newsItems, userCache);
                        //this.NewsFeedPopup.Width = this.RenderSize.Width * 0.8;
                        //this.NewsFeedPopup.Height = this.RenderSize.Height * 0.8;
                        //this.NewsFeedPopup.IsOpen = true;
                    });
                }
            }
            //);
            
            AtlasViewOptions viewOptions = new AtlasViewOptions(0);
            this.AtlasView.ViewModel.CreateNewReleaseHierarchy(newsItems.ToList().AsReadOnly(), viewOptions);
            this.AtlasView.UpdateNetwork();
        }
Esempio n. 7
0
        /// <summary>
        /// Populates the Atlas with all followed artists.  
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFollowedArtists(object sender, RoutedEventArgs e)
        {
            //Clear the Atlas, clear the playlist selection too.
            //Show all artists you're following.
            _atlasViewMode = AtlasViewMode.FollowedArtistView;

            //Clear the playlist selection.
            NavigationControl navigationControl = (NavigationControl)sender;
            navigationControl.SelectPlaylist(null);
            OnPlaylistSelectionChanged(navigationControl, e);

            //Add all followed artists to the hierarchy.
            FollowedArtistList followedArtists = SpotifyCacheService.GetFollowedArtists();
            AtlasViewOptions viewOptions = new AtlasViewOptions(0);
            this.AtlasView.ViewModel.CreateFollowedArtistHierarchy(followedArtists.ArtistItems.Items.AsReadOnly(), viewOptions);
            this.AtlasView.UpdateNetwork();
        }
Esempio n. 8
0
        private void OnRecommend(object sender, RoutedEventArgs e)
        {
            Playlist selectedPlaylist = (Playlist)this.NavigationControl.ViewModel.SelectedPlaylist;
            if (selectedPlaylist == null)
                return;

            RecommendationEngine engine = new RecommendationEngine();
            Artist recommendedArtist = engine.Recommend(SpotifyClientService.Client, selectedPlaylist);

            RecommendationWindow recommendationWindow = new RecommendationWindow(recommendedArtist);
            bool? result = recommendationWindow.ShowDialog();

            if (result != null && result.Value == true)
            {
                ArtistNetworkNodeViewModel targetNodeViewModel = this.AtlasView.ViewModel.FindNode<ArtistNetworkNodeViewModel>(recommendedArtist.ID);

                if (targetNodeViewModel == null) {
                    List<Artist> recommendedArtistList = new List<Artist>() {recommendedArtist};
                    AtlasViewOptions options = new AtlasViewOptions(1);
                    this.AtlasView.ViewModel.AddArtistsToHierarchy(recommendedArtistList.AsReadOnly(), options);
                    this.AtlasView.UpdateNetwork();

                    targetNodeViewModel = this.AtlasView.ViewModel.FindNode<ArtistNetworkNodeViewModel>(recommendedArtist.ID);
                }

                targetNodeViewModel.AddTracks();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Event raised when the playist selection has changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPlaylistSelectionChanged(object sender, RoutedEventArgs e)
        {
            if (this.StartUpHelper.Visibility == Visibility.Visible)
            {
                this.StartUpHelper.Visibility = Visibility.Hidden;
                this.AtlasView.ViewModel.IsVisible = true;
                this.PlaylistView.ViewModel.ShowTutorialInfo = false;
            }

            NavigationControl navigationControl = (NavigationControl)sender;
            NavigationViewModel navigationViewModel = (NavigationViewModel)navigationControl.DataContext;

            if (navigationViewModel.SelectedPlaylist != null) {
                _atlasViewMode = AtlasViewMode.PlaylistView;
                IEnumerable<Artist> distinctArtists = navigationViewModel.SelectedPlaylist.Tracks.SelectMany(track => track.Track.Artists).Distinct().Select(artist => artist);

                //Notify the playlist view model that the playlist has been updated.
                this.PlaylistView.ViewModel.UpdatePlaylist(navigationViewModel.SelectedPlaylist);

                AtlasViewOptions options = new AtlasViewOptions(1);
                this.AtlasView.ViewModel.CreatePlaylistHierarchy(distinctArtists.ToList().AsReadOnly(), options);
                this.AtlasView.UpdateNetwork();
            }
            else
            {
                IReadOnlyCollection<Artist> emptyList = new List<Artist>();
                AtlasViewOptions options = new AtlasViewOptions(1);
                this.AtlasView.ViewModel.CreatePlaylistHierarchy(emptyList, options);
                this.AtlasView.UpdateNetwork();
            }
        }
Esempio n. 10
0
        private void OnNewReleases(object sender, RoutedEventArgs e)
        {
            _atlasViewMode = AtlasViewMode.NewReleasesView;

            //Clear the playlist selection.
            NavigationControl navigationControl = (NavigationControl)sender;

            navigationControl.SelectPlaylist(null);
            OnPlaylistSelectionChanged(navigationControl, e);

            List <NewReleaseItem> newsItems = new List <NewReleaseItem>();

            //Add artists that have new releases.
            //System.Threading.Tasks.Task.Run(() =>
            {
                AlbumType filter         = AlbumType.Album | AlbumType.Single;
                DateTime  cutoff         = DateTime.Now.AddMonths(-3); //TODO: Data-drive this setting.
                int       maxSuggestions = 1;                          //TODO: Data-drive this setting.

                FollowedArtistList followedArtists = SpotifyCacheService.GetFollowedArtists();

                foreach (Artist followedArtist in followedArtists.ArtistItems.Items)
                {
                    //Find if there's any new content available from this artist.
                    AlbumInfoList albums = SpotifyClientService.Client.GetArtistAlbums(followedArtist, filter);

                    foreach (AlbumInfo album in albums.Items)
                    {
                        //if (_userCache.SeenNewsItem(album.ID)) continue;

                        Album albumInfo = SpotifyClientService.Client.GetAlbum(album);

                        if (albumInfo.ReleaseDate > cutoff)
                        {
                            newsItems.Add(new NewReleaseItem(followedArtist, albumInfo));
                            if (newsItems.Count >= maxSuggestions)
                            {
                                break;
                            }
                        }
                        else
                        {
                            //Assume that albums are returned by Spotify by release date, descending.
                            //If we miss the cutoff, skip out.
                            break;
                        }
                    }
                }

                if (newsItems.Any())
                {
                    Dispatcher.Invoke(() =>
                    {
                        //Display a popup.
                        //this.NewsFeedPopup.DataContext = new NewsFeedViewModel(newsItems, userCache);
                        //this.NewsFeedPopup.Width = this.RenderSize.Width * 0.8;
                        //this.NewsFeedPopup.Height = this.RenderSize.Height * 0.8;
                        //this.NewsFeedPopup.IsOpen = true;
                    });
                }
            }
            //);

            AtlasViewOptions viewOptions = new AtlasViewOptions(0);

            this.AtlasView.ViewModel.CreateNewReleaseHierarchy(newsItems.ToList().AsReadOnly(), viewOptions);
            this.AtlasView.UpdateNetwork();
        }
 public NewReleaseAtlasHierarchy(SpotifyClient client, IEnumerable<NewReleaseItem> newReleases, AtlasViewOptions viewOptions)
     : base(client, viewOptions) {
     foreach (NewReleaseItem newReleaseItem in newReleases) {
         GenerateTree(newReleaseItem);
     }
 }
Esempio n. 12
0
 public ArtistAtlasHierarchy(SpotifyClient client, IEnumerable <Artist> artists, AtlasViewOptions viewOptions)
     : base(client, viewOptions)
 {
     foreach (Artist artist in artists)
     {
         GenerateTree(artist);
     }
 }
Esempio n. 13
0
 public void AddNewReleasesToHierarchy(IReadOnlyCollection <NewReleaseItem> newReleases, AtlasViewOptions options)
 {
     if (_hierarchy == null)
     {
         _hierarchy = new NewReleaseAtlasHierarchy(SpotifyClientService.Client, newReleases, options);
     }
     else
     {
         foreach (NewReleaseItem newReleaseItem in newReleases)
         {
             _hierarchy.AddRootNode(newReleaseItem);
         }
     }
 }
Esempio n. 14
0
 public void AddArtistsToHierarchy(IReadOnlyCollection <Artist> targetArtists, AtlasViewOptions options)
 {
     if (_hierarchy == null)
     {
         _hierarchy = new ArtistAtlasHierarchy(SpotifyClientService.Client, targetArtists, options);
     }
     else
     {
         foreach (Artist artist in targetArtists)
         {
             _hierarchy.AddRootNode(artist);
         }
     }
 }
Esempio n. 15
0
 public void CreateNewReleaseHierarchy(IReadOnlyCollection <NewReleaseItem> newReleases, AtlasViewOptions options)
 {
     _viewMode  = AtlasViewMode.NewReleasesView;
     _hierarchy = new NewReleaseAtlasHierarchy(SpotifyClientService.Client, newReleases, options);
 }
Esempio n. 16
0
 public void CreateFollowedArtistHierarchy(IReadOnlyCollection <Artist> targetArtists, AtlasViewOptions options)
 {
     _viewMode  = AtlasViewMode.FollowedArtistView;
     _hierarchy = new ArtistAtlasHierarchy(SpotifyClientService.Client, targetArtists, options);
 }