[Android] Make the FolderBrowser extend a ListFragment instead of a regular fragment. Lets us get rid of the need for an AdapterView.OnItemClickListener when handling list item clicks. Simplifies the implementation of the FolderBrowser a tiny bit.

This commit is contained in:
Lioncash 2013-09-18 22:17:23 -04:00
parent 85f067780a
commit 49fff7979b

View File

@ -7,14 +7,13 @@
package org.dolphinemu.dolphinemu.folderbrowser; package org.dolphinemu.dolphinemu.folderbrowser;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.ListFragment;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import java.io.File; import java.io.File;
@ -36,12 +35,12 @@ import org.dolphinemu.dolphinemu.gamelist.GameListActivity;
* Note that this file browser does not display files * Note that this file browser does not display files
* or directories that are hidden * or directories that are hidden
*/ */
public final class FolderBrowser extends Fragment public final class FolderBrowser extends ListFragment
{ {
private Activity m_activity; private Activity m_activity;
private FolderBrowserAdapter adapter; private FolderBrowserAdapter adapter;
private ListView mDrawerList; private ListView mFolderBrowserList;
private View rootView; private ListView rootView;
private static File currentDir = null; private static File currentDir = null;
// Populates the FolderView with the given currDir's contents. // Populates the FolderView with the given currDir's contents.
@ -94,26 +93,12 @@ public final class FolderBrowser extends Fragment
dir.add(0, new FolderBrowserItem("..", getString(R.string.parent_directory), currDir.getParent())); dir.add(0, new FolderBrowserItem("..", getString(R.string.parent_directory), currDir.getParent()));
adapter = new FolderBrowserAdapter(m_activity, R.layout.gamelist_folderbrowser_list, dir); adapter = new FolderBrowserAdapter(m_activity, R.layout.gamelist_folderbrowser_list, dir);
mDrawerList = (ListView) rootView.findViewById(R.id.gamelist); mFolderBrowserList = (ListView) rootView.findViewById(R.id.gamelist);
mDrawerList.setAdapter(adapter); mFolderBrowserList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(mMenuItemClickListener);
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) public void onListItemClick(ListView lv, View v, int position, long id)
{
if(currentDir == null)
currentDir = new File(Environment.getExternalStorageDirectory().getPath());
rootView = inflater.inflate(R.layout.gamelist_listview, container, false);
Fill(currentDir);
return mDrawerList;
}
private final AdapterView.OnItemClickListener mMenuItemClickListener = new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{ {
FolderBrowserItem item = adapter.getItem(position); FolderBrowserItem item = adapter.getItem(position);
if(item.isDirectory()) if(item.isDirectory())
@ -126,7 +111,18 @@ public final class FolderBrowser extends Fragment
FolderSelected(); FolderSelected();
} }
} }
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if(currentDir == null)
currentDir = new File(Environment.getExternalStorageDirectory().getPath());
rootView = (ListView) inflater.inflate(R.layout.gamelist_listview, container, false);
Fill(currentDir);
return mFolderBrowserList;
}
@Override @Override
public void onAttach(Activity activity) public void onAttach(Activity activity)