set selected when creating group header nodes, fixing problem where

they stop showing as selected when other nodes are expanded or
contracted (which winds up reallocating all group nodes).
This commit is contained in:
Eric House 2013-10-23 19:16:55 -07:00
parent ddb64d3dc9
commit 77d38fe230
3 changed files with 28 additions and 11 deletions

View file

@ -49,9 +49,11 @@ public class GameListAdapter implements ExpandableListAdapter {
private long[] m_positions;
public interface LoadItemCB {
public void itemClicked( Object clicked, GameSummary summary );
public void itemToggled( Object toggled, boolean selected );
public boolean getSelected( long rowid );
public void itemClicked( GameListAdapter.ClickHandler clicked,
GameSummary summary );
public void itemToggled( GameListAdapter.ClickHandler toggled,
boolean selected );
public boolean getSelected( GameListAdapter.ClickHandler obj );
}
public interface ClickHandler {
@ -158,7 +160,7 @@ public class GameListAdapter implements ExpandableListAdapter {
public void clearSelectedGames( long[] rowids )
{
deselectRows( rowids );
deselectGames( rowids );
}
public void clearSelectedGroups( HashSet<Long> groupIDs )
@ -191,7 +193,7 @@ public class GameListAdapter implements ExpandableListAdapter {
// for ( long rowid : rowids ) {
// asSet.add( rowid );
// }
deselectRows( rowids );
deselectGames( rowids );
}
public void onGroupExpanded( int groupPosition )
@ -257,6 +259,8 @@ public class GameListAdapter implements ExpandableListAdapter {
groupNames()[groupPosition], nKids );
view.setText( name );
view.setSelected( m_cb.getSelected( view ) );
return view;
}
@ -379,7 +383,7 @@ public class GameListAdapter implements ExpandableListAdapter {
return gameInfo().get( getGroupPositions()[groupPosition] );
}
private void deselectRows( long[] rowids )
private void deselectGames( long[] rowids )
{
GameListItem[] items = new GameListItem[rowids.length];
getGameItemsFor( rowids, items );

View file

@ -335,7 +335,7 @@ public class GameListItem extends LinearLayout
}
}
if ( m_cb.getSelected( m_rowid ) && m_selected ) {
if ( m_cb.getSelected( GameListItem.this ) && m_selected ) {
toggleSelected();
}
}

View file

@ -493,7 +493,8 @@ public class GamesList extends XWExpandableListActivity
}
// GameListAdapter.LoadItemCB interface
public void itemClicked( Object clicked, GameSummary summary )
public void itemClicked( GameListAdapter.ClickHandler clicked,
GameSummary summary )
{
// We need a way to let the user get back to the basic-config
// dialog in case it was dismissed. That way it to check for
@ -509,7 +510,8 @@ public class GamesList extends XWExpandableListActivity
}
}
public void itemToggled( Object toggled, boolean selected )
public void itemToggled( GameListAdapter.ClickHandler toggled,
boolean selected )
{
if ( toggled instanceof GameListItem ) {
long rowid = ((GameListItem)toggled).getRowID();
@ -532,9 +534,20 @@ public class GamesList extends XWExpandableListActivity
setTitleBar();
}
public boolean getSelected( long rowid )
public boolean getSelected( GameListAdapter.ClickHandler obj )
{
return m_selGames.contains( rowid );
boolean selected;
if ( obj instanceof GameListItem ) {
long rowid = ((GameListItem)obj).getRowID();
selected = m_selGames.contains( rowid );
} else if ( obj instanceof GameListGroup ) {
long groupID = ((GameListGroup)obj).getGroupID();
selected = m_selGroupIDs.contains( groupID );
} else {
Assert.fail();
selected = false;
}
return selected;
}
// BTService.MultiEventListener interface