예제 #1
0
        private void MatchTracksWithParents(ObservableCollection <ITrackViewModel> tracks)
        {
            // Searches and matches tracks with respective albums and tracks to populate HistoryTracks
            // Also populates SortedMusicViewModels with retrieved tracks,albums,artists

            var tracksSorted = tracks.GroupBy(t => t.AlbumID).GroupBy(t => t.First().ArtistID);

            var keyValueList = new List <KeyValuePair <ITrackViewModel, TrackViewModelParents> >();

            foreach (var artistGroup in tracksSorted)
            {
                var artistMusicObject         = _musicLog.GetMusicObject(artistGroup.First().First().ArtistID);
                IArtistViewModel activeArtist = MusicObjectProvider.MakeArtistViewModel((IArtist)artistMusicObject);
                _sortedMusicViewModels.Add(activeArtist);

                foreach (var albumGroup in artistGroup)
                {
                    var             albumMusicObject = _musicLog.GetMusicObject(albumGroup.First().AlbumID);
                    IAlbumViewModel activeAlbum      = MusicObjectProvider.MakeAlbumViewModel((IAlbum)albumMusicObject);
                    _sortedMusicViewModels.Add(activeAlbum);

                    foreach (var track in albumGroup)
                    {
                        _sortedMusicViewModels.Add(track);
                        track.Visible = true;
                        var key   = track;
                        var value = new TrackViewModelParents(activeArtist, activeAlbum);
                        keyValueList.Add(new KeyValuePair <ITrackViewModel, TrackViewModelParents>(key, value));
                    }
                }
            }

            HistoryTracks = keyValueList.OrderByDescending(l => l.Key.LastListenedUnix).ToObservableCollection();
        }
예제 #2
0
        private void GetSelectedPlaylistAlbums()
        {
            if (SelectedPlaylist == null || SelectedPlaylist.Albums.Count == 0)
            {
                ActiveAlbums = null;
                return;
            }


            var albumQuery = _musicLog.GetMusicObjects(SelectedPlaylist.Albums)
                             .ConvertAll(o => (IAlbum)o);

            ActiveAlbums = new ObservableCollection <IAlbumViewModel>();
            foreach (var album in albumQuery)
            {
                var newAlbumViewModel = MusicObjectProvider.MakeAlbumViewModel(album);
                newAlbumViewModel.ArtistName = _musicLog.GetMusicObject(newAlbumViewModel.ArtistID).Name;
                ActiveAlbums.Add(newAlbumViewModel);
            }
        }