Clear selections after every menuitem call. Since that means the

selection's not available after a confirm dialog, modify
showConfirmThen() to take optional params like showNotAgainDlgThen(),
and make deleting games use it.
This commit is contained in:
Eric House 2013-10-19 10:12:57 -07:00
parent df48c5d142
commit 7712ee15e3
4 changed files with 64 additions and 26 deletions

View file

@ -194,9 +194,15 @@ public class DlgDelegate {
} }
public void showConfirmThen( String msg, int posButton, int callbackID ) public void showConfirmThen( String msg, int posButton, int callbackID )
{
showConfirmThen( msg, posButton, callbackID, null );
}
public void showConfirmThen( String msg, int posButton, int callbackID,
Object[] params )
{ {
DlgState state = new DlgState( CONFIRM_THEN, msg, posButton, DlgState state = new DlgState( CONFIRM_THEN, msg, posButton,
callbackID, 0 ); callbackID, 0, params );
addState( state ); addState( state );
m_activity.showDialog( CONFIRM_THEN ); m_activity.showDialog( CONFIRM_THEN );
} }

View file

@ -50,12 +50,19 @@ public class DlgState implements Parcelable {
public DlgState( int id, String msg, int posButton, public DlgState( int id, String msg, int posButton,
int cbckID, int prefsKey ) int cbckID, int prefsKey )
{
this( id, msg, posButton, cbckID, prefsKey, null );
}
public DlgState( int id, String msg, int posButton,
int cbckID, int prefsKey, Object[] params )
{ {
m_id = id; m_id = id;
m_msg = msg; m_msg = msg;
m_posButton = posButton; m_posButton = posButton;
m_cbckID = cbckID; m_cbckID = cbckID;
m_prefsKey = prefsKey; m_prefsKey = prefsKey;
m_params = params;
} }
public DlgState( int id, int cbckID ) public DlgState( int id, int cbckID )

View file

@ -88,7 +88,7 @@ public class GamesList extends XWExpandableListActivity
SYNC_MENU, SYNC_MENU,
NEW_FROM, NEW_FROM,
DELETE_GROUP, DELETE_GROUP,
DELETE_SELGAMES, DELETE_GAMES,
OPEN_GAME OPEN_GAME
}; };
private static final int[] DEBUGITEMS = { private static final int[] DEBUGITEMS = {
@ -576,8 +576,8 @@ public class GamesList extends XWExpandableListActivity
GameUtils.deleteGroup( this, m_groupid ); GameUtils.deleteGroup( this, m_groupid );
onContentChanged(); onContentChanged();
break; break;
case DELETE_SELGAMES: case DELETE_GAMES:
deleteSelected(); deleteGames( (long[])params[0] );
break; break;
case OPEN_GAME: case OPEN_GAME:
doOpenGame( params ); doOpenGame( params );
@ -663,10 +663,10 @@ public class GamesList extends XWExpandableListActivity
if ( 0 <= groupPos ) { if ( 0 <= groupPos ) {
m_adapter.getGroupIDFor( groupPos ); m_adapter.getGroupIDFor( groupPos );
} }
long selRowID = getSelRowID(); long[] selRowIDs = getSelRowIDs();
if ( 0 <= selRowID && !checkWarnNoDict( selRowID ) ) { if ( 1 == selRowIDs.length && !checkWarnNoDict( selRowIDs[0] ) ) {
return true; // FIX THIS!!! return true; // FIXME: RETURN FROM MIDDLE!!!
} }
switch ( item.getItemId() ) { switch ( item.getItemId() ) {
@ -685,9 +685,9 @@ public class GamesList extends XWExpandableListActivity
case R.id.gamel_menu_delete: case R.id.gamel_menu_delete:
String msg = Utils.format( this, R.string.confirm_seldeletesf, String msg = Utils.format( this, R.string.confirm_seldeletesf,
m_selectedGames.size() ); selRowIDs.length );
showConfirmThen( msg, R.string.button_delete, showConfirmThen( msg, R.string.button_delete,
GamesActions.DELETE_SELGAMES.ordinal() ); GamesActions.DELETE_GAMES.ordinal(), selRowIDs );
break; break;
case R.id.gamel_menu_dicts: case R.id.gamel_menu_dicts:
@ -729,21 +729,21 @@ public class GamesList extends XWExpandableListActivity
if ( 1 >= m_adapter.getGroupCount() ) { if ( 1 >= m_adapter.getGroupCount() ) {
showOKOnlyDialog( R.string.no_move_onegroup ); showOKOnlyDialog( R.string.no_move_onegroup );
} else { } else {
m_rowid = selRowID; m_rowid = selRowIDs[0];
showDialog( CHANGE_GROUP ); showDialog( CHANGE_GROUP );
} }
break; break;
case R.id.list_item_new_from: case R.id.list_item_new_from:
showNotAgainDlgThen( R.string.not_again_newfrom, showNotAgainDlgThen( R.string.not_again_newfrom,
R.string.key_notagain_newfrom, R.string.key_notagain_newfrom,
GamesActions.NEW_FROM.ordinal(), selRowID ); GamesActions.NEW_FROM.ordinal(), selRowIDs[0] );
break; break;
case R.id.list_item_copy: case R.id.list_item_copy:
GameSummary summary = DBUtils.getSummary( this, selRowID ); GameSummary summary = DBUtils.getSummary( this, selRowIDs[0] );
if ( summary.inNetworkGame() ) { if ( summary.inNetworkGame() ) {
showOKOnlyDialog( R.string.no_copy_network ); showOKOnlyDialog( R.string.no_copy_network );
} else { } else {
byte[] stream = GameUtils.savedGame( this, selRowID ); byte[] stream = GameUtils.savedGame( this, selRowIDs[0] );
GameLock lock = GameUtils.saveNewGame( this, stream ); GameLock lock = GameUtils.saveNewGame( this, stream );
DBUtils.saveSummary( this, lock, summary ); DBUtils.saveSummary( this, lock, summary );
lock.unlock(); lock.unlock();
@ -751,14 +751,14 @@ public class GamesList extends XWExpandableListActivity
break; break;
case R.id.list_item_reset: case R.id.list_item_reset:
m_rowid = selRowID; m_rowid = selRowIDs[0];
showConfirmThen( R.string.confirm_reset, showConfirmThen( R.string.confirm_reset,
R.string.button_reset, R.string.button_reset,
GamesActions.RESET_GAME.ordinal() ); GamesActions.RESET_GAME.ordinal() );
break; break;
case R.id.list_item_rename: case R.id.list_item_rename:
m_rowid = selRowID; m_rowid = selRowIDs[0];
showDialog( RENAME_GAME ); showDialog( RENAME_GAME );
break; break;
@ -799,6 +799,10 @@ public class GamesList extends XWExpandableListActivity
handled = false; handled = false;
} }
if ( handled ) {
clearSelections();
}
return handled; return handled;
} }
@ -1047,14 +1051,12 @@ public class GamesList extends XWExpandableListActivity
return dialog; return dialog;
} }
private void deleteSelected() private void deleteGames( long[] rowids )
{ {
for ( Iterator<Long> iter = m_selectedGames.iterator(); iter.hasNext(); ) { for ( long rowid : rowids ) {
long rowid = iter.next();
GameUtils.deleteGame( this, rowid, false ); GameUtils.deleteGame( this, rowid, false );
} }
m_selectedGames.clear();
Utils.invalidateOptionsMenuIf( this );
NetUtils.informOfDeaths( this ); NetUtils.informOfDeaths( this );
} }
@ -1068,6 +1070,26 @@ public class GamesList extends XWExpandableListActivity
return madeGame; return madeGame;
} }
private void clearSelections()
{
boolean inval = false;
if ( 0 < m_selectedGames.size() ) {
m_adapter.clearSelectedRows( m_selectedGames );
m_selectedGames.clear();
inval = true;
}
if ( 0 < m_selectedGroups.size() ) {
m_adapter.clearSelectedGroups( m_selectedGroups );
m_selectedGroups.clear();
inval = true;
}
if ( inval ) {
Utils.invalidateOptionsMenuIf( this );
}
}
private void clearSelectedRows() private void clearSelectedRows()
{ {
// clear any selection // clear any selection
@ -1150,11 +1172,13 @@ public class GamesList extends XWExpandableListActivity
} }
} }
private long getSelRowID() private long[] getSelRowIDs()
{ {
long result = -1; long[] result = new long[m_selectedGames.size()];
if ( 1 == m_selectedGames.size() ) { int ii = 0;
result = m_selectedGames.iterator().next(); for ( Iterator<Long> iter = m_selectedGames.iterator();
iter.hasNext(); ) {
result[ii++] = iter.next();
} }
return result; return result;
} }

View file

@ -122,9 +122,10 @@ public class XWExpandableListActivity extends ExpandableListActivity
m_delegate.showConfirmThen( msg, action ); m_delegate.showConfirmThen( msg, action );
} }
protected void showConfirmThen( String msg, int posButton, int action ) protected void showConfirmThen( String msg, int posButton, int action,
Object... params )
{ {
m_delegate.showConfirmThen( msg, posButton, action ); m_delegate.showConfirmThen( msg, posButton, action, params );
} }
protected void showConfirmThen( int msg, int posButton, int action ) protected void showConfirmThen( int msg, int posButton, int action )