package com.nononsenseapps.filepicker;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;

/**
 * Some utility methods
 */
public class Utils {

    private static final String SEP = "/";

    /**
     * Name is validated to be non-null, non-empty and not containing any
     * slashes.
     *
     * @param name The name of the folder the user wishes to create.
     */
    public static boolean isValidFileName(@Nullable String name) {
        return !TextUtils.isEmpty(name)
                && !name.contains("/")
                && !name.equals(".")
                && !name.equals("..");
    }

    /**
     * Append the second pathString to the first. The result will not end with a /.
     * In case two absolute paths are given, e.g. /A/B/, and /C/D/, then the result
     * will be /A/B/C/D
     *
     * Multiple slashes will be shortened to a single slash, so /A///B is equivalent to /A/B
     */
    @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;
        }
    }
}

@@ -33,16 +33,40 @@
 icker;%0A%0A
+import android.net.Uri;%0A
 import a
@@ -100,16 +100,16 @@
 onNull;%0A
-
 import a
@@ -176,16 +176,66 @@
 Utils;%0A%0A
+import java.io.File;%0Aimport java.io.IOException;%0A%0A
 /**%0A * S
@@ -1490,16 +1490,16 @@
 result;%0A
-
         
@@ -1505,11 +1505,2031 @@
  %7D%0A    %7D
+%0A%0A    /**%0A     * Convert a uri generated by a fileprovider, like content://AUTHORITY/ROOT/actual/path%0A     * to a file pointing to file:///actual/path%0A     *%0A     * Note that it only works for paths generated with %60ROOT%60 as the path element. This is done if%0A     * nnf_provider_paths.xml is used to define the file provider in the manifest.%0A     *%0A     * @param uri generated from a file provider%0A     * @return Corresponding %7B@link File%7D object%0A     */%0A    @NonNull%0A    public static File getFileForUri(@NonNull Uri uri) %7B%0A        return getFileForUriString(uri.getEncodedPath());%0A    %7D%0A%0A    /**%0A     * Convert a uri generated by a fileprovider, like content://AUTHORITY/ROOT/actual/path%0A     * to a file pointing to file:///actual/path%0A     *%0A     * Note that it only works for paths generated with %60ROOT%60 as the path element. This is done if%0A     * nnf_provider_paths.xml is used to define the file provider in the manifest.%0A     *%0A     * @param path string decoded from a URI provided by a FileProvider%0A     * @return Corresponding %7B@link File%7D object%0A     */%0A    @NonNull%0A    public static File getFileForUriString(@NonNull String path) %7B%0A        final int splitIndex = path.indexOf('/', 1);%0A        final String tag = Uri.decode(path.substring(1, splitIndex));%0A        path = Uri.decode(path.substring(splitIndex + 1));%0A%0A        if (!%22root%22.equalsIgnoreCase(tag)) %7B%0A            throw new IllegalArgumentException(%0A                    String.format(%22Can't decode paths to '%25s', only for 'root' paths.%22,%0A                            tag));%0A        %7D%0A%0A        final File root = new File(%22/%22);%0A%0A        File file = new File(root, path);%0A        try %7B%0A            file = file.getCanonicalFile();%0A        %7D catch (IOException e) %7B%0A            throw new IllegalArgumentException(%22Failed to resolve canonical path for %22 + file);%0A        %7D%0A%0A        if (!file.getPath().startsWith(root.getPath())) %7B%0A            throw new SecurityException(%22Resolved path jumped beyond configured root%22);%0A        %7D%0A%0A        return file;%0A    %7D
 %0A%7D%0A

Add utility method `getFileFromUri` to `Utils`