// Path: java/src/main/java/org/astonbitecode/rustkeylock/adapters/DirectoriesAdapter.java
// public class DirectoriesAdapter extends ArrayAdapter<DirectorySelector.DirectoryEntry> {
//     private List<DirectorySelector.DirectoryEntry> entries;
//     private Context context;
//     private int layoutResourceId;
// 
//     public DirectoriesAdapter(Context context, int resourceId, List<DirectorySelector.DirectoryEntry> entries) {
//         super(context, resourceId, entries);
//         this.entries = entries;
//         this.context = context;
//         this.layoutResourceId = resourceId;
//     }
// 
//     public View getView(int position, View convertView, ViewGroup parent) {
//         View v = convertView;
// 
//         if (v == null) {
//             LayoutInflater inflater = ((Activity) context).getLayoutInflater();
//             v = inflater.inflate(layoutResourceId, parent, false);
//         }
// 
//         DirectorySelector.DirectoryEntry i = entries.get(position);
// 
//         if (i != null) {
//             TextView tvn = (TextView) v.findViewById(R.id.directoryname);
// 
//             if (tvn != null) {
//                 tvn.setText(i.getName());
//             }
//         }
//         return v;
//     }
// }
// 
// Path: java/src/main/java/org/astonbitecode/rustkeylock/handlers/back/BackButtonHandler.java
// public interface BackButtonHandler extends Serializable {
//     void onBackButton();
// }


import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import org.astonbitecode.rustkeylock.R;
import org.astonbitecode.rustkeylock.adapters.DirectoriesAdapter;
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
import android.app.ListFragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
// Copyright 2017 astonbitecode
// This file is part of rust-keylock password manager.
//
// rust-keylock is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// rust-keylock is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with rust-keylock.  If not, see <http://www.gnu.org/licenses/>.
package org.astonbitecode.rustkeylock.fragments;




public class DirectorySelector extends ListFragment implements OnClickListener, BackButtonHandler {
    private static final long serialVersionUID = 1382314701594691684L;
    private final String TAG = getClass().getName();
    private final String PARENT_IDENTIFIER = "..";
    private final String CURR_DIR_PREFIX = "Current directory: ";

    private DirectoriesAdapter directoriesAdapter;
    private File currentDirectory;
    private TextView currentDirectoryTextView;

    public DirectorySelector() {
        File downloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        currentDirectory = downloads;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_directory_selector, container, false);
        Button sdb = (Button) rootView.findViewById(R.id.selectDirectoryButton);
        sdb.setOnClickListener(this);
        TextView cdtv = (TextView) rootView.findViewById(R.id.directorySelectorCurrent);
        currentDirectoryTextView = cdtv;

        // Hide the soft keyboard
        final InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(rootView.getWindowToken(), 0);

        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
// Path: java/src/main/java/org/astonbitecode/rustkeylock/adapters/DirectoriesAdapter.java
// public class DirectoriesAdapter extends ArrayAdapter<DirectorySelector.DirectoryEntry> {
//     private List<DirectorySelector.DirectoryEntry> entries;
//     private Context context;
//     private int layoutResourceId;
// 
//     public DirectoriesAdapter(Context context, int resourceId, List<DirectorySelector.DirectoryEntry> entries) {
//         super(context, resourceId, entries);
//         this.entries = entries;
//         this.context = context;
//         this.layoutResourceId = resourceId;
//     }
// 
//     public View getView(int position, View convertView, ViewGroup parent) {
//         View v = convertView;
// 
//         if (v == null) {
//             LayoutInflater inflater = ((Activity) context).getLayoutInflater();
//             v = inflater.inflate(layoutResourceId, parent, false);
//         }
// 
//         DirectorySelector.DirectoryEntry i = entries.get(position);
// 
//         if (i != null) {
//             TextView tvn = (TextView) v.findViewById(R.id.directoryname);
// 
//             if (tvn != null) {
//                 tvn.setText(i.getName());
//             }
//         }
//         return v;
//     }
// }
// 
// Path: java/src/main/java/org/astonbitecode/rustkeylock/handlers/back/BackButtonHandler.java
// public interface BackButtonHandler extends Serializable {
//     void onBackButton();
// }


// Path: java/src/main/java/org/astonbitecode/rustkeylock/fragments/DirectorySelector.java
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import org.astonbitecode.rustkeylock.R;
import org.astonbitecode.rustkeylock.adapters.DirectoriesAdapter;
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
import android.app.ListFragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

// Copyright 2017 astonbitecode
// This file is part of rust-keylock password manager.
//
// rust-keylock is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// rust-keylock is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with rust-keylock.  If not, see <http://www.gnu.org/licenses/>.
package org.astonbitecode.rustkeylock.fragments;




public class DirectorySelector extends ListFragment implements OnClickListener, BackButtonHandler {
    private static final long serialVersionUID = 1382314701594691684L;
    private final String TAG = getClass().getName();
    private final String PARENT_IDENTIFIER = "..";
    private final String CURR_DIR_PREFIX = "Current directory: ";

    private DirectoriesAdapter directoriesAdapter;
    private File currentDirectory;
    private TextView currentDirectoryTextView;

    public DirectorySelector() {
        File downloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        currentDirectory = downloads;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_directory_selector, container, false);
        Button sdb = (Button) rootView.findViewById(R.id.selectDirectoryButton);
        sdb.setOnClickListener(this);
        TextView cdtv = (TextView) rootView.findViewById(R.id.directorySelectorCurrent);
        currentDirectoryTextView = cdtv;

        // Hide the soft keyboard
        final InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(rootView.getWindowToken(), 0);

        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        directoriesAdapter = new DirectoriesAdapter(getActivity(), R.layout.directory_element,