fix NPEs occurring when loading in a games DB (debug feature) whose

groups were different: recreate GameListAdapter and make it correctly
deal with having no group selection data (as that's stored in prefs)
This commit is contained in:
Eric House 2013-12-03 08:30:47 -08:00
parent 7c2b3b3d15
commit ca428d6a63
2 changed files with 26 additions and 12 deletions

View file

@ -329,7 +329,8 @@ public class GameListAdapter implements ExpandableListAdapter {
long[] positions = getGroupPositions();
String[] names = new String[ positions.length ];
for ( int ii = 0; ii < names.length; ++ii ) {
names[ii] = info.get(positions[ii]).m_name;
GameGroupInfo ggi = info.get( positions[ii] );
names[ii] = ggi.m_name;
}
return names;
}
@ -486,10 +487,14 @@ public class GameListAdapter implements ExpandableListAdapter {
long[] result = positions;
if ( null != positions ) {
Set<Long> posns = gameInfo().keySet();
for ( long id : positions ) {
if ( ! posns.contains( id ) ) {
result = null;
break;
if ( positions.length != posns.size() ) {
result = null;
} else {
for ( long id : positions ) {
if ( ! posns.contains( id ) ) {
result = null;
break;
}
}
}
}

View file

@ -385,15 +385,9 @@ public class GamesList extends XWExpandableListActivity
}
PreferenceManager.setDefaultValues( this, R.xml.xwprefs, isUpgrade );
String field = CommonPrefs.getSummaryField( this );
long[] positions = XWPrefs.getGroupPositions( this );
m_adapter = new GameListAdapter( this, listview, new Handler(),
this, positions, field );
setListAdapter( m_adapter );
m_adapter = makeNewAdapter();
listview.setOnItemLongClickListener( this );
m_adapter.expandGroups( listview );
NetUtils.informOfDeaths( this );
tryStartsFromIntent( getIntent() );
@ -786,6 +780,8 @@ public class GamesList extends XWExpandableListActivity
case R.id.games_menu_loaddb:
DBUtils.loadDB( this );
XWPrefs.clearGroupPositions( this );
m_adapter = makeNewAdapter();
changeContent = true;
break;
case R.id.games_menu_storedb:
@ -1349,6 +1345,19 @@ public class GamesList extends XWExpandableListActivity
}
}
private GameListAdapter makeNewAdapter()
{
ExpandableListView listview = getExpandableListView();
String field = CommonPrefs.getSummaryField( this );
long[] positions = XWPrefs.getGroupPositions( this );
GameListAdapter adapter =
new GameListAdapter( this, listview, new Handler(),
this, positions, field );
setListAdapter( adapter );
adapter.expandGroups( listview );
return adapter;
}
public static void onGameDictDownload( Context context, Intent intent )
{
intent.setClass( context, GamesList.class );