/// <summary> /// Add a list of Songs to a specified playlist /// </summary> /// <param name="songsToAdd"></param> /// <param name="playlist"></param> public static void AddSongsToPlaylist(IEnumerable <Song> songsToAdd, SongPlaylist playlist) { playlist.AddSongs(songsToAdd); // Report the change DataReporter?.PlaylistUpdated(playlist); }
/// <summary> /// Duplicate the SongPlaylist in the specified library /// </summary> /// <param name="playlistToDuplicate"></param> /// <returns></returns> private static async void DuplicateSongPlaylistAsync(SongPlaylist playlistToDuplicate, int libraryId) { // Attempt to find matching songs for each SongPlaylistItem in the SongPlaylist // Need to access the songs via the Sources associated with the Library List <Source> sources = Sources.GetSourcesForLibrary(libraryId); // Keep track of the matching songs List <Song> songsToAdd = new(); foreach (SongPlaylistItem item in playlistToDuplicate.PlaylistItems) { Song matchingSong = null; int sourceIndex = 0; while ((matchingSong == null) && (sourceIndex < sources.Count)) { // Get a list of all the songs with matching Titles in the source List <Song> matchingTitles = Songs.GetSourceSongsWithName(sources[sourceIndex++].Id, item.Song.Title); // Now for each song access the associated artist int titleIndex = 0; while ((matchingSong == null) && (titleIndex < matchingTitles.Count)) { Artist nameCheck = Artists.GetArtistById(ArtistAlbums.GetArtistAlbumById(matchingTitles[titleIndex].ArtistAlbumId).ArtistId); // Correct name? if (nameCheck.Name == item.Artist.Name) { matchingSong = matchingTitles[titleIndex]; songsToAdd.Add(matchingSong); // Make sure that the Artist is stored with the song matchingSong.Artist = nameCheck; } titleIndex++; } } } // Only create the playlist if at least one of the songs was found if (songsToAdd.Count > 0) { SongPlaylist duplicatedPlaylist = new() { Name = playlistToDuplicate.Name, LibraryId = libraryId }; // Wait for the playlist to be added as we're going to use its id await Playlists.AddPlaylistAsync(duplicatedPlaylist); // Add the songs to the new SongPlaylist. duplicatedPlaylist.AddSongs(songsToAdd); } }
/// <summary> /// Called when a playlist name has been entered has been selected. /// </summary> /// <param name="selectedLibrary"></param> private async void NameEntered(string playlistName, NewPlaylistNameDialogFragment playlistNameFragment, bool isAlbum) { string alertText = ""; // An empty playlist name is not allowed if (playlistName.Length == 0) { alertText = EmptyNameError; } else { // Check for a duplicate if (PlaylistsViewModel.PlaylistNames.Contains(playlistName) == true) { alertText = DuplicatePlaylistError; } else { // Create a SongPlaylist or AlbumPlaylist as appropriate and add the Songs/Albums to it if (isAlbum == false) { // Create the playlist and add the songs to it // Need to wait for the playlist to be stored as we are going to access it's Id straight away SongPlaylist newPlaylist = await PlaylistsController.AddSongPlaylistAsync(playlistName); PlaylistsController.AddSongsToPlaylist(selectedObjects.Songs, newPlaylist); } else { AlbumPlaylist newPlaylist = await PlaylistsController.AddAlbumPlaylistAsync(playlistName); PlaylistsController.AddAlbumsToPlaylist(selectedObjects.Albums, newPlaylist); } } } // Display an error message if the playlist name is not valid. if (alertText.Length > 0) { NotificationDialogFragment.ShowFragment(CommandRouter.Manager, alertText); } else { // Dismiss the playlist name dialogue and finally perform the command callback (exit action mode) playlistNameFragment.Dismiss(); commandCallback.PerformAction(); } }