From 52a4ef8cfaf8a4e41051e5eef0185a844fd9dccf Mon Sep 17 00:00:00 2001 From: Gregor Santner Date: Tue, 15 Oct 2024 01:51:59 +0200 Subject: [PATCH] Rework /storage mapped folders --- .../filebrowser/GsFileBrowserListAdapter.java | 45 ++++++++++--------- build.gradle | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java index 080410525..039b4fddb 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java @@ -70,7 +70,7 @@ public class GsFileBrowserListAdapter extends RecyclerView.Adapter getVirtualFolders() { } for (final File file : ContextCompat.getExternalFilesDirs(_context, null)) { - final File remap = new File(VIRTUAL_STORAGE_ROOT, "appdata-public (" + file.getName() + ")"); + //noinspection DataFlowIssue + final File remap = new File(VIRTUAL_STORAGE_ROOT, "AppData (" + file.getParentFile().toString().replace("/", "-").substring(1) + ")"); map.put(remap, file); } - for (final Pair p : cu.getAppDataPublicDirs(_context, false, true, false)) { - final File remap = new File(VIRTUAL_STORAGE_ROOT, "sdcard (" + p.second + ")"); - map.put(remap, p.first); - } - map.put(VIRTUAL_STORAGE_RECENTS, VIRTUAL_STORAGE_RECENTS); map.put(VIRTUAL_STORAGE_POPULAR, VIRTUAL_STORAGE_POPULAR); map.put(VIRTUAL_STORAGE_FAVOURITE, VIRTUAL_STORAGE_FAVOURITE); - map.put(VIRTUAL_STORAGE_EMULATED, VIRTUAL_STORAGE_EMULATED); return map; } @@ -211,7 +206,7 @@ public void onBindViewHolder(@NonNull FilesystemViewerViewHolder holder, int pos if (isCurrentFolderVirtual() && "index.html".equals(filename)) { titleText += " [" + currentFolderName + "]"; } - if (currentFolderName.equals("storage") && _dopt.storageMaps.containsValue(displayFile)){ + if (currentFolderName.equals("storage") && _dopt.storageMaps.containsValue(displayFile)) { titleText = GsCollectionUtils.reverse(_dopt.storageMaps).get(displayFile).getName(); } @@ -695,11 +690,28 @@ private void loadFolder(final File folder, final File show) { // This function is not called on the main thread, so post to the UI thread private synchronized void _loadFolder(final @NonNull File folder, final @Nullable File toShow) { - final boolean folderChanged = !folder.equals(_currentFolder); - final List newData = new ArrayList<>(); + // Make sure /storage/emulated/0 is browsable, even though filesystem says it's not accessible + if (folder.equals(new File("/"))) { + newData.add(VIRTUAL_STORAGE_ROOT); + } else if (folder.equals(VIRTUAL_STORAGE_ROOT)) { + newData.add(VIRTUAL_STORAGE_EMULATED); + + // SD Card and other external storage directories that are also not listable + for (final Pair p : GsContextUtils.instance.getAppDataPublicDirs(_context, false, true, false)) { + File f = p.first; + while (f.getParentFile() != null && !f.getParentFile().getName().equals("storage")) { + f = f.getParentFile(); + } + newData.add(f); + } + } else if (folder.equals(VIRTUAL_STORAGE_EMULATED)) { + newData.add(new File(folder, "0")); + } + + if (folder.equals(VIRTUAL_STORAGE_RECENTS)) { newData.addAll(_dopt.recentFiles); } else if (folder.equals(VIRTUAL_STORAGE_POPULAR)) { @@ -715,17 +727,6 @@ private synchronized void _loadFolder(final @NonNull File folder, final @Nullabl newData.addAll(_virtualMapping.keySet()); } - // Add all emulated folders under /storage/emulated - if (VIRTUAL_STORAGE_EMULATED.equals(folder)) { - newData.add(new File(folder, "0")); - for (int i = 1; i < 10; i++) { - final File f = new File(folder, String.valueOf(i)); - if (GsFileUtils.canCreate(f)) { - newData.add(f); - } - } - } - if (folder.getAbsolutePath().equals("/")) { newData.add(new File(folder, VIRTUAL_STORAGE_ROOT.getName())); } diff --git a/build.gradle b/build.gradle index 739a75558..00b50ceb0 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ import java.text.SimpleDateFormat buildscript { ext { - version_gradle_tools = '8.5.1' + version_gradle_tools = '8.6.0' version_plugin_kotlin = "1.3.72" enable_plugin_kotlin = false