Example #1
0
        public List <SongList> GetAlbumsFromArtist(SongList artist)
        {
            List <SongList> albums = new List <SongList>();

            foreach (Song song in artist.Songs)
            {
                string albumStr = song.Album;
                bool   found    = false;
                foreach (SongList list in albums)
                {
                    if (list.Data["name"].Equals(albumStr) && list.Data["artist"].Equals(song.AlbumArtist))
                    {
                        list.Songs.Add(song);
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    continue;
                }
                else
                {
                    SongList album = new SongList(SongListType.ALBUM);
                    album.Songs.Add(song);
                    album.Data["name"]   = albumStr;
                    album.Data["artist"] = song.AlbumArtist;
                    albums.Add(album);
                }
            }
            return(albums);
        }
        private void ArtistItemTemplate_ItemClick(object sender, MouseButtonEventArgs e)
        {
            SongList selected = (sender as StackPanel).DataContext as SongList;

            ArtistView.Children.Clear();
            SongList artist = selected as SongList;
            foreach (SongList album in Tab.GetAlbumsFromArtist(artist))
            {
                TextBlock title = new TextBlock()
                {
                    Text = album.Data["name"]
                };
                ListBox songs = new ListBox()
                {
                    ItemsSource = album.Songs,
                    ItemTemplate = Root.FindResource("SongTemplate") as DataTemplate
                };
                /*VirtualizingPanel.SetIsVirtualizing(songs, true);
                VirtualizingPanel.SetVirtualizationMode(songs, VirtualizationMode.Recycling);*/
                ArtistView.Children.Add(title);
                ArtistView.Children.Add(songs);
            }
        }
Example #3
0
        public List <SongList> GetSongList(SongListType type)
        {
            switch (type)
            {
            case SongListType.ARTIST:
                List <SongList> artists = new List <SongList>();
                foreach (Song song in Songs)
                {
                    string artistStr = song.Artist;
                    bool   found     = false;
                    foreach (SongList list in artists)
                    {
                        if (list.Data["name"].Equals(artistStr))
                        {
                            list.Songs.Add(song);
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                    else
                    {
                        SongList artist = new SongList(SongListType.ARTIST);
                        artist.Songs.Add(song);
                        artist.Data["name"] = artistStr;
                        artists.Add(artist);
                    }
                }
                return(artists.OrderBy(o => o.Data["name"]).ToList());

            case SongListType.ALBUM:
                List <SongList> albums = new List <SongList>();
                foreach (Song song in Songs)
                {
                    string albumStr = song.Album;
                    bool   found    = false;
                    foreach (SongList list in albums)
                    {
                        if (list.Data["name"].Equals(albumStr) && list.Data["artist"].Equals(song.AlbumArtist))
                        {
                            list.Songs.Add(song);
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                    else
                    {
                        SongList album = new SongList(SongListType.ALBUM);
                        album.Songs.Add(song);
                        album.Data["name"]   = albumStr;
                        album.Data["artist"] = song.AlbumArtist;
                        albums.Add(album);
                    }
                }
                return(albums);

            default:
                return(null);
            }
        }