Search in sources :

Example 1 with OnProgressUpdate

use of com.amaze.filemanager.utils.OnProgressUpdate in project AmazeFileManager by TeamAmaze.

the class CountItemsOrAndSizeTask method doInBackground.

@Override
protected String doInBackground(Void[] params) {
    String items = "";
    long fileLength = file.length(context);
    if (file.isDirectory(context)) {
        final AtomicInteger x = new AtomicInteger(0);
        file.forEachChildrenFile(context, false, new OnFileFound() {

            @Override
            public void onFileFound(HybridFileParcelable file) {
                x.incrementAndGet();
            }
        });
        final int folderLength = x.intValue();
        long folderSize;
        if (isStorage) {
            folderSize = file.getUsableSpace();
        } else {
            folderSize = FileUtils.folderSize(file, new OnProgressUpdate<Long>() {

                @Override
                public void onUpdate(Long data) {
                    publishProgress(new Pair<>(folderLength, data));
                }
            });
        }
        items = getText(folderLength, folderSize, false);
    } else {
        items = Formatter.formatFileSize(context, fileLength) + (" (" + fileLength + " " + // truncation is insignificant
        context.getResources().getQuantityString(R.plurals.bytes, (int) fileLength) + ")");
    }
    return items;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OnFileFound(com.amaze.filemanager.utils.OnFileFound) OnProgressUpdate(com.amaze.filemanager.utils.OnProgressUpdate)

Aggregations

HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)1 OnFileFound (com.amaze.filemanager.utils.OnFileFound)1 OnProgressUpdate (com.amaze.filemanager.utils.OnProgressUpdate)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1