[Android] Like the previous commit (but for the GameListFragment), don't constantly create a new adapter when filling the game list.

This commit is contained in:
Lioncash 2013-11-16 05:30:58 -05:00
parent d98664b053
commit 11a156615f
2 changed files with 14 additions and 26 deletions

View File

@ -12,11 +12,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.List;
import org.dolphinemu.dolphinemu.R;
/**
@ -28,28 +25,19 @@ public final class GameListAdapter extends ArrayAdapter<GameListItem>
{
private final Context context;
private final int id;
private final List<GameListItem>items;
/**
* Constructor
*
* @param context The current {@link Context}.
* @param resourceId The resource ID for a layout file containing a layout to use when instantiating views.
* @param objects The objects to represent in the {@link ListView}.
*/
public GameListAdapter(Context context, int resourceId, List<GameListItem> objects)
public GameListAdapter(Context context, int resourceId)
{
super(context, resourceId, objects);
super(context, resourceId);
this.context = context;
this.id = resourceId;
this.items = objects;
}
@Override
public GameListItem getItem(int i)
{
return items.get(i);
}
@Override
@ -61,7 +49,7 @@ public final class GameListAdapter extends ArrayAdapter<GameListItem>
convertView = vi.inflate(id, parent, false);
}
final GameListItem item = items.get(position);
final GameListItem item = getItem(position);
if (item != null)
{
TextView title = (TextView) convertView.findViewById(R.id.ListItemTitle);

View File

@ -35,7 +35,6 @@ import org.dolphinemu.dolphinemu.emulation.EmulationActivity;
public final class GameListFragment extends ListFragment
{
private GameListAdapter mGameAdapter;
private static GameListActivity mMe;
private OnGameListZeroListener mCallback;
/**
@ -84,7 +83,7 @@ public final class GameListFragment extends ListFragment
if (!entry.isHidden() && !entry.isDirectory())
{
if (exts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
fls.add(new GameListItem(mMe, entryName, String.format(getString(R.string.file_size), entry.length()), entry.getAbsolutePath()));
fls.add(new GameListItem(getActivity(), entryName, String.format(getString(R.string.file_size), entry.length()), entry.getAbsolutePath()));
}
}
}
@ -94,8 +93,9 @@ public final class GameListFragment extends ListFragment
}
Collections.sort(fls);
mGameAdapter = new GameListAdapter(mMe, R.layout.gamelist_folderbrowser_list_item, fls);
setListAdapter(mGameAdapter);
// Add all the items to the adapter
mGameAdapter.addAll(fls);
mGameAdapter.notifyDataSetChanged();
if (fls.isEmpty())
{
@ -106,12 +106,13 @@ public final class GameListFragment extends ListFragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.gamelist_listview, container, false);
ListView mMainList = (ListView) rootView.findViewById(R.id.gamelist);
ListView rootView = (ListView) inflater.inflate(R.layout.gamelist_listview, container, false);
mGameAdapter = new GameListAdapter(getActivity(), R.layout.gamelist_folderbrowser_list_item);
rootView.setAdapter(mGameAdapter);
Fill();
return mMainList;
return rootView;
}
@Override
@ -120,12 +121,12 @@ public final class GameListFragment extends ListFragment
GameListItem item = mGameAdapter.getItem(position);
// Show a toast indicating which game was clicked.
Toast.makeText(mMe, String.format(getString(R.string.file_clicked), item.getPath()), Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), String.format(getString(R.string.file_clicked), item.getPath()), Toast.LENGTH_SHORT).show();
// Start the emulation activity and send the path of the clicked ROM to it.
Intent intent = new Intent(mMe, EmulationActivity.class);
Intent intent = new Intent(getActivity(), EmulationActivity.class);
intent.putExtra("SelectedGame", item.getPath());
mMe.startActivity(intent);
startActivity(intent);
}
@Override
@ -138,7 +139,6 @@ public final class GameListFragment extends ListFragment
try
{
mCallback = (OnGameListZeroListener) activity;
mMe = (GameListActivity) activity;
}
catch (ClassCastException e)
{