Search in sources :

Example 1 with HybridFile

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

the class MainFragment method goBack.

public void goBack() {
    if (openMode == OpenMode.CUSTOM) {
        loadlist(home, false, OpenMode.FILE);
        return;
    }
    HybridFile currentFile = new HybridFile(openMode, CURRENT_PATH);
    if (!results) {
        if (!mRetainSearchTask) {
            // normal case
            if (selection) {
                adapter.toggleChecked(false);
            } else {
                if (openMode == OpenMode.SMB) {
                    try {
                        if (!smbPath.equals(CURRENT_PATH)) {
                            String path = (new SmbFile(CURRENT_PATH).getParent());
                            loadlist((path), true, openMode);
                        } else
                            loadlist(home, false, OpenMode.FILE);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    }
                } else if (openMode == OpenMode.SFTP) {
                    if (!CURRENT_PATH.substring("ssh://".length()).contains("/"))
                        loadlist(home, false, OpenMode.FILE);
                    else
                        loadlist(currentFile.getParent(getContext()), true, openMode);
                } else if (CURRENT_PATH.equals("/") || CURRENT_PATH.equals(home) || CURRENT_PATH.equals(OTGUtil.PREFIX_OTG + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_BOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_DROPBOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/"))
                    getMainActivity().exit();
                else if (FileUtils.canGoBack(getContext(), currentFile)) {
                    loadlist(currentFile.getParent(getContext()), true, openMode);
                } else
                    getMainActivity().exit();
            }
        } else {
            if (MainActivityHelper.SEARCH_TEXT != null) {
                // starting the search query again :O
                getMainActivity().mainFragment = (MainFragment) getMainActivity().getTabFragment().getCurrentTabFragment();
                FragmentManager fm = getMainActivity().getSupportFragmentManager();
                // getting parent path to resume search from there
                String parentPath = new HybridFile(openMode, CURRENT_PATH).getParent(getActivity());
                // don't fuckin' remove this line, we need to change
                // the path back to parent on back press
                CURRENT_PATH = parentPath;
                MainActivityHelper.addSearchFragment(fm, new SearchWorkerFragment(), parentPath, MainActivityHelper.SEARCH_TEXT, openMode, getMainActivity().isRootExplorer(), sharedPref.getBoolean(SearchWorkerFragment.KEY_REGEX, false), sharedPref.getBoolean(SearchWorkerFragment.KEY_REGEX_MATCHES, false));
            } else
                loadlist(CURRENT_PATH, true, OpenMode.UNKNOWN);
            mRetainSearchTask = false;
        }
    } else {
        // to go back after search list have been popped
        FragmentManager fm = getActivity().getSupportFragmentManager();
        SearchWorkerFragment fragment = (SearchWorkerFragment) fm.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER);
        if (fragment != null) {
            if (fragment.mSearchAsyncTask.getStatus() == AsyncTask.Status.RUNNING) {
                fragment.mSearchAsyncTask.cancel(true);
            }
        }
        loadlist(new File(CURRENT_PATH).getPath(), true, OpenMode.UNKNOWN);
        results = false;
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) HybridFile(com.amaze.filemanager.filesystem.HybridFile) MalformedURLException(java.net.MalformedURLException) File(java.io.File) SmbFile(jcifs.smb.SmbFile) HybridFile(com.amaze.filemanager.filesystem.HybridFile) SmbFile(jcifs.smb.SmbFile)

Example 2 with HybridFile

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

the class MainFragment method onActivityCreated.

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(false);
    // getMainActivity() = (MainActivity) getActivity();
    initNoFileLayout();
    getSortModes();
    this.setRetainInstance(false);
    HybridFile f = new HybridFile(OpenMode.UNKNOWN, CURRENT_PATH);
    f.generateMode(getActivity());
    getMainActivity().getAppbar().getBottomBar().setClickListener();
    if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT) && !IS_LIST) {
        listView.setBackgroundColor(Utils.getColor(getContext(), R.color.grid_background_light));
    } else {
        listView.setBackgroundDrawable(null);
    }
    listView.setHasFixedSize(true);
    columns = Integer.parseInt(sharedPref.getString(PREFERENCE_GRID_COLUMNS, "-1"));
    if (IS_LIST) {
        mLayoutManager = new LinearLayoutManager(getContext());
        listView.setLayoutManager(mLayoutManager);
    } else {
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
        setGridLayoutSpanSizeLookup(mLayoutManagerGrid);
        listView.setLayoutManager(mLayoutManagerGrid);
    }
    // use a linear layout manager
    // View footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null);// TODO: 23/5/2017 use or delete
    dividerItemDecoration = new DividerItemDecoration(getActivity(), false, getBoolean(PREFERENCE_SHOW_DIVIDERS));
    listView.addItemDecoration(dividerItemDecoration);
    mSwipeRefreshLayout.setColorSchemeColors(accentColor);
    DefaultItemAnimator animator = new DefaultItemAnimator();
    listView.setItemAnimator(animator);
    mToolbarContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            if ((columns == 0 || columns == -1)) {
                int screen_width = listView.getWidth();
                int dptopx = Utils.dpToPx(getContext(), 115);
                columns = screen_width / dptopx;
                if (columns == 0 || columns == -1)
                    columns = 3;
                if (!IS_LIST)
                    mLayoutManagerGrid.setSpanCount(columns);
            }
            if (savedInstanceState != null && !IS_LIST)
                onSavedInstanceState(savedInstanceState);
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });
    if (savedInstanceState == null) {
        loadlist(CURRENT_PATH, false, openMode);
    } else {
        if (IS_LIST)
            onSavedInstanceState(savedInstanceState);
    }
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration) ViewTreeObserver(android.view.ViewTreeObserver) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 3 with HybridFile

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

