Search in sources :

Example 1 with FileLoader

use of us.koller.cameraroll.data.provider.itemLoader.FileLoader in project Camera-Roll-Android-App by kollerlukas.

the class StorageRetriever method loadFilesForDir.

public void loadFilesForDir(final Activity context, String dirPath, final FilesProvider.Callback callback) {
    if (new File(dirPath).isFile()) {
        callback.onDirLoaded(null);
        return;
    }
    threads = new ArrayList<>();
    Thread.Callback threadCallback = new Thread.Callback() {

        @Override
        public void done(Thread thread, ItemLoader.Result result) {
            File_POJO files = result.files;
            boolean filesContainMedia = false;
            for (int i = 0; i < files.getChildren().size(); i++) {
                if (files.getChildren().get(i) != null && MediaType.isMedia(files.getChildren().get(i).getPath())) {
                    filesContainMedia = true;
                    break;
                }
            }
            if (filesContainMedia) {
                SortUtil.sortByDate(files.getChildren());
            } else {
                SortUtil.sortByName(files.getChildren());
            }
            callback.onDirLoaded(files);
            thread.cancel();
            threads = null;
        }
    };
    final File[] files = new File[] { new File(dirPath) };
    Thread thread = new Thread(context, files, new FileLoader()).notSearchSubDirs().setCallback(threadCallback);
    threads.add(thread);
    thread.start();
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO) FileLoader(us.koller.cameraroll.data.provider.itemLoader.FileLoader) File(java.io.File)

Aggregations

File (java.io.File)1 File_POJO (us.koller.cameraroll.data.models.File_POJO)1 FileLoader (us.koller.cameraroll.data.provider.itemLoader.FileLoader)1