diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/FileSystemAdapter.java b/app/src/main/java/ch/blinkenlights/android/vanilla/FileSystemAdapter.java index b4ecf5cf2..28d2b01b1 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/FileSystemAdapter.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/FileSystemAdapter.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.Intent; +import android.os.Environment; import android.os.FileObserver; import android.view.LayoutInflater; import android.view.View; @@ -197,6 +198,29 @@ public Object query() ArrayList files = new ArrayList(Arrays.asList(readdir)); Collections.sort(files, mFileComparator); + + // Hack alert: On Android >. 6.0, some of the parent directories + // of the external storage may not be readable, meaning that if + // the user browses up the tree, they may suddenly not have the + // option to go back. Think of going from /storage/emulated/0 to + // /storage/emulated and not seeing the 0 option anymore. + if (files.isEmpty()) { + File possibleChild = Environment.getExternalStorageDirectory(); + while (true) { + File possibleParent = possibleChild.getParentFile(); + if (possibleParent == null) { + break; + } + + if (possibleParent.equals(file)) { + files.add(possibleChild); + break; + } + + possibleChild = possibleChild.getParentFile(); + } + } + if (!mFsRoot.equals(file)) files.add(0, new File(file, FileUtils.NAME_PARENT_FOLDER)); @@ -343,6 +367,7 @@ public static Limiter buildLimiter(File file) { if (pointsToParentFolder(file)) file = file.getParentFile().getParentFile(); + String[] fields = FILE_SEPARATOR.split(file.getPath().substring(1)); return new Limiter(MediaUtils.TYPE_FILE, fields, file); } diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/FolderPickerAdapter.java b/app/src/main/java/ch/blinkenlights/android/vanilla/FolderPickerAdapter.java index 2992e8ce2..656b22531 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/FolderPickerAdapter.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/FolderPickerAdapter.java @@ -18,16 +18,11 @@ package ch.blinkenlights.android.vanilla; import android.content.Context; -import android.app.Activity; import android.os.Environment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.LayoutInflater; import android.widget.ArrayAdapter; -import android.widget.TextView; -import android.widget.ImageView; -import android.graphics.drawable.Drawable; import java.io.File; import java.util.Arrays; @@ -183,13 +178,26 @@ private void refresh() { if (!mFsRoot.equals(path)) add(new FolderPickerAdapter.Item("..", null, 0)); - // Hack alert: Android >= 6.0's default storage root directory - // is usually not readable. That's not a big issue but - // can be very annoying for users who browse around. - // We are therefore detecting this and will 'simulate' - // the existence of the default storage root. - if (dirs == null && mStorageDir.getParentFile().equals(path)) { - dirs = new File[] { mStorageDir }; + // Hack alert: On Android >. 6.0, some of the parent directories + // of the external storage may not be readable, meaning that if + // the user browses up the tree, they may suddenly not have the + // option to go back. Think of going from /storage/emulated/0 to + // /storage/emulated and not seeing the 0 option anymore. + if (dirs == null) { + File possibleChild = mStorageDir; + while (true) { + File possibleParent = possibleChild.getParentFile(); + if (possibleParent == null) { + break; + } + + if (possibleParent.equals(path)) { + dirs = new File[] { possibleChild }; + break; + } + + possibleChild = possibleChild.getParentFile(); + } } if (dirs != null) {