Search in sources :

Example 6 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class LayoutElementParcelable method generateBaseFile.

public HybridFileParcelable generateBaseFile() {
    HybridFileParcelable baseFile = new HybridFileParcelable(desc, permissions, date, longSize, isDirectory);
    baseFile.setMode(mode);
    baseFile.setName(title);
    return baseFile;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable)

Example 7 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class DeleteTask method doInBackground.

protected Boolean doInBackground(ArrayList<HybridFileParcelable>... p1) {
    files = p1[0];
    boolean wasDeleted = true;
    if (files.size() == 0)
        return true;
    if (files.get(0).isOtgFile()) {
        for (HybridFileParcelable file : files) {
            DocumentFile documentFile = OTGUtil.getDocumentFile(file.getPath(), cd, false);
            wasDeleted = documentFile.delete();
        }
    } else if (files.get(0).isDropBoxFile()) {
        CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
        for (HybridFileParcelable baseFile : files) {
            try {
                cloudStorageDropbox.delete(CloudUtil.stripPath(OpenMode.DROPBOX, baseFile.getPath()));
            } catch (Exception e) {
                e.printStackTrace();
                wasDeleted = false;
                break;
            }
        }
    } else if (files.get(0).isBoxFile()) {
        CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
        for (HybridFileParcelable baseFile : files) {
            try {
                cloudStorageBox.delete(CloudUtil.stripPath(OpenMode.BOX, baseFile.getPath()));
            } catch (Exception e) {
                e.printStackTrace();
                wasDeleted = false;
                break;
            }
        }
    } else if (files.get(0).isGoogleDriveFile()) {
        CloudStorage cloudStorageGdrive = dataUtils.getAccount(OpenMode.GDRIVE);
        for (HybridFileParcelable baseFile : files) {
            try {
                cloudStorageGdrive.delete(CloudUtil.stripPath(OpenMode.GDRIVE, baseFile.getPath()));
            } catch (Exception e) {
                e.printStackTrace();
                wasDeleted = false;
                break;
            }
        }
    } else if (files.get(0).isOneDriveFile()) {
        CloudStorage cloudStorageOnedrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
        for (HybridFileParcelable baseFile : files) {
            try {
                cloudStorageOnedrive.delete(CloudUtil.stripPath(OpenMode.ONEDRIVE, baseFile.getPath()));
            } catch (Exception e) {
                e.printStackTrace();
                wasDeleted = false;
                break;
            }
        }
    } else {
        for (HybridFileParcelable file : files) {
            try {
                if (file.delete(cd, rootMode)) {
                    wasDeleted = true;
                } else {
                    wasDeleted = false;
                    break;
                }
            } catch (ShellNotRunningException e) {
                e.printStackTrace();
                wasDeleted = false;
                break;
            }
        }
    }
    // delete file from media database
    if (!files.get(0).isSmb()) {
        try {
            for (HybridFileParcelable f : files) {
                delete(cd, f.getPath());
            }
        } catch (Exception e) {
            for (HybridFileParcelable f : files) {
                FileUtils.scanFile(f.getPath(), cd);
            }
        }
    }
    // delete file entry from encrypted database
    for (HybridFileParcelable file : files) {
        if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
            CryptHandler handler = new CryptHandler(cd);
            handler.clear(file.getPath());
        }
    }
    return wasDeleted;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) DocumentFile(android.support.v4.provider.DocumentFile) CryptHandler(com.amaze.filemanager.database.CryptHandler) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException)

Example 8 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method listVideos.

private ArrayList<LayoutElementParcelable> listVideos() {
    ArrayList<LayoutElementParcelable> songs = new ArrayList<>();
    final String[] projection = { MediaStore.Images.Media.DATA };
    final Cursor cursor = c.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
    if (cursor.getCount() > 0 && cursor.moveToFirst()) {
        do {
            String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
            HybridFileParcelable strings = RootHelper.generateBaseFile(new File(path), showHiddenFiles);
            if (strings != null) {
                LayoutElementParcelable parcelable = createListParcelables(strings);
                if (parcelable != null)
                    songs.add(parcelable);
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return songs;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ArrayList(java.util.ArrayList) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) Cursor(android.database.Cursor) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) SmbFile(jcifs.smb.SmbFile)

Example 9 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method listRecent.

private ArrayList<LayoutElementParcelable> listRecent() {
    UtilsHandler utilsHandler = new UtilsHandler(c);
    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(ma.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) 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)

Example 10 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method listDocs.

private ArrayList<LayoutElementParcelable> listDocs() {
    ArrayList<LayoutElementParcelable> songs = new ArrayList<>();
    final String[] projection = { MediaStore.Files.FileColumns.DATA };
    Cursor cursor = c.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, null, null, null);
    String[] types = new String[] { ".pdf", ".xml", ".html", ".asm", ".text/x-asm", ".def", ".in", ".rc", ".list", ".log", ".pl", ".prop", ".properties", ".rc", ".doc", ".docx", ".msg", ".odt", ".pages", ".rtf", ".txt", ".wpd", ".wps" };
    if (cursor.getCount() > 0 && cursor.moveToFirst()) {
        do {
            String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
            if (path != null && Arrays.asList(types).contains(path)) {
                HybridFileParcelable strings = RootHelper.generateBaseFile(new File(path), showHiddenFiles);
                if (strings != null) {
                    LayoutElementParcelable parcelable = createListParcelables(strings);
                    if (parcelable != null)
                        songs.add(parcelable);
                }
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    Collections.sort(songs, (lhs, rhs) -> -1 * Long.valueOf(lhs.date).compareTo(rhs.date));
    if (songs.size() > 20)
        for (int i = songs.size() - 1; i > 20; i--) {
            songs.remove(i);
        }
    return songs;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ArrayList(java.util.ArrayList) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) Cursor(android.database.Cursor) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) SmbFile(jcifs.smb.SmbFile)

Aggregations

HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)35 File (java.io.File)19 ArrayList (java.util.ArrayList)16 HybridFile (com.amaze.filemanager.filesystem.HybridFile)15 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)11 SmbFile (jcifs.smb.SmbFile)11 Intent (android.content.Intent)8 Cursor (android.database.Cursor)7 ShellNotRunningException (com.amaze.filemanager.exceptions.ShellNotRunningException)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 SharedPreferences (android.content.SharedPreferences)5 DataUtils (com.amaze.filemanager.utils.DataUtils)5 Context (android.content.Context)4 AppsListFragment (com.amaze.filemanager.fragments.AppsListFragment)4 MainFragment (com.amaze.filemanager.fragments.MainFragment)4 OnFileFound (com.amaze.filemanager.utils.OnFileFound)4 Uri (android.net.Uri)3 AsyncTask (android.os.AsyncTask)3 Build (android.os.Build)3 TextUtils (android.text.TextUtils)3