fix so gameless groups are still shown (but don't have an expand button)

This commit is contained in:
Eric House 2014-03-28 22:32:35 -07:00
parent 52d2436903
commit fe14c88685
3 changed files with 29 additions and 22 deletions

View file

@ -1012,27 +1012,26 @@ public class DBUtils {
return thumb;
}
// Return map of string (group name) to info about all games in
// 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 )
private static HashMap<Long, Integer> getGameCounts( SQLiteDatabase db )
{
int result = -1;
String query = "SELECT count(rowid) from summaries where groupid = " + id;
HashMap<Long, Integer> result = new HashMap<Long, Integer>();
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 );
if ( cursor.moveToNext() ) {
result = cursor.getInt( 0 );
int rowIndex = cursor.getColumnIndex( DBHelper.GROUPID );
int cntIndex = cursor.getColumnIndex( "cnt" );
while ( cursor.moveToNext() ) {
long row = cursor.getLong(rowIndex);
int count = cursor.getInt(cntIndex);
result.put( row, count );
}
cursor.close();
DbgUtils.logf( "getGamesCount(%s)=>%d", name, result );
return result;
}
// Map of groups rowid (= summaries.groupid) to group info record
protected static HashMap<Long,GameGroupInfo> getGroups( Context context )
{
if ( null == s_groupsCache ) {
@ -1050,18 +1049,20 @@ public class DBUtils {
initDB( context );
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
HashMap<Long, Integer> map = getGameCounts( db );
Cursor cursor = db.rawQuery( query, null );
int idIndex = cursor.getColumnIndex( "rowid" );
int nameIndex = cursor.getColumnIndex( "groups_groupname" );
int expandedIndex = cursor.getColumnIndex( "groups_expanded" );
DbgUtils.logf( "indices: %d, %d, %d", idIndex, nameIndex, expandedIndex );
while ( cursor.moveToNext() ) {
long id = cursor.getLong( idIndex );
String name = cursor.getString( nameIndex );
Assert.assertNotNull( name );
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 ) );
}
cursor.close();

View file

@ -192,19 +192,20 @@ public class GameListAdapter extends XWListAdapter
DbgUtils.logf( "getView(convertView=%H)", convertView );
View result = null;
HashMap<Long,GameGroupInfo> info = gameInfo();
Set<Long> posns = info.keySet();
int groupPosition = 0;
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 );
if ( indx == 0 ) {
int nKids = getChildrenCount( groupPosition );
GameListGroup group =
GameListGroup.makeForPosition( m_context, groupPosition,
groupID, groupInfo.m_expanded,
groupID, nKids,
groupInfo.m_expanded,
m_cb, this );
int nKids = getChildrenCount( groupPosition );
String name = m_context.getString( R.string.group_namef,
groupNames()[groupPosition], nKids );
group.setText( name );
@ -214,7 +215,7 @@ public class GameListAdapter extends XWListAdapter
} else {
int count = groupInfo.m_expanded ? groupInfo.m_count : 0;
// 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 ) {
long[] rows = DBUtils.getGroupGames( m_context, groupID );
long rowid = rows[indx - 1];

View file

@ -46,12 +46,14 @@ public class GameListGroup extends LinearLayout
private GroupStateListener m_gcb;
private ExpiringTextView m_etv;
private boolean m_selected;
private int m_nGames;
private DrawSelDelegate m_dsdel;
private ImageButton m_expandButton;
public static GameListGroup makeForPosition( Context context,
int groupPosition,
long groupID,
int nGames,
boolean expanded,
SelectableItem cb,
GroupStateListener gcb )
@ -62,6 +64,7 @@ public class GameListGroup extends LinearLayout
result.m_gcb = gcb;
result.m_groupPosition = groupPosition;
result.m_groupID = groupID;
result.m_nGames = nGames;
result.m_expanded = expanded;
result.setButton(); // in case onFinishInflate already called
@ -160,6 +163,8 @@ public class GameListGroup extends LinearLayout
private void setButton()
{
if ( null != m_expandButton ) {
m_expandButton.setVisibility( 0 == m_nGames ?
View.GONE : View.VISIBLE );
m_expandButton.setImageResource( m_expanded ?
R.drawable.expander_ic_maximized :
R.drawable.expander_ic_minimized);