mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
d53b694e94
commit
b97c4fd9eb
|
@ -1696,11 +1696,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
@Override
|
||||
protected List<File> onExecute(Context context, Bundle args) {
|
||||
List<File> files = new ArrayList<>();
|
||||
files.addAll(getFiles(context.getFilesDir(), MIN_FILE_SIZE));
|
||||
files.addAll(getFiles(context.getCacheDir(), MIN_FILE_SIZE));
|
||||
files.addAll(Helper.listFiles(context.getFilesDir(), MIN_FILE_SIZE));
|
||||
files.addAll(Helper.listFiles(context.getCacheDir(), MIN_FILE_SIZE));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
files.addAll(getFiles(context.getDataDir(), MIN_FILE_SIZE));
|
||||
files.addAll(getFiles(Helper.getExternalFilesDir(context), MIN_FILE_SIZE));
|
||||
files.addAll(Helper.listFiles(context.getDataDir(), MIN_FILE_SIZE));
|
||||
files.addAll(Helper.listFiles(Helper.getExternalFilesDir(context), MIN_FILE_SIZE));
|
||||
|
||||
Collections.sort(files, new Comparator<File>() {
|
||||
@Override
|
||||
|
@ -1708,20 +1708,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
return -Long.compare(f1.length(), f2.length());
|
||||
}
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
private List<File> getFiles(File dir, long minSize) {
|
||||
List<File> files = new ArrayList<>();
|
||||
if (dir != null) {
|
||||
File[] listed = dir.listFiles();
|
||||
if (listed != null)
|
||||
for (File file : listed)
|
||||
if (file.isDirectory())
|
||||
files.addAll(getFiles(file, minSize));
|
||||
else if (file.length() > minSize)
|
||||
files.add(file);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
|
|
|
@ -2487,15 +2487,21 @@ public class Helper {
|
|||
}
|
||||
|
||||
static List<File> listFiles(File dir) {
|
||||
List<File> result = new ArrayList<>();
|
||||
File[] files = dir.listFiles();
|
||||
if (files != null)
|
||||
for (File file : files)
|
||||
if (file.isDirectory())
|
||||
result.addAll(listFiles(file));
|
||||
else
|
||||
result.add(file);
|
||||
return result;
|
||||
return listFiles(dir, null);
|
||||
}
|
||||
|
||||
static List<File> listFiles(File dir, Long minSize) {
|
||||
List<File> files = new ArrayList<>();
|
||||
if (dir != null) {
|
||||
File[] listed = dir.listFiles();
|
||||
if (listed != null)
|
||||
for (File file : listed)
|
||||
if (file.isDirectory())
|
||||
files.addAll(listFiles(file, minSize));
|
||||
else if (minSize == null || file.length() > minSize)
|
||||
files.add(file);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
static long getAvailableStorageSpace() {
|
||||
|
|
Loading…
Reference in New Issue