on ICS+, onPrepareOptionsMenu can get called several times while

adjusting selections, so just bail when they're in an incomplete state.
This commit is contained in:
Eric House 2013-10-21 07:43:31 -07:00
parent b7edbf14a4
commit 7a4d3093a1

View file

@ -617,66 +617,73 @@ public class GamesList extends XWExpandableListActivity
@Override @Override
public boolean onPrepareOptionsMenu( Menu menu ) public boolean onPrepareOptionsMenu( Menu menu )
{ {
boolean show;
int nGamesSelected = m_selectedGames.size(); int nGamesSelected = m_selectedGames.size();
int nGroupsSelected = m_selectedGroups.size(); int nGroupsSelected = m_selectedGroups.size();
boolean nothingSelected = 0 == (nGroupsSelected + nGamesSelected); if ( 0 < nGamesSelected && 0 < nGroupsSelected ) {
Assert.assertTrue( 0 == nGamesSelected || 0 == nGroupsSelected ); DbgUtils.logf( "onPrepareOptionsMenu: incomplete so bailing" );
show = false;
} else {
boolean nothingSelected = 0 == (nGroupsSelected + nGamesSelected);
boolean visible = XWPrefs.getDebugEnabled( this ); boolean visible = XWPrefs.getDebugEnabled( this );
for ( int id : DEBUGITEMS ) { for ( int id : DEBUGITEMS ) {
Utils.setItemVisible( menu, id, nothingSelected && visible ); Utils.setItemVisible( menu, id, nothingSelected && visible );
} }
if ( visible && !DBUtils.gameDBExists( this ) ) { if ( visible && !DBUtils.gameDBExists( this ) ) {
Utils.setItemVisible( menu, R.id.gamel_menu_loaddb, false ); Utils.setItemVisible( menu, R.id.gamel_menu_loaddb, false );
} }
for ( int id : NOSEL_ITEMS ) { for ( int id : NOSEL_ITEMS ) {
Utils.setItemVisible( menu, id, nothingSelected ); Utils.setItemVisible( menu, id, nothingSelected );
} }
for ( int id : ONEGAME_ITEMS ) { for ( int id : ONEGAME_ITEMS ) {
Utils.setItemVisible( menu, id, 1 == nGamesSelected ); Utils.setItemVisible( menu, id, 1 == nGamesSelected );
} }
for ( int id : ONEGROUP_ITEMS ) { for ( int id : ONEGROUP_ITEMS ) {
Utils.setItemVisible( menu, id, 1 == nGroupsSelected ); Utils.setItemVisible( menu, id, 1 == nGroupsSelected );
} }
int selGroupPos = -1; int selGroupPos = -1;
if ( 1 == nGroupsSelected ) { if ( 1 == nGroupsSelected ) {
selGroupPos = m_selectedGroups.iterator().next(); selGroupPos = m_selectedGroups.iterator().next();
} }
// You can't delete the default group, nor make it the default // You can't delete the default group, nor make it the default
boolean defaultAvail = 1 == nGroupsSelected; boolean defaultAvail = 1 == nGroupsSelected;
if ( defaultAvail ) { if ( defaultAvail ) {
long selID = m_adapter.getGroupIDFor( selGroupPos ); long selID = m_adapter.getGroupIDFor( selGroupPos );
defaultAvail = selID != XWPrefs.getDefaultNewGameGroup( this ); defaultAvail = selID != XWPrefs.getDefaultNewGameGroup( this );
} }
Utils.setItemVisible( menu, R.id.list_group_default, defaultAvail ); Utils.setItemVisible( menu, R.id.list_group_default, defaultAvail );
Utils.setItemVisible( menu, R.id.list_group_delete, defaultAvail ); Utils.setItemVisible( menu, R.id.list_group_delete, defaultAvail );
// Move up/down enabled for groups if not the top-most or bottommost // Move up/down enabled for groups if not the top-most or bottommost
// selected // selected
boolean enable = 0 < selGroupPos; boolean enable = 0 < selGroupPos;
Utils.setItemVisible( menu, R.id.list_group_moveup, enable ); Utils.setItemVisible( menu, R.id.list_group_moveup, enable );
enable = 0 <= selGroupPos && selGroupPos + 1 < m_adapter.getGroupCount(); enable = 0 <= selGroupPos && selGroupPos + 1 < m_adapter.getGroupCount();
Utils.setItemVisible( menu, R.id.list_group_movedown, enable ); Utils.setItemVisible( menu, R.id.list_group_movedown, enable );
// New game available when nothing selected or one group // New game available when nothing selected or one group
Utils.setItemVisible( menu, R.id.gamel_menu_newgame, Utils.setItemVisible( menu, R.id.gamel_menu_newgame,
nothingSelected || 1 == nGroupsSelected ); nothingSelected || 1 == nGroupsSelected );
// Multiples can be deleted // Multiples can be deleted
Utils.setItemVisible( menu, R.id.gamel_menu_delete, Utils.setItemVisible( menu, R.id.gamel_menu_delete,
0 < nGamesSelected ); 0 < nGamesSelected );
Utils.setItemVisible( menu, R.id.list_group_delete, Utils.setItemVisible( menu, R.id.list_group_delete,
0 < nGroupsSelected ); 0 < nGroupsSelected );
// multiple games can be regrouped/reset. (Later....) // multiple games can be regrouped/reset. (Later....)
Utils.setItemVisible( menu, R.id.list_item_move, 1 == nGamesSelected ); Utils.setItemVisible( menu, R.id.list_item_move, 1 == nGamesSelected );
Utils.setItemVisible( menu, R.id.list_item_reset, 1 == nGamesSelected ); Utils.setItemVisible( menu, R.id.list_item_reset, 1 == nGamesSelected );
return super.onPrepareOptionsMenu( menu ); show = super.onPrepareOptionsMenu( menu );
}
return show;
} }
public boolean onOptionsItemSelected( MenuItem item ) public boolean onOptionsItemSelected( MenuItem item )