Search in sources :

Example 1 with OpenMode

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

the class MainFragment method loadlist.

/**
 * This loads a path into the MainFragment.
 * @param path the path to be loaded
 * @param back if we're coming back from any directory and want the scroll to be restored
 * @param openMode the mode in which the directory should be opened
 */
public void loadlist(final String path, final boolean back, final OpenMode openMode) {
    if (mActionMode != null)
        mActionMode.finish();
    mSwipeRefreshLayout.setRefreshing(true);
    if (loadFilesListTask != null && loadFilesListTask.getStatus() == AsyncTask.Status.RUNNING) {
        loadFilesListTask.cancel(true);
    }
    loadFilesListTask = new LoadFilesListTask(ma.getActivity(), path, ma, openMode, getBoolean(PREFERENCE_SHOW_THUMB), getBoolean(PREFERENCE_SHOW_HIDDENFILES), (data) -> {
        if (data != null && data.second != null) {
            boolean isPathLayoutGrid = dataUtils.getListOrGridForPath(path, DataUtils.LIST) == DataUtils.GRID;
            setListElements(data.second, back, path, data.first, false, isPathLayoutGrid);
            mSwipeRefreshLayout.setRefreshing(false);
        }
    });
    loadFilesListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) Uri(android.net.Uri) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) AppTheme(com.amaze.filemanager.utils.theme.AppTheme) CryptHandler(com.amaze.filemanager.database.CryptHandler) PREFERENCE_SHOW_HEADERS(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_HEADERS) Log(android.util.Log) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation) MediaScannerConnection(android.media.MediaScannerConnection) ActionMode(android.support.v7.view.ActionMode) IntentFilter(android.content.IntentFilter) R(com.amaze.filemanager.R) PREFERENCE_SHOW_DIVIDERS(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_DIVIDERS) MainActivity(com.amaze.filemanager.activities.MainActivity) ArrayList(java.util.ArrayList) PREFERENCE_USE_CIRCULAR_IMAGES(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_USE_CIRCULAR_IMAGES) MainActivityHelper(com.amaze.filemanager.utils.MainActivityHelper) SshClientUtils(com.amaze.filemanager.filesystem.ssh.SshClientUtils) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) DataUtils(com.amaze.filemanager.utils.DataUtils) Menu(android.view.Menu) CloudUtil(com.amaze.filemanager.utils.cloud.CloudUtil) ShortcutManagerCompat(android.support.v4.content.pm.ShortcutManagerCompat) DrawerLayout(android.support.v4.widget.DrawerLayout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Formatter(android.text.format.Formatter) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask) UtilitiesProvider(com.amaze.filemanager.utils.provider.UtilitiesProvider) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) File(java.io.File) EncryptDecryptUtils(com.amaze.filemanager.utils.files.EncryptDecryptUtils) FragmentManager(android.support.v4.app.FragmentManager) Utils(com.amaze.filemanager.utils.Utils) SharedPreferences(android.content.SharedPreferences) SmbFile(jcifs.smb.SmbFile) RingtoneManager(android.media.RingtoneManager) PreferencesConstants(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants) ColorUsage(com.amaze.filemanager.utils.color.ColorUsage) PackageManager(android.content.pm.PackageManager) SmbException(jcifs.smb.SmbException) ThemedActivity(com.amaze.filemanager.activities.superclasses.ThemedActivity) RecyclerAdapter(com.amaze.filemanager.adapters.RecyclerAdapter) PasteHelper(com.amaze.filemanager.filesystem.PasteHelper) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) BottomBarButtonPath(com.amaze.filemanager.utils.BottomBarButtonPath) FileHandler(com.amaze.filemanager.asynchronous.handlers.FileHandler) PREFERENCE_SHOW_GOBACK_BUTTON(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_GOBACK_BUTTON) AsyncTask(android.os.AsyncTask) LoadFilesListTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFilesListTask) OTGUtil(com.amaze.filemanager.utils.OTGUtil) IconCompat(android.support.v4.graphics.drawable.IconCompat) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) CryptUtil(com.amaze.filemanager.utils.files.CryptUtil) List(java.util.List) TextView(android.widget.TextView) ActivityNotFoundException(android.content.ActivityNotFoundException) FragmentActivity(android.support.v4.app.FragmentActivity) CustomFileObserver(com.amaze.filemanager.filesystem.CustomFileObserver) CloudHandler(com.amaze.filemanager.database.CloudHandler) ShortcutInfoCompat(android.support.v4.content.pm.ShortcutInfoCompat) MimeTypes(com.amaze.filemanager.ui.icons.MimeTypes) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Tab(com.amaze.filemanager.database.models.Tab) FastScroller(com.amaze.filemanager.ui.views.FastScroller) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) PREFERENCE_SHOW_LAST_MODIFIED(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_LAST_MODIFIED) HybridFile(com.amaze.filemanager.filesystem.HybridFile) Intent(android.content.Intent) HashMap(java.util.HashMap) RoundedImageView(com.amaze.filemanager.ui.views.RoundedImageView) Streamer(com.amaze.filemanager.utils.SmbStreamer.Streamer) PreferencesActivity(com.amaze.filemanager.activities.PreferencesActivity) MenuItem(android.view.MenuItem) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) PREFERENCE_SHOW_FILE_SIZE(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_FILE_SIZE) PREFERENCE_SHOW_PERMISSIONS(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_PERMISSIONS) Build(android.os.Build) FileListSorter(com.amaze.filemanager.utils.files.FileListSorter) MalformedURLException(java.net.MalformedURLException) LayoutInflater(android.view.LayoutInflater) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) MediaStoreHack(com.amaze.filemanager.filesystem.MediaStoreHack) FileUtils(com.amaze.filemanager.utils.files.FileUtils) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) OpenMode(com.amaze.filemanager.utils.OpenMode) Collections(java.util.Collections) Resources(android.content.res.Resources) LoadFilesListTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFilesListTask)

