package net.nitroshare.android.explorer;

import android.app.ListFragment;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.ListView;

import java.io.File;
import java.util.ArrayList;

/**
 * Display the contents of a directory
 */
public class ExplorerFragment extends ListFragment {

    static final String DIRECTORY = "directory";

    interface Listener {
        void onBrowseDirectory(String directory);
        void onSendUris(ArrayList<Uri> uris);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String directory = null;
        if (getArguments() != null) {
            directory = getArguments().getString(DIRECTORY);
        }
        if (directory == null) {
            directory = Environment.getExternalStorageDirectory().getPath();
        }
        setListAdapter(new DirectoryAdapter(directory, getActivity()));
    }

    @Override
    public void onListItemClick(ListView listView, View view, int position, long id) {
        Listener listener = (Listener) getActivity();
        File file = (File) getListAdapter().getItem(position);
        if (file.isDirectory()) {
            listener.onBrowseDirectory(file.getPath());
        } else {
            ArrayList<Uri> uris = new ArrayList<>();
            uris.add(Uri.fromFile(file));
            listener.onSendUris(uris);
        }
    }
}

@@ -175,16 +175,51 @@
 w.View;%0A
+import android.widget.AdapterView;%0A
 import a
@@ -242,16 +242,16 @@
 stView;%0A
-
 %0Aimport 
@@ -564,32 +564,65 @@
 %3E uris);%0A    %7D%0A%0A
+    private Listener mListener;%0A%0A
     @Override%0A  
@@ -1055,24 +1055,883 @@
 )));%0A    %7D%0A%0A
+    @Override%0A    public void onActivityCreated(Bundle savedInstanceState) %7B%0A        super.onActivityCreated(savedInstanceState);%0A%0A        mListener = (Listener) getActivity();%0A%0A        // Watch for long presses on directories%0A        getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() %7B%0A            @Override%0A            public boolean onItemLongClick(AdapterView%3C?%3E parent, View view, int position, long id) %7B%0A                File file = (File) getListAdapter().getItem(position);%0A                if (file.isDirectory()) %7B%0A                    ArrayList%3CUri%3E uris = new ArrayList%3C%3E();%0A                    uris.add(Uri.fromFile(file));%0A                    mListener.onSendUris(uris);%0A                    return true;%0A                %7D else %7B%0A                    return false;%0A                %7D%0A            %7D%0A        %7D);%0A    %7D%0A%0A
     @Overrid
@@ -2023,62 +2023,8 @@
 ) %7B%0A
-        Listener listener = (Listener) getActivity();%0A
     
@@ -2120,33 +2120,34 @@
 ) %7B%0A            
-l
+mL
 istener.onBrowse
@@ -2297,17 +2297,18 @@
         
-l
+mL
 istener.

Add ability to transfer directories (fixes #3).