Browse Source

fix(android): handle home uri when picking folder

Andelf 3 years ago
parent
commit
471b52b985
1 changed files with 10 additions and 5 deletions
  1. 10 5
      android/app/src/main/java/com/logseq/app/FileUtil.java

+ 10 - 5
android/app/src/main/java/com/logseq/app/FileUtil.java

@@ -14,8 +14,10 @@ import android.util.Log;
 
 
 import java.io.File;
 import java.io.File;
 
 
+// The following refs
 // https://stackoverflow.com/questions/29713587/how-to-get-the-real-path-with-action-open-document-tree-intent
 // https://stackoverflow.com/questions/29713587/how-to-get-the-real-path-with-action-open-document-tree-intent
 // https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
 // https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
+// with bug fixes and patches.
 public class FileUtil {
 public class FileUtil {
     @TargetApi(Build.VERSION_CODES.KITKAT)
     @TargetApi(Build.VERSION_CODES.KITKAT)
     public static String getPath(final Context context, final Uri uri) {
     public static String getPath(final Context context, final Uri uri) {
@@ -29,17 +31,20 @@ public class FileUtil {
                 final String docId = DocumentsContract.getDocumentId(uri);
                 final String docId = DocumentsContract.getDocumentId(uri);
                 final String[] split = docId.split(":");
                 final String[] split = docId.split(":");
                 final String type = split[0];
                 final String type = split[0];
-
-                if ("primary".equalsIgnoreCase(type)) {
-                    return Environment.getExternalStorageDirectory() + "/" + split[1];
-                }
-
                 // NOTE: It's not a good idea to use storage root as Graph root.
                 // NOTE: It's not a good idea to use storage root as Graph root.
                 String remain = "";
                 String remain = "";
                 if (split.length == 2) {
                 if (split.length == 2) {
                     remain = split[1];
                     remain = split[1];
                 }
                 }
 
 
+                if ("primary".equalsIgnoreCase(type)) {
+                    return Environment.getExternalStorageDirectory() + "/" + remain;
+                } else if ("home".equalsIgnoreCase(type)) {
+                    return Environment.getExternalStorageDirectory() + "/Documents/" + remain;
+                } else if ("downloads".equalsIgnoreCase(type)) {
+                    return Environment.getExternalStorageDirectory() + "/Download/" + remain; // No 's' here
+                }
+
                 File dir = null;
                 File dir = null;
                 File[] mdirs = context.getExternalMediaDirs();
                 File[] mdirs = context.getExternalMediaDirs();
                 for (File mdir : mdirs) {
                 for (File mdir : mdirs) {