/// <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> /// Clear the contents of the specified library /// </summary> /// <param name="libraryToClear"></param> /// <returns></returns> public static void ClearLibrary(Library libraryToClear) { int libId = libraryToClear.Id; // Delete all the artists in the library and their associated ArtistAlbum entries List <Artist> artists = Artists.ArtistCollection.Where(art => art.LibraryId == libId).ToList(); Artists.DeleteArtists(artists); ArtistAlbums.DeleteArtistAlbums( ArtistAlbums.ArtistAlbumCollection.Where(artAlb => artists.Any(art => art.Id == artAlb.ArtistId)).Distinct().ToList()); // Delete all the albums in the library and any tags associated with them List <Album> albums = Albums.AlbumCollection.Where(alb => alb.LibraryId == libId).ToList(); Albums.DeleteAlbums(albums); // We can use the FilterManagementController to carry out the Tag deletions. new AlbumsDeletedMessage() { DeletedAlbumIds = albums.Select(alb => alb.Id).ToList() }.Send(); // Delete all the user playlists and thier contents Playlists.GetPlaylistsForLibrary(libId).ForEach(play => Playlists.DeletePlaylist(play)); // Delete the contents of the NowPlayingList but keep the playlist itself Playlist nowPlaying = Playlists.GetNowPlayingPlaylist(libId); nowPlaying.Clear(); nowPlaying.SongIndex = -1; // Delete all the songs in each of the sources associated with the library List <Source> sources = Sources.GetSourcesForLibrary(libId); foreach (Source source in sources) { Songs.DeleteSongs(Songs.GetSourceSongs(source.Id)); source.Songs = null; } }
/// <summary> /// Create the dialogue /// </summary> /// <param name="savedInstanceState"></param> /// <returns></returns> public override Dialog OnCreateDialog(Bundle savedInstanceState) { // Create the view here so that we can access the listview View layout = LayoutInflater.FromContext(Context).Inflate(Resource.Layout.source_display_dialogue_layout, null); // Create an adapter for the list view to display the main source details // Keep a reference to the adapter so that we can refresh the data if a source is changed ListView sourceView = layout.FindViewById <ListView>(Resource.Id.sourceList); sourceAdapter = new SourceDisplayAdapter(Context, Sources.GetSourcesForLibrary(libraryToDisplay.Id), sourceView, this); sourceView.Adapter = sourceAdapter; // Add a header to the ListView sourceView.AddHeaderView(LayoutInflater.FromContext(Context).Inflate(Resource.Layout.source_header_layout, null)); // Create the rest of the dialog return(new AlertDialog.Builder(Activity) .SetTitle(string.Format("Library {0}", libraryToDisplay.Name)) .SetView(layout) .SetPositiveButton("Done", delegate { }).Create()); }