use of com.simplecity.amp_library.model.TagInfo in project Shuttle by timusus.
the class FileBrowser method loadDir.
/**
* Loads the specified folder.
*
* @param directory The file object to points to the directory to load.
* @return An {@link List<BaseFileObject>} object that holds the data of the specified directory.
*/
@WorkerThread
public List<BaseFileObject> loadDir(File directory) {
ThreadUtils.ensureNotOnMainThread();
currentDir = directory;
List<BaseFileObject> folderObjects = new ArrayList<>();
List<BaseFileObject> fileObjects = new ArrayList<>();
// Grab a list of all files/subdirs within the specified directory.
File[] files = directory.listFiles(FileHelper.getAudioFilter());
if (files != null) {
for (File file : files) {
BaseFileObject baseFileObject;
if (file.isDirectory()) {
baseFileObject = new FolderObject();
baseFileObject.path = FileHelper.getPath(file);
baseFileObject.name = file.getName();
File[] listOfFiles = file.listFiles(FileHelper.getAudioFilter());
if (listOfFiles != null && listOfFiles.length > 0) {
for (File listOfFile : listOfFiles) {
if (listOfFile.isDirectory()) {
((FolderObject) baseFileObject).folderCount++;
} else {
((FolderObject) baseFileObject).fileCount++;
}
}
} else {
continue;
}
if (!folderObjects.contains(baseFileObject)) {
folderObjects.add(baseFileObject);
}
} else {
baseFileObject = new FileObject();
baseFileObject.path = FileHelper.getPath(file);
baseFileObject.name = FileHelper.getName(file.getName());
baseFileObject.size = file.length();
((FileObject) baseFileObject).extension = FileHelper.getExtension(file.getName());
if (TextUtils.isEmpty(((FileObject) baseFileObject).extension)) {
continue;
}
((FileObject) baseFileObject).tagInfo = new TagInfo(baseFileObject.path);
if (!fileObjects.contains(baseFileObject)) {
fileObjects.add(baseFileObject);
}
}
}
}
sortFileObjects(fileObjects);
sortFolderObjects(folderObjects);
if (!settingsManager.getFolderBrowserFilesAscending()) {
Collections.reverse(fileObjects);
}
if (!settingsManager.getFolderBrowserFoldersAscending()) {
Collections.reverse(folderObjects);
}
folderObjects.addAll(fileObjects);
if (!FileHelper.isRootDirectory(currentDir)) {
FolderObject parentObject = new FolderObject();
parentObject.fileType = FileType.PARENT;
parentObject.name = FileHelper.PARENT_DIRECTORY;
parentObject.path = FileHelper.getPath(currentDir) + "/" + FileHelper.PARENT_DIRECTORY;
folderObjects.add(0, parentObject);
}
return folderObjects;
}
Aggregations