Search in sources :

Example 1 with MainFragment

use of com.amaze.filemanager.ui.fragments.MainFragment in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method listRecent.

@Nullable
private ArrayList<LayoutElementParcelable> listRecent() {
    final MainFragment mainFragment = this.mainFragmentReference.get();
    if (mainFragment == null) {
        cancel(true);
        return null;
    }
    UtilsHandler utilsHandler = AppConfig.getInstance().getUtilsHandler();
    final LinkedList<String> paths = utilsHandler.getHistoryLinkedList();
    ArrayList<LayoutElementParcelable> songs = new ArrayList<>();
    for (String f : paths) {
        if (!f.equals("/")) {
            HybridFileParcelable hybridFileParcelable = RootHelper.generateBaseFile(new File(f), showHiddenFiles);
            if (hybridFileParcelable != null) {
                hybridFileParcelable.generateMode(mainFragment.getActivity());
                if (!hybridFileParcelable.isSmb() && !hybridFileParcelable.isDirectory() && hybridFileParcelable.exists()) {
                    LayoutElementParcelable parcelable = createListParcelables(hybridFileParcelable);
                    if (parcelable != null)
                        songs.add(parcelable);
                }
            }
        }
    }
    return songs;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) ArrayList(java.util.ArrayList) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) SmbFile(jcifs.smb.SmbFile) UtilsHandler(com.amaze.filemanager.database.UtilsHandler) Nullable(androidx.annotation.Nullable)

Example 2 with MainFragment

use of com.amaze.filemanager.ui.fragments.MainFragment in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method doInBackground.

