[Android] Simplify the FolderBrowserAdapter a little, as well as the Fill method within FolderBrowser.java. Previously the fill method would create an entire new adapter and assign it to the backing ListView. This is pretty unnecessary, so what it now does is, when the function is called, it clears out the adapter, then simply fills it in again with the new directory's contents. Simple, and doesn't require a reference to the actual ListView to be used.
This commit is contained in:
parent
c8ddc70c97
commit
d98664b053
|
@ -6,7 +6,6 @@
|
|||
|
||||
package org.dolphinemu.dolphinemu.folderbrowser;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ListFragment;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
@ -37,16 +36,18 @@ import org.dolphinemu.dolphinemu.gamelist.GameListActivity;
|
|||
*/
|
||||
public final class FolderBrowser extends ListFragment
|
||||
{
|
||||
private Activity m_activity;
|
||||
private FolderBrowserAdapter adapter;
|
||||
private ListView mFolderBrowserList;
|
||||
private ListView rootView;
|
||||
private static File currentDir = null;
|
||||
|
||||
// Populates the FolderView with the given currDir's contents.
|
||||
private void Fill(File currDir)
|
||||
{
|
||||
m_activity.setTitle(String.format(getString(R.string.current_dir), currDir.getName()));
|
||||
// Clear the adapter of previous items.
|
||||
adapter.clear();
|
||||
|
||||
// Set the activity title to the current directory the FolderBrowser is in.
|
||||
getActivity().setTitle(String.format(getString(R.string.current_dir), currDir.getName()));
|
||||
|
||||
File[] dirs = currDir.listFiles();
|
||||
List<FolderBrowserItem> dir = new ArrayList<FolderBrowserItem>();
|
||||
List<FolderBrowserItem> fls = new ArrayList<FolderBrowserItem>();
|
||||
|
@ -96,9 +97,9 @@ public final class FolderBrowser extends ListFragment
|
|||
if (!currDir.getPath().equalsIgnoreCase("/"))
|
||||
dir.add(0, new FolderBrowserItem("..", getString(R.string.parent_directory), currDir.getParent()));
|
||||
|
||||
adapter = new FolderBrowserAdapter(m_activity, R.layout.gamelist_folderbrowser_list_item, dir);
|
||||
mFolderBrowserList = (ListView) rootView.findViewById(R.id.gamelist);
|
||||
mFolderBrowserList.setAdapter(adapter);
|
||||
// Add the items to the adapter and notify the adapter users of its new contents.
|
||||
adapter.addAll(dir);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,22 +123,14 @@ public final class FolderBrowser extends ListFragment
|
|||
if(currentDir == null)
|
||||
currentDir = new File(Environment.getExternalStorageDirectory().getPath());
|
||||
|
||||
rootView = (ListView) inflater.inflate(R.layout.gamelist_listview, container, false);
|
||||
ListView rootView = (ListView) inflater.inflate(R.layout.gamelist_listview, container, false);
|
||||
adapter = new FolderBrowserAdapter(getActivity(), R.layout.gamelist_folderbrowser_list_item);
|
||||
rootView.setAdapter(adapter);
|
||||
|
||||
Fill(currentDir);
|
||||
return mFolderBrowserList;
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity)
|
||||
{
|
||||
super.onAttach(activity);
|
||||
|
||||
// Cache the activity instance.
|
||||
m_activity = activity;
|
||||
}
|
||||
|
||||
|
||||
private void FolderSelected()
|
||||
{
|
||||
String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPathes", "0");
|
||||
|
@ -168,6 +161,6 @@ public final class FolderBrowser extends ListFragment
|
|||
NativeLibrary.SetConfig("Dolphin.ini", "General", "GCMPath" + Integer.toString(intDirectories), currentDir.getPath());
|
||||
}
|
||||
|
||||
((GameListActivity)m_activity).SwitchPage(0);
|
||||
((GameListActivity)getActivity()).SwitchPage(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
|
||||
package org.dolphinemu.dolphinemu.folderbrowser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
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 org.dolphinemu.dolphinemu.R;
|
||||
|
@ -40,7 +37,6 @@ public final class FolderBrowserAdapter extends ArrayAdapter<FolderBrowserItem>
|
|||
|
||||
private final Context context;
|
||||
private final int id;
|
||||
private final List<FolderBrowserItem> items;
|
||||
private ViewHolder viewHolder;
|
||||
|
||||
/**
|
||||
|
@ -48,21 +44,13 @@ public final class FolderBrowserAdapter extends ArrayAdapter<FolderBrowserItem>
|
|||
*
|
||||
* @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 FolderBrowserAdapter(Context context, int resourceId, List<FolderBrowserItem> objects)
|
||||
public FolderBrowserAdapter(Context context, int resourceId)
|
||||
{
|
||||
super(context, resourceId, objects);
|
||||
super(context, resourceId);
|
||||
|
||||
this.context = context;
|
||||
this.id = resourceId;
|
||||
this.items = objects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FolderBrowserItem getItem(int i)
|
||||
{
|
||||
return items.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,7 +73,7 @@ public final class FolderBrowserAdapter extends ArrayAdapter<FolderBrowserItem>
|
|||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
final FolderBrowserItem item = items.get(position);
|
||||
final FolderBrowserItem item = getItem(position);
|
||||
if (item != null)
|
||||
{
|
||||
if (viewHolder.title != null)
|
||||
|
|
Loading…
Reference in New Issue