Example 2 with OpenMode

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

the class RootHelper method getFiles.

/**
 * Get 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
 */
public static void getFiles(String path, boolean root, boolean showHidden, GetModeCallBack getModeCallBack, OnFileFound fileCallback) {
    OpenMode mode = OpenMode.FILE;
    ArrayList<HybridFileParcelable> files = new ArrayList<>();
    if (root && !path.startsWith("/storage") && !path.startsWith("/sdcard")) {
        try {
            // we're rooted and we're trying to load file with superuser
            // we're at the root directories, superuser is required!
            ArrayList<String> ls;
            String cpath = getCommandLineString(path);
            // ls = Shell.SU.run("ls -l " + cpath);
            ls = runShellCommand("ls -l " + (showHidden ? "-a " : "") + "\"" + cpath + "\"");
            if (ls != null) {
                for (int i = 0; i < ls.size(); i++) {
                    String file = ls.get(i);
                    if (!file.contains("Permission denied")) {
                        HybridFileParcelable array = FileUtils.parseName(file);
                        if (array != null) {
                            array.setMode(OpenMode.ROOT);
                            array.setName(array.getPath());
                            array.setPath(path + "/" + array.getPath());
                            if (array.getLink().trim().length() > 0) {
                                boolean isdirectory = isDirectory(array.getLink(), root, 0);
                                array.setDirectory(isdirectory);
                            } else
                                array.setDirectory(isDirectory(array));
                            files.add(array);
                            fileCallback.onFileFound(array);
                        }
                    }
                }
                mode = OpenMode.ROOT;
            }
            if (getModeCallBack != null)
                getModeCallBack.getMode(mode);
        } catch (ShellNotRunningException e) {
            e.printStackTrace();
        }
    }
    if (FileUtils.canListFiles(new File(path))) {
        // we're taking a chance to load files using basic java filesystem
        getFilesList(path, showHidden, fileCallback);
        mode = OpenMode.FILE;
    } else {
        // we couldn't load files using native java filesystem callbacks
        // maybe the access is not allowed due to android system restrictions, we'll see later
        mode = OpenMode.FILE;
    }
    if (getModeCallBack != null)
        getModeCallBack.getMode(mode);
}
Also used : ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) ArrayList(java.util.ArrayList) DocumentFile(android.support.v4.provider.DocumentFile) File(java.io.File) OpenMode(com.amaze.filemanager.utils.OpenMode)

