/// <summary> /// Called to handle a command that takes a collection of selected objects and a completion action /// </summary> /// <param name="commandIdentity"></param> /// <param name="selection"></param> /// <param name="callback"></param> public virtual void HandleCommand(int commandIdentity, GroupedSelection selection, CommandRouter.CommandHandlerCallback callback, AppCompatImageButton button) { selectedObjects = selection; commandCallback = callback; commandButton = button; HandleCommand(commandIdentity); }
/// <summary> /// Use the command handler associated with each button to determine if the button should be shown /// </summary> /// <param name="selectedObjects"></param> public void DetermineButtonsVisibility(GroupedSelection selectedObjects) { foreach (KeyValuePair <int, AppCompatImageButton> buttonPair in Buttons) { // Is there a command handler associated with this button CommandHandler handler = CommandRouter.GetHandlerForCommand(buttonPair.Key); if (handler != null) { buttonPair.Value.Visibility = (handler.IsSelectionValidForCommand(selectedObjects, buttonPair.Key) == true) ? ViewStates.Visible : ViewStates.Gone; } } }
/// <summary> /// Called when the number of selected items (songs) has changed. /// Update the text to be shown in the Action Mode title /// </summary> protected override void SelectedItemsChanged(GroupedSelection selectedObjects) { if (selectedObjects.Songs.Count == 0) { ActionMode.ActionModeTitle = NoItemsSelectedText; } else { int albumsCount = selectedObjects.Albums.Count; int songsCount = selectedObjects.Songs.Count; string albumsText = (albumsCount > 0) ? string.Format("{0} album{1} ", albumsCount, (albumsCount == 1) ? "" : "s") : ""; string songsText = (songsCount > 0) ? string.Format("{0} song{1} ", songsCount, (songsCount == 1) ? "" : "s") : ""; ActionMode.ActionModeTitle = string.Format(ItemsSelectedText, albumsText, songsText); } ActionMode.AllSelected = (selectedObjects.Albums.Count == AlbumsViewModel.Albums.Count); }
/// <summary> /// Called when the number of selected items has changed. /// Update the text to be shown in the Action Mode title /// </summary> protected override void SelectedItemsChanged(GroupedSelection selectedObjects) { if ((selectedObjects.PlaylistItems.Count == 0) && (selectedObjects.Playlists.Count == 0)) { ActionMode.ActionModeTitle = NoItemsSelectedText; } else { int playlistCount = selectedObjects.Playlists.Count; int songCount = selectedObjects.PlaylistItems.Count(item => item is SongPlaylistItem) + selectedObjects.PlaylistItems.Where(item => item is AlbumPlaylistItem).SelectMany(list => (( AlbumPlaylistItem )list).Album.Songs).Count(); string playlistText = (playlistCount > 0) ? string.Format("{0} playlist{1} ", playlistCount, (playlistCount == 1) ? "" : "s") : ""; string songsText = (songCount > 0) ? string.Format("{0} song{1} ", songCount, (songCount == 1) ? "" : "s") : ""; ActionMode.ActionModeTitle = string.Format(ItemsSelectedText, playlistText, songsText); } ActionMode.AllSelected = (selectedObjects.Playlists.Count == PlaylistsViewModel.Playlists.Count); }
/// <summary> /// Called when the number of selected items (songs) has changed. /// Update the text to be shown in the Action Mode title /// </summary> protected override void SelectedItemsChanged(GroupedSelection selectedObjects) { ActionMode.ActionModeTitle = (selectedObjects.PlaylistItems.Count == 0) ? NoItemsSelectedText : string.Format(ItemsSelectedText, selectedObjects.PlaylistItems.Count); ActionMode.AllSelected = (selectedObjects.PlaylistItems.Count == NowPlayingViewModel.NowPlayingPlaylist.PlaylistItems.Count); }
/// <summary> /// Is the command valid given the selected objects /// </summary> /// <param name="selectedObjects"></param> /// <returns></returns> public bool IsSelectionValidForCommand(GroupedSelection selection, int commandId) { selectedObjects = selection; return(IsSelectionValidForCommand(commandId)); }