/// <summary> /// Add a list of Albums to a specified playlist /// </summary> /// <param name="albumsToAdd"></param> /// <param name="playlist"></param> public static void AddAlbumsToPlaylist(IEnumerable <Album> albumsToAdd, AlbumPlaylist playlist) { playlist.AddAlbums(albumsToAdd); // Report the change DataReporter?.PlaylistUpdated(playlist); }
/// <summary> /// Provide a view containing either album or song details at the specified position /// Attempt to reuse the supplied view if it previously contained the same type of detail. /// </summary> /// <param name="groupPosition"></param> /// <param name="childPosition"></param> /// <param name="isLastChild"></param> /// <param name="convertView"></param> /// <param name="parent"></param> /// <returns></returns> protected override View GetSpecialisedChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent) { if (Groups[groupPosition] is SongPlaylist playlist) { // If no view supplied then create a new one if (convertView == null) { convertView = inflator.Inflate(Resource.Layout.playlists_song_layout, null); convertView.Tag = new SongViewHolder() { SelectionBox = GetSelectionBox(convertView), Artist = convertView.FindViewById <TextView>(Resource.Id.artist), Title = convertView.FindViewById <TextView>(Resource.Id.title), Duration = convertView.FindViewById <TextView>(Resource.Id.duration) }; } // Display the SongPlaylistItem (( SongViewHolder )convertView.Tag).DisplaySong(( SongPlaylistItem )playlist.PlaylistItems[childPosition]); // If this song is currently being played then show with a different background convertView.SetBackgroundColor((playlist.SongIndex == childPosition) ? Color.AliceBlue : Color.Transparent); } else { // If the supplied view is null then create one if (convertView == null) { convertView = inflator.Inflate(Resource.Layout.playlists_album_layout, null); convertView.Tag = new AlbumViewHolder() { SelectionBox = GetSelectionBox(convertView), AlbumName = convertView.FindViewById <TextView>(Resource.Id.albumName), ArtistName = convertView.FindViewById <TextView>(Resource.Id.artist), Year = convertView.FindViewById <TextView>(Resource.Id.year), Genre = convertView.FindViewById <TextView>(Resource.Id.genre), }; } // Display the album AlbumPlaylist albumPlaylist = ( AlbumPlaylist )Groups[groupPosition]; Album album = ((AlbumPlaylistItem)albumPlaylist.PlaylistItems[childPosition]).Album; (( AlbumViewHolder )convertView.Tag).DisplayAlbum(album, ActionMode, album.Genre); // If this album is currently being played then show it with a different background convertView.SetBackgroundColor(albumPlaylist.InProgressAlbum == album ? Color.AliceBlue : Color.Transparent); } return(convertView); }
/// <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(); } }
/// <summary> /// Called when an AlbumPlaylistItem has been clicked /// </summary> /// <param name="albumPlaylist"></param> /// <param name="albumPlaylistItem"></param> public void AlbumPlaylistItemClicked(AlbumPlaylist albumPlaylist, AlbumPlaylistItem albumPlaylistItem) { AlertDialog dialogue = null; // Create the listview and its adapter View customView = LayoutInflater.FromContext(Context).Inflate(Resource.Layout.album_songs_popup, null); ListView songView = customView.FindViewById <ListView>(Resource.Id.songsList); songView.Adapter = new SongsDisplayAdapter(Context, songView, albumPlaylistItem.Album.Songs, albumPlaylist.InProgressSong?.Id ?? -1, clickAction: () => dialogue.Dismiss()); // Create and show the dialogue dialogue = new AlertDialog.Builder(Context) .SetView(customView) .Create(); dialogue.Show(); }
/// <summary> /// Duplicate the AlbumPlaylist in the specified library /// </summary> /// <param name="playlistToDuplicate"></param> /// <param name="libararyId"></param> private static async void DuplicateAlbumPlaylistAsync(AlbumPlaylist playlistToDuplicate, int libraryId) { List <Album> albumsToAdd = new(); foreach (AlbumPlaylistItem item in playlistToDuplicate.PlaylistItems) { // Find a matching Album name with the same Artist name Album matchingAlbum = Albums.AlbumCollection.Where(album => (album.LibraryId == libraryId) && (album.Name == item.Album.Name) && (album.ArtistName == item.Album.ArtistName)).FirstOrDefault(); if (matchingAlbum != null) { albumsToAdd.Add(matchingAlbum); } } // Only create the playlist if we've got something to add to it if (albumsToAdd.Count > 0) { AlbumPlaylist duplicatedPlaylist = new() { Name = playlistToDuplicate.Name, LibraryId = libraryId }; await Playlists.AddPlaylistAsync(duplicatedPlaylist); duplicatedPlaylist.AddAlbums(albumsToAdd); } }