Search in sources :

Example 1 with OnFileFound

use of com.amaze.filemanager.utils.OnFileFound 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)

Example 2 with OnFileFound

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

the class LoadFilesListTask method doInBackground.

@Override
protected Pair<OpenMode, ArrayList<LayoutElementParcelable>> doInBackground(Void... p) {
    HybridFile hFile = null;
    if (openmode == OpenMode.UNKNOWN) {
        hFile = new HybridFile(OpenMode.UNKNOWN, path);
        hFile.generateMode(ma.getActivity());
        openmode = hFile.getMode();
        if (hFile.isSmb()) {
            ma.smbPath = path;
        } else if (android.util.Patterns.EMAIL_ADDRESS.matcher(path).matches()) {
            openmode = OpenMode.ROOT;
        }
    }
    if (isCancelled())
        return null;
    ma.folder_count = 0;
    ma.file_count = 0;
    final ArrayList<LayoutElementParcelable> list;
    switch(openmode) {
        case SMB:
            if (hFile == null) {
                hFile = new HybridFile(OpenMode.SMB, path);
            }
            try {
                SmbFile[] smbFile = hFile.getSmbFile(5000).listFiles();
                list = ma.addToSmb(smbFile, path);
                openmode = OpenMode.SMB;
            } catch (SmbAuthException e) {
                if (!e.getMessage().toLowerCase().contains("denied")) {
                    ma.reauthenticateSmb();
                }
                return null;
            } catch (SmbException | NullPointerException e) {
                e.printStackTrace();
                return null;
            }
            break;
        case SFTP:
            HybridFile sftpHFile = new HybridFile(OpenMode.SFTP, path);
            list = new ArrayList<LayoutElementParcelable>();
            sftpHFile.forEachChildrenFile(c, false, file -> {
                LayoutElementParcelable elem = createListParcelables(file);
                if (elem != null)
                    list.add(elem);
            });
            break;
        case CUSTOM:
            switch(Integer.parseInt(path)) {
                case 0:
                    list = listImages();
                    break;
                case 1:
                    list = listVideos();
                    break;
                case 2:
                    list = listaudio();
                    break;
                case 3:
                    list = listDocs();
                    break;
                case 4:
                    list = listApks();
                    break;
                case 5:
                    list = listRecent();
                    break;
                case 6:
                    list = listRecentFiles();
                    break;
                default:
                    throw new IllegalStateException();
            }
            break;
        case OTG:
            list = new ArrayList<>();
            listOtg(path, new OnFileFound() {

                @Override
                public void onFileFound(HybridFileParcelable file) {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null)
                        list.add(elem);
                }
            });
            openmode = OpenMode.OTG;
            break;
        case DROPBOX:
        case BOX:
        case GDRIVE:
        case ONEDRIVE:
            CloudStorage cloudStorage = dataUtils.getAccount(openmode);
            list = new ArrayList<>();
            try {
                listCloud(path, cloudStorage, openmode, new OnFileFound() {

                    @Override
                    public void onFileFound(HybridFileParcelable file) {
                        LayoutElementParcelable elem = createListParcelables(file);
                        if (elem != null)
                            list.add(elem);
                    }
                });
            } catch (CloudPluginException e) {
                e.printStackTrace();
                AppConfig.toast(c, c.getResources().getString(R.string.failed_no_connection));
                return new Pair<>(openmode, list);
            }
            break;
        default:
            // we're neither in OTG not in SMB, load the list based on root/general filesystem
            list = new ArrayList<>();
            RootHelper.getFiles(path, ma.getMainActivity().isRootExplorer(), showHiddenFiles, new RootHelper.GetModeCallBack() {

                @Override
                public void getMode(OpenMode mode) {
                    openmode = mode;
                }
            }, new OnFileFound() {

                @Override
                public void onFileFound(HybridFileParcelable file) {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null)
                        list.add(elem);
                }
            });
            break;
    }
    if (list != null && !(openmode == OpenMode.CUSTOM && ((path).equals("5") || (path).equals("6")))) {
        Collections.sort(list, new FileListSorter(ma.dsort, ma.sortby, ma.asc));
    }
    return new Pair<>(openmode, list);
}
Also used : LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) OpenMode(com.amaze.filemanager.utils.OpenMode) SmbFile(jcifs.smb.SmbFile) SmbException(jcifs.smb.SmbException) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) HybridFile(com.amaze.filemanager.filesystem.HybridFile) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) SmbAuthException(jcifs.smb.SmbAuthException) RootHelper(com.amaze.filemanager.filesystem.RootHelper) FileListSorter(com.amaze.filemanager.utils.files.FileListSorter) OnFileFound(com.amaze.filemanager.utils.OnFileFound) Pair(android.support.v4.util.Pair)

