Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Like the previous commit (but for the GameListFragment), do…
…n't constantly create a new adapter when filling the game list.
  • Loading branch information
lioncash committed Nov 16, 2013
1 parent d98664b commit 11a1566
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
Expand Up @@ -12,11 +12,8 @@
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;

/**
Expand All @@ -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
Expand All @@ -61,7 +49,7 @@ public View getView(int position, View convertView, ViewGroup parent)
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);
Expand Down
Expand Up @@ -35,7 +35,6 @@
public final class GameListFragment extends ListFragment
{
private GameListAdapter mGameAdapter;
private static GameListActivity mMe;
private OnGameListZeroListener mCallback;

/**
Expand Down Expand Up @@ -84,7 +83,7 @@ private void Fill()
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()));
}
}
}
Expand All @@ -94,8 +93,9 @@ private void Fill()
}
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())
{
Expand All @@ -106,12 +106,13 @@ private void Fill()
@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
Expand All @@ -120,12 +121,12 @@ public void onListItemClick(ListView listView, View view, int position, long id)
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
Expand All @@ -138,7 +139,6 @@ public void onAttach(Activity activity)
try
{
mCallback = (OnGameListZeroListener) activity;
mMe = (GameListActivity) activity;
}
catch (ClassCastException e)
{
Expand Down

0 comments on commit 11a1566

Please sign in to comment.