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