mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-26 07:45:33 +01:00
[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:
parent
d98664b053
commit
11a156615f
@ -12,11 +12,8 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.dolphinemu.dolphinemu.R;
|
import org.dolphinemu.dolphinemu.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,28 +25,19 @@ public final class GameListAdapter extends ArrayAdapter<GameListItem>
|
|||||||
{
|
{
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final int id;
|
private final int id;
|
||||||
private final List<GameListItem>items;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param context The current {@link Context}.
|
* @param context The current {@link Context}.
|
||||||
* @param resourceId The resource ID for a layout file containing a layout to use when instantiating views.
|
* @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.context = context;
|
||||||
this.id = resourceId;
|
this.id = resourceId;
|
||||||
this.items = objects;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GameListItem getItem(int i)
|
|
||||||
{
|
|
||||||
return items.get(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,7 +49,7 @@ public final class GameListAdapter extends ArrayAdapter<GameListItem>
|
|||||||
convertView = vi.inflate(id, parent, false);
|
convertView = vi.inflate(id, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
final GameListItem item = items.get(position);
|
final GameListItem item = getItem(position);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
TextView title = (TextView) convertView.findViewById(R.id.ListItemTitle);
|
TextView title = (TextView) convertView.findViewById(R.id.ListItemTitle);
|
||||||
|
@ -35,7 +35,6 @@ import org.dolphinemu.dolphinemu.emulation.EmulationActivity;
|
|||||||
public final class GameListFragment extends ListFragment
|
public final class GameListFragment extends ListFragment
|
||||||
{
|
{
|
||||||
private GameListAdapter mGameAdapter;
|
private GameListAdapter mGameAdapter;
|
||||||
private static GameListActivity mMe;
|
|
||||||
private OnGameListZeroListener mCallback;
|
private OnGameListZeroListener mCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,7 +83,7 @@ public final class GameListFragment extends ListFragment
|
|||||||
if (!entry.isHidden() && !entry.isDirectory())
|
if (!entry.isHidden() && !entry.isDirectory())
|
||||||
{
|
{
|
||||||
if (exts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
|
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);
|
Collections.sort(fls);
|
||||||
|
|
||||||
mGameAdapter = new GameListAdapter(mMe, R.layout.gamelist_folderbrowser_list_item, fls);
|
// Add all the items to the adapter
|
||||||
setListAdapter(mGameAdapter);
|
mGameAdapter.addAll(fls);
|
||||||
|
mGameAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
if (fls.isEmpty())
|
if (fls.isEmpty())
|
||||||
{
|
{
|
||||||
@ -106,12 +106,13 @@ public final class GameListFragment extends ListFragment
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
View rootView = inflater.inflate(R.layout.gamelist_listview, container, false);
|
ListView rootView = (ListView) inflater.inflate(R.layout.gamelist_listview, container, false);
|
||||||
ListView mMainList = (ListView) rootView.findViewById(R.id.gamelist);
|
mGameAdapter = new GameListAdapter(getActivity(), R.layout.gamelist_folderbrowser_list_item);
|
||||||
|
rootView.setAdapter(mGameAdapter);
|
||||||
|
|
||||||
Fill();
|
Fill();
|
||||||
|
|
||||||
return mMainList;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -120,12 +121,12 @@ public final class GameListFragment extends ListFragment
|
|||||||
GameListItem item = mGameAdapter.getItem(position);
|
GameListItem item = mGameAdapter.getItem(position);
|
||||||
|
|
||||||
// Show a toast indicating which game was clicked.
|
// 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.
|
// 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());
|
intent.putExtra("SelectedGame", item.getPath());
|
||||||
mMe.startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -138,7 +139,6 @@ public final class GameListFragment extends ListFragment
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
mCallback = (OnGameListZeroListener) activity;
|
mCallback = (OnGameListZeroListener) activity;
|
||||||
mMe = (GameListActivity) activity;
|
|
||||||
}
|
}
|
||||||
catch (ClassCastException e)
|
catch (ClassCastException e)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user