Exemplo n.º 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);
                }
            }
        }
 /// <summary>
 /// Called to handle the command. Show the NewPlaylistNameDialogFragment.
 /// </summary>
 /// <param name="commandIdentity"></param>
 public override void HandleCommand(int commandIdentity) =>
 NewPlaylistNameDialogFragment.ShowFragment(CommandRouter.Manager, NameEntered, "Rename playlist", selectedObjects.Playlists[0].Name);