Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
lioncash committed Nov 16, 2013
1 parent c8ddc70 commit d98664b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -37,16 +36,18 @@
*/
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>();
Expand Down Expand Up @@ -96,9 +97,9 @@ else if (entry.isFile() && hasExtension)
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
Expand All @@ -122,22 +123,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
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;
}

@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);

// Cache the activity instance.
m_activity = activity;
return rootView;
}


private void FolderSelected()
{
String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPathes", "0");
Expand Down Expand Up @@ -168,6 +161,6 @@ private void FolderSelected()
NativeLibrary.SetConfig("Dolphin.ini", "General", "GCMPath" + Integer.toString(intDirectories), currentDir.getPath());
}

((GameListActivity)m_activity).SwitchPage(0);
((GameListActivity)getActivity()).SwitchPage(0);
}
}
Expand Up @@ -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;
Expand All @@ -40,29 +37,20 @@ public final class FolderBrowserAdapter extends ArrayAdapter<FolderBrowserItem>

private final Context context;
private final int id;
private final List<FolderBrowserItem> items;
private ViewHolder viewHolder;

/**
* Constructor
*
* @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
Expand All @@ -85,7 +73,7 @@ public View getView(int position, View convertView, ViewGroup parent)
viewHolder = (ViewHolder) convertView.getTag();
}

final FolderBrowserItem item = items.get(position);
final FolderBrowserItem item = getItem(position);
if (item != null)
{
if (viewHolder.title != null)
Expand Down

0 comments on commit d98664b

Please sign in to comment.