Example 3 with OnFileFound

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

the class PrepareCopyTask method checkConflicts.

private ArrayList<HybridFileParcelable> checkConflicts(final ArrayList<HybridFileParcelable> filesToCopy, HybridFile destination) {
    final ArrayList<HybridFileParcelable> conflictingFiles = new ArrayList<>();
    destination.forEachChildrenFile(context, rootMode, new OnFileFound() {

        @Override
        public void onFileFound(HybridFileParcelable file) {
            for (HybridFileParcelable j : filesToCopy) {
                if (file.getName().equals((j).getName())) {
                    conflictingFiles.add(j);
                }
            }
        }
    });
    return conflictingFiles;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ArrayList(java.util.ArrayList) OnFileFound(com.amaze.filemanager.utils.OnFileFound)

Example 4 with OnFileFound

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

the class RootHelper method getFilesList.

/**
 * Get a list of files using shell, supposing the path is not a SMB/OTG/Custom (*.apk/images)
 *
 * @param path
 * @param root            whether root is available or not
 * @param showHidden      to show hidden files
 * @param getModeCallBack callback to set the type of file
 * @return TODO: Avoid parsing ls
 * @deprecated use getFiles()
 */
public static ArrayList<HybridFileParcelable> getFilesList(String path, boolean root, boolean showHidden, GetModeCallBack getModeCallBack) {
    final ArrayList<HybridFileParcelable> files = new ArrayList<>();
    getFiles(path, root, showHidden, getModeCallBack, new OnFileFound() {

        @Override
        public void onFileFound(HybridFileParcelable file) {
            files.add(file);
        }
    });
    return files;
}
Also used : ArrayList(java.util.ArrayList) OnFileFound(com.amaze.filemanager.utils.OnFileFound)

Example 5 with OnFileFound

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

the class FileUtils method otgFolderSize.

/**
 * Helper method to get size of an otg folder
 */
public static long otgFolderSize(String path, final Context context) {
    final AtomicLong totalBytes = new AtomicLong(0);
    OTGUtil.getDocumentFiles(path, context, new OnFileFound() {

        @Override
        public void onFileFound(HybridFileParcelable file) {
            totalBytes.addAndGet(getBaseFileSize(file, context));
        }
    });
    return totalBytes.longValue();
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) AtomicLong(java.util.concurrent.atomic.AtomicLong) OnFileFound(com.amaze.filemanager.utils.OnFileFound)

Aggregations

OnFileFound (com.amaze.filemanager.utils.OnFileFound)6 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)5 ArrayList (java.util.ArrayList)3 Pair (android.support.v4.util.Pair)1 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)1 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)1 HybridFile (com.amaze.filemanager.filesystem.HybridFile)1 RootHelper (com.amaze.filemanager.filesystem.RootHelper)1 OnProgressUpdate (com.amaze.filemanager.utils.OnProgressUpdate)1 OpenMode (com.amaze.filemanager.utils.OpenMode)1 FileListSorter (com.amaze.filemanager.utils.files.FileListSorter)1 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 SmbAuthException (jcifs.smb.SmbAuthException)1 SmbException (jcifs.smb.SmbException)1 SmbFile (jcifs.smb.SmbFile)1