Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Make the FolderBrowser extend a ListFragment instead of a r…
…egular 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.
  • Loading branch information
lioncash committed Sep 19, 2013
1 parent 85f0677 commit 49fff79
Showing 1 changed file with 23 additions and 27 deletions.
Expand Up @@ -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;
Expand All @@ -36,12 +35,12 @@
* 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.
Expand Down Expand Up @@ -94,9 +93,23 @@ else if (entry.isFile() && hasExtension)
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
Expand All @@ -105,29 +118,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
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)
{
Expand Down

0 comments on commit 49fff79

Please sign in to comment.