/// <summary> /// Called to handle the command. /// Determine the subject of this, either the Now Playing playlist or a user playlist /// </summary> /// <param name="_"></param> public override void HandleCommand(int _) { // If this is a Now Playing command then the parent of the first selected song will have the NowPlayingPlaylistName if ((selectedObjects.ParentPlaylist != null) && (selectedObjects.ParentPlaylist.Name == Playlists.NowPlayingPlaylistName)) { // Process this Now Playing command NowPlayingController.DeleteNowPlayingItems(selectedObjects.PlaylistItems); commandCallback.PerformAction(); } else { if (selectedObjects.PlaylistItems.Count > 0) { if (selectedObjects.Playlists.Count == 1) { // Deletion of songs and playlist - confirm first ConfirmationDialogFragment.ShowFragment(CommandRouter.Manager, PlaylistDeleteSelected, "Do you want to delete the Playlist?"); } else { // Deletion of items from a playlist PlaylistsController.DeletePlaylistItems(selectedObjects.ParentPlaylist, selectedObjects.PlaylistItems); commandCallback.PerformAction(); } } else if (selectedObjects.Playlists.Count == 1) { // Deletion of a playlist with no songs PlaylistsController.DeletePlaylist(selectedObjects.Playlists[0]); commandCallback.PerformAction(); } } }
/// <summary> /// Duplciate the next playlist in the list /// </summary> private void DuplicateNextPlaylist() { if (++playlistIndex < playlistsBeingDuplicated.Count) { Playlist nextPlaylist = playlistsBeingDuplicated[playlistIndex]; // If the playlist already exists in other libraries then prompt for deletion if (PlaylistsController.CheckForOtherPlaylists(nextPlaylist.Name, ConnectionDetailsModel.LibraryId) == true) { ConfirmationDialogFragment.ShowFragment(CommandRouter.Manager, DuplicationConfirmed, $"Playlist [{nextPlaylist.Name}] already exists in other libraries. Are you sure you want to duplicate it?"); } else { // Duplicate the playlist in the other libraries PlaylistsController.DuplicatePlaylist(nextPlaylist); DuplicateNextPlaylist(); } } else { playlistsBeingDuplicated = null; playlistIndex = -1; commandCallback.PerformAction(); } }
/// <summary> /// Called to handle the command. /// Pass the request on to the PlaylistsController having first worked out the parent playlist /// If the playlist is a NowPlaying playlist then pass the request on to the NowPlayingController /// </summary> /// <param name="commandIdentity"></param> public override void HandleCommand(int commandIdentity) { if (selectedObjects.ParentPlaylist != null) { if (selectedObjects.ParentPlaylist.Name == Playlists.NowPlayingPlaylistName) { if (commandIdentity == Resource.Id.move_up) { NowPlayingController.MoveItemsUp(selectedObjects.PlaylistItems); } else { NowPlayingController.MoveItemsDown(selectedObjects.PlaylistItems); } } else { if (commandIdentity == Resource.Id.move_up) { PlaylistsController.MoveItemsUp(selectedObjects.ParentPlaylist, selectedObjects.PlaylistItems); } else { PlaylistsController.MoveItemsDown(selectedObjects.ParentPlaylist, selectedObjects.PlaylistItems); } } } }
/// <summary> /// Called when a library has been selected. /// </summary> /// <param name="selectedLibrary"></param> private void NameEntered(string playlistName, NewPlaylistNameDialogFragment playlistNameFragment, bool _) { string alertText = ""; if (playlistName.Length == 0) { alertText = "An empty name is not valid."; } else if (playlistName == selectedObjects.Playlists[0].Name) { alertText = "Name not changed."; } else if (PlaylistsViewModel.PlaylistNames.Contains(playlistName) == true) { alertText = "A playlist with that name already exists."; } else { PlaylistsController.RenamePlaylist(selectedObjects.Playlists[0], playlistName); playlistNameFragment.Dismiss(); commandCallback.PerformAction(); } // Display an error message if the playlist name is not valid. Do not dismiss the dialog if (alertText.Length > 0) { NotificationDialogFragment.ShowFragment(CommandRouter.Manager, alertText); } }
/// <summary> /// Called /// </summary> /// <param name="confirm"></param> private void DuplicationConfirmed(bool confirm) { if (confirm == true) { PlaylistsController.DuplicatePlaylist(playlistsBeingDuplicated[playlistIndex]); } DuplicateNextPlaylist(); }
/// <summary> /// Called when the user has decided whether to delete the entire playlist or just the items in it /// </summary> /// <param name="deletePlaylist"></param> private void PlaylistDeleteSelected(bool deletePlaylist) { if (deletePlaylist == true) { PlaylistsController.DeletePlaylist(selectedObjects.Playlists[0]); } else { PlaylistsController.DeletePlaylistItems(selectedObjects.Playlists[0], selectedObjects.PlaylistItems); } commandCallback.PerformAction(); }
/// <summary> /// When a menu item is clicked pass the songs or albums to the appropriate controller /// </summary> /// <param name="_"></param> /// <param name="args"></param> private void MenuItemClicked(object _, PopupMenu.MenuItemClickEventArgs args) { // Use the menu id to determine what has been selected int menuId = args.Item.ItemId; if (menuId < PlaylistsViewModel.SongPlaylists.Count) { // Add the selected songs to the selected playlist PlaylistsController.AddSongsToPlaylist(selectedObjects.Songs, PlaylistsViewModel.SongPlaylists[menuId]); commandCallback.PerformAction(); } else if (menuId < PlaylistsViewModel.Playlists.Count) { // Add the selected albumns to the selected playlist PlaylistsController.AddAlbumsToPlaylist(selectedObjects.Albums, PlaylistsViewModel.AlbumPlaylists[menuId - PlaylistsViewModel.SongPlaylists.Count]); commandCallback.PerformAction(); } else { // Finally check for a New SongPlaylist command if (menuId == PlaylistsViewModel.Playlists.Count) { // Display a NewPlaylistNameDialogFragment to request a playlist name // If complete albums have been selected then try to choose an appropriate name for the new album playlist string suggestedPlaylistName = ""; if (completeAlbums == true) { // If just a single album then suggest the name of the album if (selectedObjects.Albums.Count == 1) { suggestedPlaylistName = $"{selectedObjects.Albums[ 0 ].ArtistName} : {selectedObjects.Albums[ 0 ].Name}"; } else { // If all the albums are from the same artist then suggest the artist name string artistName = selectedObjects.Albums[0].ArtistName; if (selectedObjects.Albums.All(album => album.ArtistName == artistName) == true) { suggestedPlaylistName = artistName; } } } NewPlaylistNameDialogFragment.ShowFragment(CommandRouter.Manager, NameEntered, "New playlist", suggestedPlaylistName, completeAlbums == true, true); } } }
/// <summary> /// Configure all the controllers /// </summary> private void ConfigureControllers() { AlbumsController.GetControllerData(); ArtistsController.GetControllerData(); PlaylistsController.GetControllerData(); LibraryNameDisplayController.GetControllerData(); FilterManagementController.GetControllerData(); PlaybackSelectionController.GetControllerData(); AutoplayController.GetControllerData(); PlaybackModeController.GetControllerData(); PlaybackManagementController.GetControllerData(); MediaControllerController.GetControllerData(); MediaNotificationController.GetControllerData(); NowPlayingController.GetControllerData(); }
/// <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(); } }