Пример #1
0
        private SongViewModel LookupSong(SongModel song)
        {
            if (song == null)
            {
                return(null);
            }

            if (SongLookupMap.ContainsKey(song.SongId))
            {
                return(SongLookupMap[song.SongId]);
            }
            else
            {
                ArtistViewModel artist = LookupArtistById(song.ArtistId);

                AlbumViewModel album = LookupAlbumById(song.AlbumId);

                SongViewModel newSongViewModel = new SongViewModel(song, artist, album);

                SongLookupMap.Add(newSongViewModel.SongId, newSongViewModel);
                SongCollection.Add(newSongViewModel, newSongViewModel.SortName);
                FlatSongCollection.Add(newSongViewModel);

                if (LibraryLoaded)
                {
                    NotifyPropertyChanged(Properties.IsEmpty);
                }

                return(newSongViewModel);
            }
        }
Пример #2
0
        public AlbumViewModel(AlbumModel album, ArtistViewModel artistViewModel)
            : base(album)
        {
            _artist = artistViewModel;
            _artist.Albums.Add(this);

            Artist.PropertyChanged  += HandleArtistPropertyChanged;
            Songs.CollectionChanged += HandleSongCollectionChanged;
            album.PropertyChanged   += HandleAlbumModelPropertyChanged;
        }
Пример #3
0
        public SongViewModel(SongModel song, ArtistViewModel artistViewModel, AlbumViewModel albumViewModel) : base(song)
        {
            Artist = artistViewModel;
            Artist.Songs.Add(this);

            Album = albumViewModel;
            Album.Songs.Add(this);

            rootModel.PropertyChanged += HandleSongModelPropertyChanged;
        }
Пример #4
0
        internal SongViewModel LookupSongByName(string TrackName, string ArtistName)
        {
            ArtistViewModel artist = LookupArtistByName(ArtistName, false);

            if (artist == null)
            {
                return(null);
            }

            return(LookupSong(LibraryModel.Current.SearchSongByName(TrackName, artist.ArtistId)));
        }
Пример #5
0
        internal void RemoveArtistIfNeeded(ArtistViewModel artistViewModel)
        {
            if (artistViewModel.Songs.Count == 0 && artistViewModel.Albums.Count == 0)
            {
                ArtistCollection.Remove(artistViewModel, artistViewModel.SortName);
                ArtistLookupMap.Remove(artistViewModel.ArtistId);

                artistViewModel.IsBeingDeleted = true;

                LibraryModel.Current.DeleteArtist(artistViewModel.ArtistId);
            }
        }
Пример #6
0
        internal bool AddSong(StorageProviderSong song, bool resetSongData)
        {
            SongModel songFromSource = LibraryModel.Current.GetSongFromSource(StorageProviderSourceToSongOriginSource(song.Origin), song.Source);

            if (songFromSource != null)
            {
                if (resetSongData)
                {
                    SongViewModel songViewModel = LookupSong(songFromSource);

                    songViewModel.Name = song.Name;

                    songViewModel.ArtistName = song.Artist;

                    string newAlbumName      = song.Album;
                    string newAlbumAristName = song.AlbumArtist;

                    if (newAlbumName != songViewModel.Album.Name || newAlbumAristName != songViewModel.Album.ArtistName)
                    {
                        ArtistViewModel albumArtistViewModel = LibraryViewModel.Current.LookupArtistByName(newAlbumAristName);
                        AlbumViewModel  newAlbumViewModel    = LibraryViewModel.Current.LookupAlbumByName(newAlbumName, albumArtistViewModel.ArtistId);

                        songViewModel.UpdateAlbum(newAlbumViewModel);
                    }

                    songViewModel.TrackNumber = song.TrackNumber;
                }
                return(false);
            }

            SongModel newSongModel = LibraryModel.Current.AddNewSong(
                song.Artist,
                song.Album,
                song.AlbumArtist,
                song.Name,
                song.Source,
                StorageProviderSourceToSongOriginSource(song.Origin),
                song.Duration.Ticks,
                song.Rating,
                song.TrackNumber
                );

            if (LookupSong(newSongModel) == null)
            {
                DebugHelper.Alert(new CallerInfo(), "Failed to add song");
                return(false);
            }

            return(true);
        }
Пример #7
0
        internal void DeleteSong(SongViewModel song)
        {
            foreach (PlaylistViewModel playlist in PlaylistCollection)
            {
                playlist.RemoveAllInstancesOfSong(song);
            }

            PlayQueue.RemoveAllInstancesOfSong(song);

            AlbumViewModel  album  = song.Album;
            ArtistViewModel artist = song.Artist;

            LibraryModel.Current.DeleteSong(song.SongId);

            RemoveAlbumIfNeeded(album);
            RemoveArtistIfNeeded(artist);
        }
Пример #8
0
        private AlbumViewModel LookupAlbum(AlbumModel album)
        {
            if (AlbumLookupMap.ContainsKey(album.AlbumId))
            {
                return(AlbumLookupMap[album.AlbumId]);
            }
            else
            {
                ArtistViewModel artist = LookupArtistById(album.ArtistId);

                AlbumViewModel newAlbumViewModel = new AlbumViewModel(album, artist);

                AlbumLookupMap.Add(newAlbumViewModel.AlbumId, newAlbumViewModel);
                AlbumCollection.Add(newAlbumViewModel, newAlbumViewModel.SortName);
                return(newAlbumViewModel);
            }
        }
Пример #9
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            ArtistViewModel otherArtist = obj as ArtistViewModel;

            if (otherArtist != null)
            {
                return(this.SortName.CompareTo(otherArtist.SortName));
            }
            else
            {
                throw new ArgumentException("Object is not a artistViewModel");
            }
        }
Пример #10
0
        private async void SearchArtists(string query)
        {
            Artists.Clear();

            List <int> foundArtists = await SearchManagerModel.SearchArtists(query);

            foreach (int artistId in foundArtists)
            {
                ArtistViewModel foundArtist = LibraryViewModel.Current.LookupArtistById(artistId);
                if (foundArtist != null)
                {
                    Artists.Add(foundArtist);
                }
            }

            artistSearchInProgress = false;
            NotifyPropertyChanged(Properties.SearchInProgress);
            NotifyPropertyChanged(Properties.ContentInfoArtists);
        }
Пример #11
0
        private ArtistViewModel LookupArtist(ArtistModel artist)
        {
            if (artist == null)
            {
                return(null);
            }

            if (ArtistLookupMap.ContainsKey(artist.ArtistId))
            {
                return(ArtistLookupMap[artist.ArtistId]);
            }
            else
            {
                ArtistViewModel newArtistViewModel = new ArtistViewModel(artist);

                ArtistLookupMap.Add(newArtistViewModel.ArtistId, newArtistViewModel);
                ArtistCollection.Add(newArtistViewModel, newArtistViewModel.SortName);

                return(newArtistViewModel);
            }
        }