Example 3 with OpenMode

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

the class CloudUtil method checkToken.

/**
 * Asynctask checks if the item pressed on is a cloud account, and if the token that
 * is saved for it is invalid or not, in which case, we'll clear off the
 * saved token and authenticate the user again
 * @param path the path of item in drawer
 * @param mainActivity reference to main activity to fire callbacks to delete/add connection
 */
public static void checkToken(String path, final MainActivity mainActivity) {
    new AsyncTask<String, Void, Boolean>() {

        OpenMode serviceType;

        private DataUtils dataUtils = DataUtils.getInstance();

        @Override
        protected Boolean doInBackground(String... params) {
            boolean isTokenValid = true;
            String path = params[0];
            if (path.startsWith(CloudHandler.CLOUD_PREFIX_DROPBOX)) {
                // dropbox account
                serviceType = OpenMode.DROPBOX;
                CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
                try {
                    cloudStorageDropbox.getUserLogin();
                } catch (Exception e) {
                    e.printStackTrace();
                    isTokenValid = false;
                }
            } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_ONE_DRIVE)) {
                serviceType = OpenMode.ONEDRIVE;
                CloudStorage cloudStorageOneDrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
                try {
                    cloudStorageOneDrive.getUserLogin();
                } catch (Exception e) {
                    e.printStackTrace();
                    isTokenValid = false;
                }
            } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_BOX)) {
                serviceType = OpenMode.BOX;
                CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
                try {
                    cloudStorageBox.getUserLogin();
                } catch (Exception e) {
                    e.printStackTrace();
                    isTokenValid = false;
                }
            } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE)) {
                serviceType = OpenMode.GDRIVE;
                CloudStorage cloudStorageGDrive = dataUtils.getAccount(OpenMode.GDRIVE);
                try {
                    cloudStorageGDrive.getUserLogin();
                } catch (Exception e) {
                    e.printStackTrace();
                    isTokenValid = false;
                }
            }
            return isTokenValid;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (!aBoolean) {
                // delete account and create a new one
                Toast.makeText(mainActivity, mainActivity.getResources().getString(R.string.cloud_token_lost), Toast.LENGTH_LONG).show();
                mainActivity.deleteConnection(serviceType);
                mainActivity.addConnection(serviceType);
            }
        }
    }.execute(path);
}
Also used : CloudStorage(com.cloudrail.si.interfaces.CloudStorage) DataUtils(com.amaze.filemanager.utils.DataUtils) OpenMode(com.amaze.filemanager.utils.OpenMode) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 4 with OpenMode

use of com.amaze.filemanager.utils.OpenMode 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 5 with OpenMode

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

the class SearchWorkerFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    String mPath = getArguments().getString(KEY_PATH);
    String mInput = getArguments().getString(KEY_INPUT);
    OpenMode mOpenMode = OpenMode.getOpenMode(getArguments().getInt(KEY_OPEN_MODE));
    boolean mRootMode = getArguments().getBoolean(KEY_ROOT_MODE);
    boolean isRegexEnabled = getArguments().getBoolean(KEY_REGEX);
    boolean isMatchesEnabled = getArguments().getBoolean(KEY_REGEX_MATCHES);
    mSearchAsyncTask = new SearchAsyncTask(getActivity(), mCallbacks, mInput, mOpenMode, mRootMode, isRegexEnabled, isMatchesEnabled);
    mSearchAsyncTask.execute(mPath);
}
Also used : SearchAsyncTask(com.amaze.filemanager.asynchronous.asynctasks.SearchAsyncTask) OpenMode(com.amaze.filemanager.utils.OpenMode)

Aggregations

OpenMode (com.amaze.filemanager.utils.OpenMode)5 ActivityNotFoundException (android.content.ActivityNotFoundException)2 DataUtils (com.amaze.filemanager.utils.DataUtils)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Activity (android.app.Activity)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Resources (android.content.res.Resources)1 Color (android.graphics.Color)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 MediaScannerConnection (android.media.MediaScannerConnection)1 RingtoneManager (android.media.RingtoneManager)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1