the class MainFragment method hide.

public void hide(String path) {
    dataUtils.addHiddenFile(path);
    if (new File(path).isDirectory()) {
        File f1 = new File(path + "/" + ".nomedia");
        if (!f1.exists()) {
            try {
                getMainActivity().mainActivityHelper.mkFile(new HybridFile(OpenMode.FILE, f1.getPath()), this);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        FileUtils.scanFile(path, getActivity());
    }
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) SmbFile(jcifs.smb.SmbFile) HybridFile(com.amaze.filemanager.filesystem.HybridFile) SmbException(jcifs.smb.SmbException) ActivityNotFoundException(android.content.ActivityNotFoundException) MalformedURLException(java.net.MalformedURLException)

Example 4 with HybridFile

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

the class Drawer method onDrawerClosed.

public void onDrawerClosed() {
    if (pending_fragmentTransaction != null) {
        pending_fragmentTransaction.commit();
        pending_fragmentTransaction = null;
    }
    if (pendingPath != null) {
        HybridFile hFile = new HybridFile(OpenMode.UNKNOWN, pendingPath);
        hFile.generateMode(mainActivity);
        if (hFile.isSimpleFile()) {
            FileUtils.openFile(new File(pendingPath), mainActivity, mainActivity.getPrefs());
            pendingPath = null;
            return;
        }
        MainFragment mainFrag = mainActivity.getCurrentMainFragment();
        if (mainFrag != null) {
            mainFrag.loadlist(pendingPath, false, OpenMode.UNKNOWN);
        } else {
            mainActivity.goToMain(pendingPath);
            return;
        }
        pendingPath = null;
    }
    mainActivity.supportInvalidateOptionsMenu();
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragment(com.amaze.filemanager.fragments.MainFragment) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File)

Example 5 with HybridFile

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

the class CryptUtil method encrypt.

/**
 * Wrapper around handling encryption in directory tree
 * @param context
 * @param sourceFile        the source file to encrypt
 * @param targetDirectory   the target directory in which we're going to encrypt
 */
private void encrypt(final Context context, HybridFileParcelable sourceFile, HybridFile targetDirectory) throws GeneralSecurityException, IOException {
    if (sourceFile.isDirectory()) {
        // succeed #CRYPT_EXTENSION at end of directory/file name
        final HybridFile hFile = new HybridFile(targetDirectory.getMode(), targetDirectory.getPath(), sourceFile.getName() + CRYPT_EXTENSION, sourceFile.isDirectory());
        FileUtil.mkdirs(context, hFile);
        sourceFile.forEachChildrenFile(context, sourceFile.isRoot(), file -> {
            try {
                encrypt(context, file, hFile);
            } catch (IOException | GeneralSecurityException e) {
                // throw unchecked exception, no throws needed
                throw new IllegalStateException(e);
            }
        });
    } else {
        if (sourceFile.getName().endsWith(CRYPT_EXTENSION)) {
            failedOps.add(sourceFile);
            return;
        }
        BufferedInputStream inputStream = new BufferedInputStream(sourceFile.getInputStream(context), GenericCopyUtil.DEFAULT_BUFFER_SIZE);
        // succeed #CRYPT_EXTENSION at end of directory/file name
        HybridFile targetFile = new HybridFile(targetDirectory.getMode(), targetDirectory.getPath(), sourceFile.getName() + CRYPT_EXTENSION, sourceFile.isDirectory());
        progressHandler.setFileName(sourceFile.getName());
        BufferedOutputStream outputStream = new BufferedOutputStream(targetFile.getOutputStream(context), GenericCopyUtil.DEFAULT_BUFFER_SIZE);
        if (progressHandler.getCancelled())
            return;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            aesEncrypt(inputStream, outputStream);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            rsaEncrypt(context, inputStream, outputStream);
        }
    }
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) BufferedInputStream(java.io.BufferedInputStream) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

HybridFile (com.amaze.filemanager.filesystem.HybridFile)22 File (java.io.File)7 ArrayList (java.util.ArrayList)5 Toast (android.widget.Toast)4 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)4 MainFragment (com.amaze.filemanager.fragments.MainFragment)4 SmbFile (jcifs.smb.SmbFile)4 Intent (android.content.Intent)3 DeleteTask (com.amaze.filemanager.asynchronous.asynctasks.DeleteTask)3 Uri (android.net.Uri)2 MoveFiles (com.amaze.filemanager.asynchronous.asynctasks.MoveFiles)2 CopyService (com.amaze.filemanager.asynchronous.services.CopyService)2 CryptHandler (com.amaze.filemanager.database.CryptHandler)2 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)2 Operations (com.amaze.filemanager.filesystem.Operations)2 RootHelper (com.amaze.filemanager.filesystem.RootHelper)2 OpenMode (com.amaze.filemanager.utils.OpenMode)2 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)2 MalformedURLException (java.net.MalformedURLException)2 Pattern (java.util.regex.Pattern)2