// Path: library/src/main/java/com/nononsenseapps/filepicker/Utils.java
// @NonNull
// public static String appendPath(@NonNull String first,
//                                 @NonNull String second) {
//     String result = first + SEP + second;
// 
//     while (result.contains("//")) {
//         result = result.replaceAll("//", "/");
//     }
// 
//     if (result.length() > 1 && result.endsWith(SEP)) {
//         return result.substring(0, result.length() - 1);
//     } else {
//         return result;
//     }
// }


import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.util.SortedList;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import static com.nononsenseapps.filepicker.Utils.appendPath;
        if (mListener == null) {
            return;
        }

        // Some invalid cases first
        /*if (MODE_NEW_FILE == mode && !isValidFileName(getNewFileName())) {
            mToast = Toast.makeText(getActivity(), R.string.nnf_need_valid_filename,
                    Toast.LENGTH_SHORT);
            mToast.show();
            return;
        }*/
        if ((allowMultiple || mode == MODE_FILE) &&
                (mCheckedItems.isEmpty() || getFirstCheckedItem() == null)) {
            if (mToast == null) {
                mToast = Toast.makeText(getActivity(), R.string.nnf_select_something_first,
                        Toast.LENGTH_SHORT);
            }
            mToast.show();
            return;
        }

        // New file allows only a single file
        if (mode == MODE_NEW_FILE) {
            final String filename = getNewFileName();
            final Uri result;
            if (filename.startsWith("/")) {
                // Return absolute paths directly
                result = toUri(getPath(filename));
            } else {
                // Append to current directory
// Path: library/src/main/java/com/nononsenseapps/filepicker/Utils.java
// @NonNull
// public static String appendPath(@NonNull String first,
//                                 @NonNull String second) {
//     String result = first + SEP + second;
// 
//     while (result.contains("//")) {
//         result = result.replaceAll("//", "/");
//     }
// 
//     if (result.length() > 1 && result.endsWith(SEP)) {
//         return result.substring(0, result.length() - 1);
//     } else {
//         return result;
//     }
// }


// Path: library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.util.SortedList;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import static com.nononsenseapps.filepicker.Utils.appendPath;

        if (mListener == null) {
            return;
        }

        // Some invalid cases first
        /*if (MODE_NEW_FILE == mode && !isValidFileName(getNewFileName())) {
            mToast = Toast.makeText(getActivity(), R.string.nnf_need_valid_filename,
                    Toast.LENGTH_SHORT);
            mToast.show();
            return;
        }*/
        if ((allowMultiple || mode == MODE_FILE) &&
                (mCheckedItems.isEmpty() || getFirstCheckedItem() == null)) {
            if (mToast == null) {
                mToast = Toast.makeText(getActivity(), R.string.nnf_select_something_first,
                        Toast.LENGTH_SHORT);
            }
            mToast.show();
            return;
        }

        // New file allows only a single file
        if (mode == MODE_NEW_FILE) {
            final String filename = getNewFileName();
            final Uri result;
            if (filename.startsWith("/")) {
                // Return absolute paths directly
                result = toUri(getPath(filename));
            } else {
                // Append to current directory
                result = toUri(getPath(appendPath(getFullPath(mCurrentPath), filename)));