Skip to content

Commit

Permalink
Rework /storage mapped folders
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Oct 14, 2024
1 parent b282167 commit 52a4ef8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class GsFileBrowserListAdapter extends RecyclerView.Adapter<GsFileBrowser
public static final File VIRTUAL_STORAGE_RECENTS = new File(VIRTUAL_STORAGE_ROOT, "Recent");
public static final File VIRTUAL_STORAGE_FAVOURITE = new File(VIRTUAL_STORAGE_ROOT, "Favourites");
public static final File VIRTUAL_STORAGE_POPULAR = new File(VIRTUAL_STORAGE_ROOT, "Popular");
public static final File VIRTUAL_STORAGE_APP_DATA_PRIVATE = new File(VIRTUAL_STORAGE_ROOT, "appdata-private");
public static final File VIRTUAL_STORAGE_APP_DATA_PRIVATE = new File(VIRTUAL_STORAGE_ROOT, "AppData (data partition)");
private static final File GO_BACK_SIGNIFIER = new File("__GO_BACK__");
private static final StrikethroughSpan STRIKE_THROUGH_SPAN = new StrikethroughSpan();
public static final String EXTRA_CURRENT_FOLDER = "EXTRA_CURRENT_FOLDER";
Expand Down Expand Up @@ -151,19 +151,14 @@ public Map<File, File> 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<File, String> 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;
}
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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<File> 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<File, String> 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)) {
Expand All @@ -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()));
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 52a4ef8

Please sign in to comment.