Example #1
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);
        }
Example #2
0
        public void UpdateAlbum(AlbumViewModel newAlbum)
        {
            // Set the root AlbumId so we can remove the old Album
            rootModel.AlbumId = newAlbum.AlbumId;

            Album.Songs.Remove(this);
            LibraryViewModel.Current.RemoveAlbumIfNeeded(Album);

            // Then set the new album and fill it out
            Album = newAlbum;

            Album.Songs.Add(this);

            NotifyPropertyChanged(Properties.Album);
        }
Example #3
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);
        }
Example #4
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);
            }
        }
Example #5
0
        internal void RemoveAlbumIfNeeded(AlbumViewModel albumViewModel)
        {
            if (albumViewModel.Songs.Count == 0)
            {
                if (albumViewModel.Artist.Albums.Contains(albumViewModel))
                {
                    albumViewModel.Artist.Albums.Remove(albumViewModel);
                    RemoveArtistIfNeeded(albumViewModel.Artist);

                    AlbumCollection.Remove(albumViewModel, albumViewModel.SortName);
                    AlbumLookupMap.Remove(albumViewModel.AlbumId);

                    albumViewModel.IsBeingDeleted = true;

                    LibraryModel.Current.DeleteAlbum(albumViewModel.AlbumId);
                }
            }
        }
        private async void SearchAlbums(string query)
        {
            Albums.Clear();

            List <int> foundAlbums = await SearchManagerModel.SearchAlbums(query);

            foreach (int albumId in foundAlbums)
            {
                AlbumViewModel foundAlbum = LibraryViewModel.Current.LookupAlbumById(albumId);
                if (foundAlbum != null)
                {
                    Albums.Add(foundAlbum);
                }
            }

            albumSearchInProgress = false;
            NotifyPropertyChanged(Properties.SearchInProgress);
            NotifyPropertyChanged(Properties.ContentInfoAlbums);
        }
Example #7
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            AlbumViewModel otherAlbum = obj as AlbumViewModel;

            if (otherAlbum != null)
            {
                if (otherAlbum.SortName == this.SortName)
                {
                    return(this.Artist.SortName.CompareTo(otherAlbum.Artist.SortName));
                }
                return(this.SortName.CompareTo(otherAlbum.SortName));
            }
            else
            {
                throw new ArgumentException("Object is not a albumViewModel");
            }
        }
Example #8
0
 internal void AlertAlbumNameChanged(AlbumViewModel albumViewModel, string oldName)
 {
     AlbumCollection.Remove(albumViewModel, oldName);
     AlbumCollection.Add(albumViewModel, albumViewModel.SortName);
 }