diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml
index cc2318e77..77cd644b2 100644
--- a/xwords4/android/XWords4/res/values/strings.xml
+++ b/xwords4/android/XWords4/res/values/strings.xml
@@ -2129,8 +2129,12 @@
Are you sure you want to delete
this group?
+ Are you sure you want to delete
+ these groups?
\u0020(It contains %d game[s],
which will also be deleted.)
+ \u0020(They contains %d game[s],
+ which will also be deleted.)
Change the name of this group to:
Name group
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java
index 6cf4ed192..afe74f862 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java
@@ -695,6 +695,14 @@ public class DBUtils {
public static GameLock saveNewGame( Context context, byte[] bytes )
{
+ long groupID = XWPrefs.getDefaultNewGameGroup( context );
+ return saveNewGame( context, bytes, groupID );
+ }
+
+ public static GameLock saveNewGame( Context context, byte[] bytes,
+ long groupID )
+ {
+ Assert.assertTrue( -1 != groupID ); // DON'T SHIP
GameLock lock = null;
initDB( context );
@@ -707,8 +715,7 @@ public class DBUtils {
long timestamp = new Date().getTime();
values.put( DBHelper.CREATE_TIME, timestamp );
values.put( DBHelper.LASTPLAY_TIME, timestamp );
- values.put( DBHelper.GROUPID,
- XWPrefs.getDefaultNewGameGroup( context ) );
+ values.put( DBHelper.GROUPID, groupID );
values.put( DBHelper.VISID, maxVISID( db ) );
long rowid = db.insert( DBHelper.TABLE_NAME_SUM, null, values );
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java
index 72a37abbd..feb90ca39 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java
@@ -190,7 +190,12 @@ public class DlgDelegate {
public void showConfirmThen( String msg, int callbackID )
{
- showConfirmThen( msg, R.string.button_ok, callbackID );
+ showConfirmThen( msg, R.string.button_ok, callbackID, null );
+ }
+
+ public void showConfirmThen( String msg, int callbackID, Object[] params )
+ {
+ showConfirmThen( msg, R.string.button_ok, callbackID, params );
}
public void showConfirmThen( String msg, int posButton, int callbackID )
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java
index c301fb25e..78f2cd2ab 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java
@@ -156,7 +156,7 @@ public class GameListAdapter implements ExpandableListAdapter {
return ggi.m_name;
}
- public void clearSelectedRows( Set rowids )
+ public void clearSelectedGames( long[] rowids )
{
deselectRows( rowids );
}
@@ -187,11 +187,11 @@ public class GameListAdapter implements ExpandableListAdapter {
DBUtils.setGroupExpanded( m_context, groupid, false );
long[] rowids = DBUtils.getGroupGames( m_context, groupid );
- HashSet asSet = new HashSet(rowids.length);
- for ( long rowid : rowids ) {
- asSet.add( rowid );
- }
- deselectRows( asSet );
+ // HashSet asSet = new HashSet(rowids.length);
+ // for ( long rowid : rowids ) {
+ // asSet.add( rowid );
+ // }
+ deselectRows( rowids );
}
public void onGroupExpanded( int groupPosition )
@@ -282,7 +282,12 @@ public class GameListAdapter implements ExpandableListAdapter {
public int getChildrenCount( int groupPosition )
{
- long[] rows = getRows( getPositions()[groupPosition] );
+ return getChildrenCount( getPositions()[groupPosition] );
+ }
+
+ public int getChildrenCount( long groupID )
+ {
+ long[] rows = getRows( groupID );
return rows.length;
}
@@ -372,9 +377,9 @@ public class GameListAdapter implements ExpandableListAdapter {
return gameInfo().get( getPositions()[groupPosition] );
}
- private void deselectRows( Set rowids )
+ private void deselectRows( long[] rowids )
{
- GameListItem[] items = new GameListItem[rowids.size()];
+ GameListItem[] items = new GameListItem[rowids.length];
getGameItemsFor( rowids, items );
for ( GameListItem item : items ) {
if ( null != item ) {
@@ -393,15 +398,20 @@ public class GameListAdapter implements ExpandableListAdapter {
}
}
- private void getGameItemsFor( Set rowids, GameListItem[] items )
+ private void getGameItemsFor( long[] rowids, GameListItem[] items )
{
+ Set rowidsSet = new HashSet();
+ for ( long rowid : rowids ) {
+ rowidsSet.add( rowid );
+ }
+
int next = 0;
int count = m_list.getChildCount();
for ( int ii = 0; ii < count; ++ii ) {
View view = m_list.getChildAt( ii );
if ( view instanceof GameListItem ) {
GameListItem tryme = (GameListItem)view;
- if ( rowids.contains( tryme.getRowID() ) ) {
+ if ( rowidsSet.contains( tryme.getRowID() ) ) {
items[next++] = tryme;
if ( next >= items.length ) {
break;
@@ -413,8 +423,7 @@ public class GameListAdapter implements ExpandableListAdapter {
private GameListItem getGameItemFor( long rowid )
{
- Set rowids = new HashSet(1);
- rowids.add( rowid );
+ long[] rowids = { rowid };
GameListItem[] items = new GameListItem[1];
getGameItemsFor( rowids, items );
return items[0];
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java
index 627aca0de..ec940e85b 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java
@@ -319,11 +319,17 @@ public class GameUtils {
}
public static long saveNew( Context context, CurGameInfo gi )
+ {
+ long groupID = XWPrefs.getDefaultNewGameGroup( context );
+ return saveNew( context, gi, groupID );
+ }
+
+ public static long saveNew( Context context, CurGameInfo gi, long groupID )
{
long rowid = DBUtils.ROWID_NOTFOUND;
byte[] bytes = XwJNI.gi_to_stream( gi );
if ( null != bytes ) {
- GameLock lock = DBUtils.saveNewGame( context, bytes );
+ GameLock lock = DBUtils.saveNewGame( context, bytes, groupID );
rowid = lock.getRowid();
lock.unlock();
}
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java
index 5bed4e4e0..9af63e912 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java
@@ -87,36 +87,34 @@ public class GamesList extends XWExpandableListActivity
RESET_GAME,
SYNC_MENU,
NEW_FROM,
- DELETE_GROUP,
+ DELETE_GROUPS,
DELETE_GAMES,
OPEN_GAME
};
private static final int[] DEBUGITEMS = {
- R.id.gamel_menu_loaddb
- , R.id.gamel_menu_storedb
- , R.id.gamel_menu_checkupdates
+ R.id.gamel_menu_loaddb,
+ R.id.gamel_menu_storedb,
+ R.id.gamel_menu_checkupdates,
};
private static final int[] NOSEL_ITEMS = {
- R.id.gamel_menu_newgame
- ,R.id.gamel_menu_newgroup
- ,R.id.gamel_menu_prefs
- ,R.id.gamel_menu_dicts
- ,R.id.gamel_menu_about
- ,R.id.gamel_menu_email
- ,R.id.gamel_menu_checkmoves
+ R.id.gamel_menu_newgroup,
+ R.id.gamel_menu_prefs,
+ R.id.gamel_menu_dicts,
+ R.id.gamel_menu_about,
+ R.id.gamel_menu_email,
+ R.id.gamel_menu_checkmoves,
};
private static final int[] ONEGAME_ITEMS = {
- R.id.listl_item_config
- ,R.id.list_item_rename
- ,R.id.list_item_new_from
- ,R.id.list_item_copy
+ R.id.listl_item_config,
+ R.id.list_item_rename,
+ R.id.list_item_new_from,
+ R.id.list_item_copy,
};
private static final int[] ONEGROUP_ITEMS = {
- R.id.list_group_default
- ,R.id.list_group_rename
- ,R.id.list_group_moveup
- ,R.id.list_group_movedown
+ R.id.list_group_rename,
+ R.id.list_group_moveup,
+ R.id.list_group_movedown,
};
private static boolean s_firstShown = false;
@@ -512,7 +510,7 @@ public class GamesList extends XWExpandableListActivity
int position = ((GameListGroup)toggled).getGroupPosition();
if ( selected ) {
m_selectedGroups.add( position );
- clearSelectedRows();
+ clearSelectedGames();
} else {
m_selectedGroups.remove( position );
}
@@ -572,8 +570,11 @@ public class GamesList extends XWExpandableListActivity
}
break;
- case DELETE_GROUP:
- GameUtils.deleteGroup( this, m_groupid );
+ case DELETE_GROUPS:
+ long[] groupIDs = (long[])params[0];
+ for ( long groupID : groupIDs ) {
+ GameUtils.deleteGroup( this, groupID );
+ }
onContentChanged();
break;
case DELETE_GAMES:
@@ -602,7 +603,7 @@ public class GamesList extends XWExpandableListActivity
if ( 0 == m_selectedGames.size() ) {
super.onBackPressed();
} else {
- clearSelectedRows();
+ clearSelections();
}
}
@@ -641,7 +642,21 @@ public class GamesList extends XWExpandableListActivity
for ( int id : ONEGROUP_ITEMS ) {
Utils.setItemVisible( menu, id, 1 == nGroupsSelected );
}
-
+
+ // You can't delete the default group, nor make it the default
+ boolean defaultAvail = 1 == nGroupsSelected;
+ if ( defaultAvail ) {
+ int selPos = m_selectedGroups.iterator().next();
+ long selID = m_adapter.getGroupIDFor( selPos );
+ defaultAvail = selID != XWPrefs.getDefaultNewGameGroup( this );
+ }
+ Utils.setItemVisible( menu, R.id.list_group_default, defaultAvail );
+ Utils.setItemVisible( menu, R.id.list_group_delete, defaultAvail );
+
+ // New game available when nothing selected or one group
+ Utils.setItemVisible( menu, R.id.gamel_menu_newgame,
+ nothingSelected || 1 == nGroupsSelected );
+
// Multiples can be deleted
Utils.setItemVisible( menu, R.id.gamel_menu_delete,
0 < nGamesSelected );
@@ -661,7 +676,7 @@ public class GamesList extends XWExpandableListActivity
int groupPos = getSelGroupPos();
long groupID = -1;
if ( 0 <= groupPos ) {
- m_adapter.getGroupIDFor( groupPos );
+ groupID = m_adapter.getGroupIDFor( groupPos );
}
long[] selRowIDs = getSelRowIDs();
@@ -671,7 +686,7 @@ public class GamesList extends XWExpandableListActivity
switch ( item.getItemId() ) {
case R.id.gamel_menu_newgame:
- startNewGameActivity();
+ startNewGameActivity( groupID );
break;
case R.id.gamel_menu_newgroup:
@@ -764,16 +779,23 @@ public class GamesList extends XWExpandableListActivity
// Group menus
case R.id.list_group_delete:
- m_groupid = groupID;
if ( groupID == XWPrefs.getDefaultNewGameGroup( this ) ) {
showOKOnlyDialog( R.string.cannot_delete_default_group );
} else {
- msg = getString( R.string.group_confirm_del );
- int nGames = m_adapter.getChildrenCount( groupPos );
- if ( 0 < nGames ) {
- msg += getString( R.string.group_confirm_delf, nGames );
+ long[] groupIDs = getSelGroupIDs();
+ msg = getString( 1 == groupIDs.length ? R.string.group_confirm_del
+ : R.string.groups_confirm_del );
+ int nGames = 0;
+ for ( long tmp : groupIDs ) {
+ nGames += m_adapter.getChildrenCount( tmp );
}
- showConfirmThen( msg, GamesActions.DELETE_GROUP.ordinal() );
+ if ( 0 < nGames ) {
+ int fmtID = 1 == groupIDs.length ? R.string.group_confirm_delf
+ : R.string.groups_confirm_delf;
+ msg += getString( fmtID, nGames );
+ }
+ showConfirmThen( msg, GamesActions.DELETE_GROUPS.ordinal(),
+ groupIDs );
}
break;
case R.id.list_group_default:
@@ -944,9 +966,12 @@ public class GamesList extends XWExpandableListActivity
}
}
- private void startNewGameActivity()
+ private void startNewGameActivity( long groupID )
{
- startActivity( new Intent( this, NewGameActivity.class ) );
+ if ( 0 > groupID ) {
+ groupID = XWPrefs.getDefaultNewGameGroup( this );
+ }
+ NewGameActivity.startActivity( this, groupID );
}
private void startNewNetGame( NetLaunchInfo nli )
@@ -1073,39 +1098,38 @@ public class GamesList extends XWExpandableListActivity
private void clearSelections()
{
boolean inval = false;
- if ( 0 < m_selectedGames.size() ) {
- m_adapter.clearSelectedRows( m_selectedGames );
- m_selectedGames.clear();
+ if ( clearSelectedGames() ) {
inval = true;
}
-
- if ( 0 < m_selectedGroups.size() ) {
- m_adapter.clearSelectedGroups( m_selectedGroups );
- m_selectedGroups.clear();
+ if ( clearSelectedGroups() ) {
inval = true;
}
-
- if ( inval ) {
+ if ( !inval ) {
Utils.invalidateOptionsMenuIf( this );
}
}
- private void clearSelectedRows()
+ private boolean clearSelectedGames()
{
// clear any selection
- if ( 0 < m_selectedGames.size() ) {
- m_adapter.clearSelectedRows( m_selectedGames );
+ boolean needsClear = 0 < m_selectedGames.size();
+ if ( needsClear ) {
+ long[] rowIDs = getSelRowIDs();
m_selectedGames.clear();
+ m_adapter.clearSelectedGames( rowIDs );
}
+ return needsClear;
}
- private void clearSelectedGroups()
+ private boolean clearSelectedGroups()
{
// clear any selection
- if ( 0 < m_selectedGroups.size() ) {
+ boolean needsClear = 0 < m_selectedGroups.size();
+ if ( needsClear ) {
m_adapter.clearSelectedGroups( m_selectedGroups );
m_selectedGroups.clear();
}
+ return needsClear;
}
private boolean launchGameIf()
@@ -1123,7 +1147,7 @@ public class GamesList extends XWExpandableListActivity
if ( !m_gameLaunched ) {
m_gameLaunched = true;
GameUtils.launchGame( this, rowid, invited );
- clearSelectedRows();
+ // clearSelectedGames();
}
}
@@ -1192,6 +1216,17 @@ public class GamesList extends XWExpandableListActivity
return result;
}
+ private long[] getSelGroupIDs()
+ {
+ long[] result = new long[m_selectedGroups.size()];
+ int ii = 0;
+ for ( Iterator iter = m_selectedGroups.iterator();
+ iter.hasNext(); ) {
+ result[ii++] = m_adapter.getGroupIDFor( iter.next() );
+ }
+ return result;
+ }
+
public static void onGameDictDownload( Context context, Intent intent )
{
intent.setClass( context, GamesList.class );
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java
index 6ed4e6b3a..16aba7711 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java
@@ -51,6 +51,7 @@ public class NewGameActivity extends XWActivity {
private static final String SAVE_REMOTEGAME = "REMOTEGAME";
private static final String SAVE_GAMEID = "GAMEID";
private static final String SAVE_NAMEFOR = "SAVE_NAMEFOR";
+ private static final String GROUPID_EXTRA = "groupid";
private static final int CONFIG_FOR_BT = 1;
private static final int CONFIG_FOR_SMS = 2;
private static final int INVITE_FOR_BT = 3;
@@ -68,6 +69,7 @@ public class NewGameActivity extends XWActivity {
private long m_newRowID = -1;
private String m_gameName;
private int m_gameID;
+ private long m_groupID;
private String m_remoteDev;
@Override
@@ -76,6 +78,8 @@ public class NewGameActivity extends XWActivity {
super.onCreate( savedInstanceState );
getBundledData( savedInstanceState );
+ m_groupID = getIntent().getLongExtra( GROUPID_EXTRA, -1 );
+
setContentView( R.layout.new_game );
TextView desc = (TextView)findViewById( R.id.newgame_local_desc );
@@ -327,7 +331,7 @@ public class NewGameActivity extends XWActivity {
rowid = GameUtils.makeNewNetGame( this, room, inviteID, lang,
dict, nPlayers, 1 );
} else {
- rowid = GameUtils.saveNew( this, new CurGameInfo( this ) );
+ rowid = GameUtils.saveNew( this, new CurGameInfo( this ), m_groupID );
}
if ( launch ) {
@@ -468,4 +472,11 @@ public class NewGameActivity extends XWActivity {
}
}
}
+
+ public static void startActivity( Activity parent, long groupID )
+ {
+ Intent intent = new Intent( parent, NewGameActivity.class );
+ intent.putExtra( GROUPID_EXTRA, groupID );
+ parent.startActivity( intent );
+ }
}
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWExpandableListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWExpandableListActivity.java
index 054ca2ac0..a6e78ee4c 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWExpandableListActivity.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWExpandableListActivity.java
@@ -117,9 +117,9 @@ public class XWExpandableListActivity extends ExpandableListActivity
m_delegate.showOKOnlyDialog( msg );
}
- protected void showConfirmThen( String msg, int action )
+ protected void showConfirmThen( String msg, int action, Object... params )
{
- m_delegate.showConfirmThen( msg, action );
+ m_delegate.showConfirmThen( msg, action, params );
}
protected void showConfirmThen( String msg, int posButton, int action,