Exemple #1
0
        /// <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);
                }
            }
        }
Exemple #2
0
        /// <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();
            }
        }