diff --git a/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java b/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java index 29245e1e1f..6fb882f7f9 100644 --- a/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java +++ b/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java @@ -543,6 +543,9 @@ else if (cursor.getCount() > 0 && cursor.moveToFirst()) { return null; } + final MainFragment mainFragment = mainFragmentReference.get(); + MainFragmentViewModel viewModel = mainFragment.getMainFragmentViewModel(); + List recentFiles = new ArrayList<>(40); Cursor cursor = getRecentFilesCursor(c); @@ -552,10 +555,10 @@ else if (cursor.getCount() > 0 && cursor.moveToFirst()) { String filePath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)); File f = new File(filePath); if (f.isDirectory()) { - List files = getFilesFromDirectory(f); + List files = getFilesFromDirectory(mainFragment, filePath); for (File file : files) - compareFileAndAddToList(recentFiles, file); - } else compareFileAndAddToList(recentFiles, f); + compareFileAndAddToList(viewModel, recentFiles, file); + } else compareFileAndAddToList(viewModel, recentFiles, f); } while (cursor.moveToNext()); } cursor.close(); @@ -597,7 +600,7 @@ private Cursor getRecentFilesCursor(Context c) { return cursor; } - private void compareFileAndAddToList(List recentFiles, File file) { + private void compareFileAndAddToList(MainFragmentViewModel viewModel, List recentFiles, File file) { Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) - 2); Date d = c.getTime(); @@ -608,32 +611,34 @@ private void compareFileAndAddToList(List recentFiles, LayoutElementParcelable parcelable = createListParcelables(strings); if (parcelable != null) { recentFiles.add(parcelable); + viewModel.incrementFileCount(); } } } } /** - * Recursively fetches the files from directory tree and adds all the files in a list + * fetches the files from directory tree and adds all the files in a list * - * @param f: File + * @param mainFragment: the main fragment reference + * @param filePath: the file filePath * @return List of files in directory tree. */ - private List getFilesFromDirectory(File f) { - List allFilesInDir = new ArrayList<>(); - try { - File[] files = f.listFiles(); - for (File file : files) { - if (file.isDirectory()) { - getFilesFromDirectory(file); - } else { - allFilesInDir.add(file); - } - } - } catch (Exception exception) { - LOG.error(exception.getLocalizedMessage()); - } - return allFilesInDir; + private List getFilesFromDirectory(MainFragment mainFragment, String filePath) { + + List files = new ArrayList<>(); + + ListFilesCommand.INSTANCE.listFiles( + filePath, + mainFragment.requireMainActivity().isRootExplorer(), + showHiddenFiles, + mode -> { return null; }, + hybridFileParcelable -> { + files.add(hybridFileParcelable.getFile()); + return null; + }); + + return files; } private @Nullable List listTrashBinFiles() {