Example #1
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();
            }
        }
Example #2
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();
        }
Example #3
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();
        }