Allow selecting external media dirs as data directory (#7400)
In addition to /sdcard/Android/data/de.danoeh.antennapod, this now enables /sdcard/Android/media/de.danoeh.antennapod. The folder is readable by other applications that have the "read storage" permission. At the same time, AntennaPod does not need the permission to write the folder.
This commit is contained in:
parent
f35e92c112
commit
2a1b537d13
|
@ -47,14 +47,14 @@ public class DataFolderAdapter extends RecyclerView.Adapter<DataFolderAdapter.Vi
|
||||||
String freeSpace = Formatter.formatShortFileSize(context, storagePath.getAvailableSpace());
|
String freeSpace = Formatter.formatShortFileSize(context, storagePath.getAvailableSpace());
|
||||||
String totalSpace = Formatter.formatShortFileSize(context, storagePath.getTotalSpace());
|
String totalSpace = Formatter.formatShortFileSize(context, storagePath.getTotalSpace());
|
||||||
|
|
||||||
holder.path.setText(storagePath.getShortPath());
|
holder.path.setText(storagePath.getPath());
|
||||||
holder.size.setText(String.format(freeSpaceString, freeSpace, totalSpace));
|
holder.size.setText(String.format(freeSpaceString, freeSpace, totalSpace));
|
||||||
holder.progressBar.setProgress(storagePath.getUsagePercentage());
|
holder.progressBar.setProgress(storagePath.getUsagePercentage());
|
||||||
View.OnClickListener selectListener = v -> selectionHandler.accept(storagePath.getFullPath());
|
View.OnClickListener selectListener = v -> selectionHandler.accept(storagePath.getPath());
|
||||||
holder.root.setOnClickListener(selectListener);
|
holder.root.setOnClickListener(selectListener);
|
||||||
holder.radioButton.setOnClickListener(selectListener);
|
holder.radioButton.setOnClickListener(selectListener);
|
||||||
|
|
||||||
if (storagePath.getFullPath().equals(currentPath)) {
|
if (storagePath.getPath().equals(currentPath)) {
|
||||||
holder.radioButton.toggle();
|
holder.radioButton.toggle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,8 +73,10 @@ public class DataFolderAdapter extends RecyclerView.Adapter<DataFolderAdapter.Vi
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<StoragePath> getStorageEntries(Context context) {
|
private List<StoragePath> getStorageEntries(Context context) {
|
||||||
File[] mediaDirs = context.getExternalFilesDirs(null);
|
final List<File> mediaDirs = new ArrayList<>();
|
||||||
final List<StoragePath> entries = new ArrayList<>(mediaDirs.length);
|
mediaDirs.addAll(List.of(context.getExternalFilesDirs(null)));
|
||||||
|
mediaDirs.addAll(List.of(context.getExternalMediaDirs()));
|
||||||
|
final List<StoragePath> entries = new ArrayList<>(mediaDirs.size());
|
||||||
for (File dir : mediaDirs) {
|
for (File dir : mediaDirs) {
|
||||||
if (!isWritable(dir)) {
|
if (!isWritable(dir)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -115,12 +117,7 @@ public class DataFolderAdapter extends RecyclerView.Adapter<DataFolderAdapter.Vi
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getShortPath() {
|
String getPath() {
|
||||||
int prefixIndex = path.indexOf("Android");
|
|
||||||
return (prefixIndex > 0) ? path.substring(0, prefixIndex) : path;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getFullPath() {
|
|
||||||
return this.path;
|
return this.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue