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 )
{
showConfirmThen( msg, posButton, callbackID, null );
}
public void showConfirmThen( String msg, int posButton, int callbackID,
Object[] params )
{
DlgState state = new DlgState( CONFIRM_THEN, msg, posButton,
callbackID, 0 );
callbackID, 0, params );
addState( state );
m_activity.showDialog( CONFIRM_THEN );
}

View file

@ -50,12 +50,19 @@ public class DlgState implements Parcelable {
public DlgState( int id, String msg, int posButton,
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_msg = msg;
m_posButton = posButton;
m_cbckID = cbckID;
m_prefsKey = prefsKey;
m_params = params;
}
public DlgState( int id, int cbckID )

View file

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

View file

@ -122,9 +122,10 @@ public class XWExpandableListActivity extends ExpandableListActivity
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 )