From b97c4fd9eb4f42691352c2332bc1407dbe6df6f1 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 27 Dec 2022 15:22:27 +0100 Subject: [PATCH] Refactoring --- .../faircode/email/FragmentOptionsMisc.java | 21 ++++------------ .../main/java/eu/faircode/email/Helper.java | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 0404d4457e..711aad8fee 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -1696,11 +1696,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc @Override protected List onExecute(Context context, Bundle args) { List 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() { @Override @@ -1708,20 +1708,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc return -Long.compare(f1.length(), f2.length()); } }); - return files; - } - private List getFiles(File dir, long minSize) { - List 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; } diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 50c750ec5e..cd4878e987 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -2487,15 +2487,21 @@ public class Helper { } static List listFiles(File dir) { - List 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 listFiles(File dir, Long minSize) { + List 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() {