mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
For move, make current group the default and warn whether there's only
one.
This commit is contained in:
parent
19e7e27f1e
commit
3bff555bfd
4 changed files with 50 additions and 7 deletions
|
@ -2157,4 +2157,7 @@
|
|||
|
||||
<string name="cannot_delete_default_group">The group for new games
|
||||
cannot be deleted."</string>
|
||||
|
||||
<string name="no_move_onegroup">Moving is impossible until there
|
||||
is more than one group.</string>
|
||||
</resources>
|
||||
|
|
|
@ -875,7 +875,6 @@ public class DBUtils {
|
|||
// that group.
|
||||
public static HashMap<String,GameGroupInfo> getGroups( Context context )
|
||||
{
|
||||
DbgUtils.logf("getGroupInfo called");
|
||||
if ( null == s_groupsCache ) {
|
||||
HashMap<String,GameGroupInfo> result =
|
||||
new HashMap<String,GameGroupInfo>();
|
||||
|
@ -899,14 +898,12 @@ public class DBUtils {
|
|||
String name = cursor.getString( nameIndex );
|
||||
long id = cursor.getLong( idIndex );
|
||||
Assert.assertNotNull( name );
|
||||
DbgUtils.logf( "getGroups: got name %s, id %d", name, id );
|
||||
boolean expanded = 0 != cursor.getInt( expandedIndex );
|
||||
result.put( name, new GameGroupInfo( id, expanded ) );
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
DbgUtils.logf("getGroups=>size %d", result.size());
|
||||
s_groupsCache = result;
|
||||
}
|
||||
return s_groupsCache;
|
||||
|
@ -940,6 +937,31 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static long getGroupForGame( Context context, long rowid )
|
||||
{
|
||||
long result = ROWID_NOTFOUND;
|
||||
initDB( context );
|
||||
String[] columns = { DBHelper.GROUPID };
|
||||
String selection = String.format( ROW_ID_FMT, rowid );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, // selection
|
||||
null, // args
|
||||
null, // groupBy
|
||||
null, // having
|
||||
null //orderby
|
||||
);
|
||||
if ( cursor.moveToNext() ) {
|
||||
int index = cursor.getColumnIndex( DBHelper.GROUPID );
|
||||
result = cursor.getLong( index );
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static long addGroup( Context context, String name )
|
||||
{
|
||||
long rowid = ROWID_NOTFOUND;
|
||||
|
|
|
@ -297,8 +297,6 @@ public class GameListAdapter implements ExpandableListAdapter {
|
|||
GameGroupInfo ggi = info.get( names[ii] );
|
||||
if ( ggi.m_expanded ) {
|
||||
view.expandGroup( ii );
|
||||
} else {
|
||||
view.collapseGroup( ii );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -525,6 +523,20 @@ public class GameListAdapter implements ExpandableListAdapter {
|
|||
set.toArray(names);
|
||||
return names;
|
||||
}
|
||||
|
||||
public int getGroupPosition( long groupid )
|
||||
{
|
||||
int pos;
|
||||
String[] names = groupNames();
|
||||
HashMap<String, GameGroupInfo> info = gameInfo();
|
||||
for ( pos = 0; pos < names.length; ++pos ) {
|
||||
GameGroupInfo ggi = info.get( names[pos] );
|
||||
if ( ggi.m_id == groupid ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
private HashMap<String,GameGroupInfo> gameInfo()
|
||||
{
|
||||
|
|
|
@ -243,8 +243,10 @@ public class GamesList extends XWExpandableListActivity
|
|||
}
|
||||
};
|
||||
String[] groups = m_adapter.groupNames();
|
||||
long groupid = DBUtils.getGroupForGame( this, m_rowid );
|
||||
int curGroupPos = m_adapter.getGroupPosition( groupid );
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
.setSingleChoiceItems( groups, -1, lstnr )
|
||||
.setSingleChoiceItems( groups, curGroupPos, lstnr )
|
||||
.setPositiveButton( R.string.button_ok, lstnr2 )
|
||||
.create();
|
||||
Utils.setRemoveOnDismiss( this, dialog, id );
|
||||
|
@ -746,7 +748,11 @@ public class GamesList extends XWExpandableListActivity
|
|||
showDialog( RENAME_GAME );
|
||||
break;
|
||||
case R.id.list_item_move:
|
||||
showDialog( CHANGE_GROUP );
|
||||
if ( 1 >= m_adapter.getGroupCount() ) {
|
||||
showOKOnlyDialog( R.string.no_move_onegroup );
|
||||
} else {
|
||||
showDialog( CHANGE_GROUP );
|
||||
}
|
||||
break;
|
||||
case R.id.list_item_new_from:
|
||||
showNotAgainDlgThen( R.string.not_again_newfrom,
|
||||
|
|
Loading…
Reference in a new issue