@Override
@Nullable
protected Pair<OpenMode, ArrayList<LayoutElementParcelable>> doInBackground(Void... p) {
    final MainFragment mainFragment = this.mainFragmentReference.get();
    final Context context = this.context.get();
    if (mainFragment == null || context == null || mainFragment.getMainFragmentViewModel() == null) {
        cancel(true);
        return null;
    }
    HybridFile hFile = null;
    if (OpenMode.UNKNOWN.equals(openmode) || OpenMode.CUSTOM.equals(openmode)) {
        hFile = new HybridFile(openmode, path);
        hFile.generateMode(mainFragment.getActivity());
        openmode = hFile.getMode();
        if (hFile.isSmb()) {
            mainFragment.getMainFragmentViewModel().setSmbPath(path);
        }
    }
    if (isCancelled())
        return null;
    mainFragment.getMainFragmentViewModel().setFolderCount(0);
    mainFragment.getMainFragmentViewModel().setFileCount(0);
    final ArrayList<LayoutElementParcelable> list;
    switch(openmode) {
        case SMB:
            if (hFile == null) {
                hFile = new HybridFile(OpenMode.SMB, path);
            }
            if (!hFile.getPath().endsWith("/")) {
                hFile.setPath(hFile.getPath() + "/");
            }
            try {
                SmbFile[] smbFile = hFile.getSmbFile(5000).listFiles();
                list = mainFragment.addToSmb(smbFile, path, showHiddenFiles);
                openmode = OpenMode.SMB;
            } catch (SmbAuthException e) {
                if (!e.getMessage().toLowerCase().contains("denied")) {
                    mainFragment.reauthenticateSmb();
                }
                e.printStackTrace();
                return null;
            } catch (SmbException | NullPointerException e) {
                Log.w(getClass().getSimpleName(), "Failed to load smb files for path: " + path, e);
                mainFragment.reauthenticateSmb();
                return null;
            }
            break;
        case SFTP:
            HybridFile sftpHFile = new HybridFile(OpenMode.SFTP, path);
            list = new ArrayList();
            sftpHFile.forEachChildrenFile(context, false, file -> {
                if (!(dataUtils.isFileHidden(file.getPath()) || file.isHidden() && !showHiddenFiles)) {
                    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, file -> {
                LayoutElementParcelable elem = createListParcelables(file);
                if (elem != null)
                    list.add(elem);
            });
            openmode = OpenMode.OTG;
            break;
        case DOCUMENT_FILE:
            list = new ArrayList<>();
            listDocumentFiles(file -> {
                LayoutElementParcelable elem = createListParcelables(file);
                if (elem != null)
                    list.add(elem);
            });
            openmode = OpenMode.DOCUMENT_FILE;
            break;
        case DROPBOX:
        case BOX:
        case GDRIVE:
        case ONEDRIVE:
            CloudStorage cloudStorage = dataUtils.getAccount(openmode);
            list = new ArrayList<>();
            try {
                listCloud(path, cloudStorage, openmode, file -> {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null)
                        list.add(elem);
                });
            } catch (CloudPluginException e) {
                e.printStackTrace();
                AppConfig.toast(context, context.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<>();
            final OpenMode[] currentOpenMode = new OpenMode[1];
            ListFilesCommand.INSTANCE.listFiles(path, mainFragment.getMainActivity().isRootExplorer(), showHiddenFiles, mode -> {
                currentOpenMode[0] = mode;
                return null;
            }, hybridFileParcelable -> {
                LayoutElementParcelable elem = createListParcelables(hybridFileParcelable);
                if (elem != null)
                    list.add(elem);
                return null;
            });
            if (null != currentOpenMode[0]) {
                openmode = currentOpenMode[0];
            }
            break;
    }
    if (list != null && !(openmode == OpenMode.CUSTOM && ((path).equals("5") || (path).equals("6")))) {
        int t = SortHandler.getSortType(context, path);
        int sortby;
        int asc;
        if (t <= 3) {
            sortby = t;
            asc = 1;
        } else {
            asc = -1;
            sortby = t - 4;
        }
        MainFragmentViewModel viewModel = mainFragment.getMainFragmentViewModel();
        if (viewModel != null) {
            Collections.sort(list, new FileListSorter(viewModel.getDsort(), sortby, asc));
        } else {
            Log.e(TAG, "MainFragmentViewModel is null, this is a bug");
        }
    }
    return new Pair<>(openmode, list);
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode) SmbFile(jcifs.smb.SmbFile) SmbException(jcifs.smb.SmbException) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) HybridFile(com.amaze.filemanager.filesystem.HybridFile) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) SmbAuthException(jcifs.smb.SmbAuthException) MainFragmentViewModel(com.amaze.filemanager.ui.fragments.data.MainFragmentViewModel) FileListSorter(com.amaze.filemanager.filesystem.files.FileListSorter) Pair(androidx.core.util.Pair) Nullable(androidx.annotation.Nullable)

Example 3 with MainFragment

use of com.amaze.filemanager.ui.fragments.MainFragment in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method createListParcelables.

@Nullable
private LayoutElementParcelable createListParcelables(HybridFileParcelable baseFile) {
    if (dataUtils.isFileHidden(baseFile.getPath())) {
        return null;
    }
    final MainFragment mainFragment = this.mainFragmentReference.get();
    final Context context = this.context.get();
    if (mainFragment == null || context == null) {
        cancel(true);
        return null;
    }
    String size = "";
    long longSize = 0;
    if (baseFile.isDirectory()) {
        mainFragment.getMainFragmentViewModel().setFolderCount(mainFragment.getMainFragmentViewModel().getFolderCount() + 1);
    } else {
        if (baseFile.getSize() != -1) {
            try {
                longSize = baseFile.getSize();
                size = Formatter.formatFileSize(context, longSize);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        mainFragment.getMainFragmentViewModel().setFileCount(mainFragment.getMainFragmentViewModel().getFileCount() + 1);
    }
    LayoutElementParcelable layoutElement = new LayoutElementParcelable(context, baseFile.getName(context), baseFile.getPath(), baseFile.getPermission(), baseFile.getLink(), size, longSize, false, baseFile.getDate() + "", baseFile.isDirectory(), showThumbs, baseFile.getMode());
    return layoutElement;
}
Also used : Context(android.content.Context) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) Nullable(androidx.annotation.Nullable)

Example 4 with MainFragment

use of com.amaze.filemanager.ui.fragments.MainFragment in project AmazeFileManager by TeamAmaze.

the class PasteHelper method showSnackbar.

private void showSnackbar() {
    Single.fromCallable(() -> getSnackbarContent()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<Spanned>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onSuccess(Spanned spanned) {
            snackbar = Utils.showCutCopySnackBar(mainActivity, spanned, BaseTransientBottomBar.LENGTH_INDEFINITE, R.string.paste, () -> {
                final MainFragment mainFragment = Objects.requireNonNull(mainActivity.getCurrentMainFragment());
                String path = mainFragment.getCurrentPath();
                ArrayList<HybridFileParcelable> arrayList = new ArrayList<>(Arrays.asList(paths));
                boolean move = operation == PasteHelper.OPERATION_CUT;
                new PrepareCopyTask(path, move, mainActivity, mainActivity.isRootExplorer(), mainFragment.getMainFragmentViewModel().getOpenMode()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
                dismissSnackbar(true);
            }, () -> dismissSnackbar(true));
        }

        @Override
        public void onError(Throwable e) {
            Log.e(getClass().getSimpleName(), "Failed to show paste snackbar due to " + e.getCause());
            e.printStackTrace();
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) ArrayList(java.util.ArrayList) Spanned(android.text.Spanned) PrepareCopyTask(com.amaze.filemanager.asynchronous.asynctasks.PrepareCopyTask)

Aggregations

MainFragment (com.amaze.filemanager.ui.fragments.MainFragment)4 Nullable (androidx.annotation.Nullable)3 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 HybridFile (com.amaze.filemanager.filesystem.HybridFile)2 SmbFile (jcifs.smb.SmbFile)2 Spanned (android.text.Spanned)1 Pair (androidx.core.util.Pair)1 PrepareCopyTask (com.amaze.filemanager.asynchronous.asynctasks.PrepareCopyTask)1 UtilsHandler (com.amaze.filemanager.database.UtilsHandler)1 CloudPluginException (com.amaze.filemanager.file_operations.exceptions.CloudPluginException)1 OpenMode (com.amaze.filemanager.file_operations.filesystem.OpenMode)1 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)1 FileListSorter (com.amaze.filemanager.filesystem.files.FileListSorter)1 MainFragmentViewModel (com.amaze.filemanager.ui.fragments.data.MainFragmentViewModel)1 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)1 Disposable (io.reactivex.disposables.Disposable)1 File (java.io.File)1 SmbAuthException (jcifs.smb.SmbAuthException)1