mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
fix so gameless groups are still shown (but don't have an expand button)
This commit is contained in:
parent
52d2436903
commit
fe14c88685
3 changed files with 29 additions and 22 deletions
|
@ -1012,27 +1012,26 @@ public class DBUtils {
|
||||||
return thumb;
|
return thumb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return map of string (group name) to info about all games in
|
private static HashMap<Long, Integer> getGameCounts( SQLiteDatabase db )
|
||||||
// that group.
|
|
||||||
// public static HashMap<Long,GameGroupInfo> getGroups( Context context )
|
|
||||||
// {
|
|
||||||
// return getGroups( context, 0 );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// called while have db opened
|
|
||||||
private static int getGamesCount( SQLiteDatabase db, String name, long id )
|
|
||||||
{
|
{
|
||||||
int result = -1;
|
HashMap<Long, Integer> result = new HashMap<Long, Integer>();
|
||||||
String query = "SELECT count(rowid) from summaries where groupid = " + id;
|
String query = "SELECT %s, count(%s) as cnt FROM %s GROUP BY %s";
|
||||||
|
query = String.format( query, DBHelper.GROUPID, DBHelper.GROUPID,
|
||||||
|
DBHelper.TABLE_NAME_SUM, DBHelper.GROUPID );
|
||||||
|
|
||||||
Cursor cursor = db.rawQuery( query, null );
|
Cursor cursor = db.rawQuery( query, null );
|
||||||
if ( cursor.moveToNext() ) {
|
int rowIndex = cursor.getColumnIndex( DBHelper.GROUPID );
|
||||||
result = cursor.getInt( 0 );
|
int cntIndex = cursor.getColumnIndex( "cnt" );
|
||||||
|
while ( cursor.moveToNext() ) {
|
||||||
|
long row = cursor.getLong(rowIndex);
|
||||||
|
int count = cursor.getInt(cntIndex);
|
||||||
|
result.put( row, count );
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
DbgUtils.logf( "getGamesCount(%s)=>%d", name, result );
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map of groups rowid (= summaries.groupid) to group info record
|
||||||
protected static HashMap<Long,GameGroupInfo> getGroups( Context context )
|
protected static HashMap<Long,GameGroupInfo> getGroups( Context context )
|
||||||
{
|
{
|
||||||
if ( null == s_groupsCache ) {
|
if ( null == s_groupsCache ) {
|
||||||
|
@ -1050,18 +1049,20 @@ public class DBUtils {
|
||||||
initDB( context );
|
initDB( context );
|
||||||
synchronized( s_dbHelper ) {
|
synchronized( s_dbHelper ) {
|
||||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||||
|
|
||||||
|
HashMap<Long, Integer> map = getGameCounts( db );
|
||||||
|
|
||||||
Cursor cursor = db.rawQuery( query, null );
|
Cursor cursor = db.rawQuery( query, null );
|
||||||
int idIndex = cursor.getColumnIndex( "rowid" );
|
int idIndex = cursor.getColumnIndex( "rowid" );
|
||||||
int nameIndex = cursor.getColumnIndex( "groups_groupname" );
|
int nameIndex = cursor.getColumnIndex( "groups_groupname" );
|
||||||
int expandedIndex = cursor.getColumnIndex( "groups_expanded" );
|
int expandedIndex = cursor.getColumnIndex( "groups_expanded" );
|
||||||
DbgUtils.logf( "indices: %d, %d, %d", idIndex, nameIndex, expandedIndex );
|
|
||||||
|
|
||||||
while ( cursor.moveToNext() ) {
|
while ( cursor.moveToNext() ) {
|
||||||
long id = cursor.getLong( idIndex );
|
long id = cursor.getLong( idIndex );
|
||||||
String name = cursor.getString( nameIndex );
|
String name = cursor.getString( nameIndex );
|
||||||
Assert.assertNotNull( name );
|
Assert.assertNotNull( name );
|
||||||
boolean expanded = 0 != cursor.getInt( expandedIndex );
|
boolean expanded = 0 != cursor.getInt( expandedIndex );
|
||||||
int count = getGamesCount( db, name, id );
|
int count = map.containsKey( id ) ? map.get( id ) : 0;
|
||||||
result.put( id, new GameGroupInfo( name, count, expanded ) );
|
result.put( id, new GameGroupInfo( name, count, expanded ) );
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
|
@ -192,19 +192,20 @@ public class GameListAdapter extends XWListAdapter
|
||||||
DbgUtils.logf( "getView(convertView=%H)", convertView );
|
DbgUtils.logf( "getView(convertView=%H)", convertView );
|
||||||
View result = null;
|
View result = null;
|
||||||
HashMap<Long,GameGroupInfo> info = gameInfo();
|
HashMap<Long,GameGroupInfo> info = gameInfo();
|
||||||
Set<Long> posns = info.keySet();
|
|
||||||
int groupPosition = 0;
|
int groupPosition = 0;
|
||||||
int indx = position;
|
int indx = position;
|
||||||
for ( Iterator<Long>iter = posns.iterator(); iter.hasNext(); ) {
|
|
||||||
long groupID = iter.next();
|
long[] groupPosns = getGroupPositions();
|
||||||
|
for ( long groupID : groupPosns ) {
|
||||||
GameGroupInfo groupInfo = info.get( groupID );
|
GameGroupInfo groupInfo = info.get( groupID );
|
||||||
if ( indx == 0 ) {
|
if ( indx == 0 ) {
|
||||||
|
int nKids = getChildrenCount( groupPosition );
|
||||||
GameListGroup group =
|
GameListGroup group =
|
||||||
GameListGroup.makeForPosition( m_context, groupPosition,
|
GameListGroup.makeForPosition( m_context, groupPosition,
|
||||||
groupID, groupInfo.m_expanded,
|
groupID, nKids,
|
||||||
|
groupInfo.m_expanded,
|
||||||
m_cb, this );
|
m_cb, this );
|
||||||
|
|
||||||
int nKids = getChildrenCount( groupPosition );
|
|
||||||
String name = m_context.getString( R.string.group_namef,
|
String name = m_context.getString( R.string.group_namef,
|
||||||
groupNames()[groupPosition], nKids );
|
groupNames()[groupPosition], nKids );
|
||||||
group.setText( name );
|
group.setText( name );
|
||||||
|
@ -214,7 +215,7 @@ public class GameListAdapter extends XWListAdapter
|
||||||
} else {
|
} else {
|
||||||
int count = groupInfo.m_expanded ? groupInfo.m_count : 0;
|
int count = groupInfo.m_expanded ? groupInfo.m_count : 0;
|
||||||
// int count = groupInfo.m_count;
|
// int count = groupInfo.m_count;
|
||||||
DbgUtils.logf( "group[%d] visible count: %d", groupPosition, count );
|
// DbgUtils.logf( "group[%d] visible count: %d", groupPosition, count );
|
||||||
if ( indx <= count ) {
|
if ( indx <= count ) {
|
||||||
long[] rows = DBUtils.getGroupGames( m_context, groupID );
|
long[] rows = DBUtils.getGroupGames( m_context, groupID );
|
||||||
long rowid = rows[indx - 1];
|
long rowid = rows[indx - 1];
|
||||||
|
|
|
@ -46,12 +46,14 @@ public class GameListGroup extends LinearLayout
|
||||||
private GroupStateListener m_gcb;
|
private GroupStateListener m_gcb;
|
||||||
private ExpiringTextView m_etv;
|
private ExpiringTextView m_etv;
|
||||||
private boolean m_selected;
|
private boolean m_selected;
|
||||||
|
private int m_nGames;
|
||||||
private DrawSelDelegate m_dsdel;
|
private DrawSelDelegate m_dsdel;
|
||||||
private ImageButton m_expandButton;
|
private ImageButton m_expandButton;
|
||||||
|
|
||||||
public static GameListGroup makeForPosition( Context context,
|
public static GameListGroup makeForPosition( Context context,
|
||||||
int groupPosition,
|
int groupPosition,
|
||||||
long groupID,
|
long groupID,
|
||||||
|
int nGames,
|
||||||
boolean expanded,
|
boolean expanded,
|
||||||
SelectableItem cb,
|
SelectableItem cb,
|
||||||
GroupStateListener gcb )
|
GroupStateListener gcb )
|
||||||
|
@ -62,6 +64,7 @@ public class GameListGroup extends LinearLayout
|
||||||
result.m_gcb = gcb;
|
result.m_gcb = gcb;
|
||||||
result.m_groupPosition = groupPosition;
|
result.m_groupPosition = groupPosition;
|
||||||
result.m_groupID = groupID;
|
result.m_groupID = groupID;
|
||||||
|
result.m_nGames = nGames;
|
||||||
result.m_expanded = expanded;
|
result.m_expanded = expanded;
|
||||||
|
|
||||||
result.setButton(); // in case onFinishInflate already called
|
result.setButton(); // in case onFinishInflate already called
|
||||||
|
@ -160,6 +163,8 @@ public class GameListGroup extends LinearLayout
|
||||||
private void setButton()
|
private void setButton()
|
||||||
{
|
{
|
||||||
if ( null != m_expandButton ) {
|
if ( null != m_expandButton ) {
|
||||||
|
m_expandButton.setVisibility( 0 == m_nGames ?
|
||||||
|
View.GONE : View.VISIBLE );
|
||||||
m_expandButton.setImageResource( m_expanded ?
|
m_expandButton.setImageResource( m_expanded ?
|
||||||
R.drawable.expander_ic_maximized :
|
R.drawable.expander_ic_maximized :
|
||||||
R.drawable.expander_ic_minimized);
|
R.drawable.expander_ic_minimized);
|
||||||
|
|
Loading…
Add table
Reference in a new issue