Search in sources :

Example 1 with MoveFragment

use of dev.dworks.apps.anexplorer.fragment.MoveFragment in project AnExplorer by 1hakr.

the class DocumentsActivity method onDocumentPicked.

public void onDocumentPicked(DocumentInfo doc) {
    final FragmentManager fm = getFragmentManager();
    if (doc.isDirectory() || DocumentArchiveHelper.isSupportedArchiveType(doc.mimeType)) {
        mState.stack.push(doc);
        mState.stackTouched = true;
        onCurrentDirectoryChanged(ANIM_DOWN);
        final MoveFragment move = MoveFragment.get(fm);
        if (move != null) {
            move.setReplaceTarget(doc);
        }
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
        // Explicit file picked, return
        new ExistingFinishTask(doc.derivedUri).executeOnExecutor(getCurrentExecutor());
    } else if (mState.action == ACTION_BROWSE) {
        // Fall back to viewing
        final Intent view = new Intent(Intent.ACTION_VIEW);
        view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        view.setDataAndType(doc.derivedUri, doc.mimeType);
        if ((MimePredicate.mimeMatches(MimePredicate.SPECIAL_MIMES, doc.mimeType) || !Utils.isIntentAvailable(this, view)) && !Utils.hasNougat()) {
            try {
                File file = new File(doc.path);
                view.setDataAndType(Uri.fromFile(file), doc.mimeType);
            } catch (Exception e) {
                view.setDataAndType(doc.derivedUri, doc.mimeType);
                CrashReportingManager.logException(e);
            }
        }
        if (Utils.isIntentAvailable(this, view)) {
            // exported gives java.lang.SecurityException: Permission Denial:
            try {
                startActivity(view);
            } catch (Exception e) {
                CrashReportingManager.logException(e);
            }
        } else {
            showError(R.string.toast_no_application);
        }
    } else if (mState.action == ACTION_CREATE) {
        // Replace selected file
        // TODO: null pointer crash
        SaveFragment.get(fm).setReplaceTarget(doc);
    } else if (mState.action == ACTION_MANAGE) {
        // First try managing the document; we expect manager to filter
        // based on authority, so we don't grant.
        final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT);
        manage.setData(doc.derivedUri);
        if (Utils.isIntentAvailable(this, manage)) {
            try {
                startActivity(manage);
            } catch (ActivityNotFoundException ex) {
                // Fall back to viewing
                CrashReportingManager.logException(ex);
                final Intent view = new Intent(Intent.ACTION_VIEW);
                view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                view.setData(doc.derivedUri);
                try {
                    startActivity(view);
                } catch (ActivityNotFoundException ex2) {
                    showError(R.string.toast_no_application);
                    CrashReportingManager.logException(ex2);
                }
            }
        } else {
            showError(R.string.toast_no_application);
        }
    }
}
Also used : FragmentManager(android.app.FragmentManager) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) File(java.io.File) MoveFragment(dev.dworks.apps.anexplorer.fragment.MoveFragment) SQLiteFullException(android.database.sqlite.SQLiteFullException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 2 with MoveFragment

use of dev.dworks.apps.anexplorer.fragment.MoveFragment in project AnExplorer by 1hakr.

the class DocumentsActivity method onCurrentDirectoryChanged.

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void onCurrentDirectoryChanged(int anim) {
    // FIX for java.lang.IllegalStateException ("Activity has been destroyed")
    if (!Utils.isActivityAlive(DocumentsActivity.this)) {
        return;
    }
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    DocumentInfo cwd = getCurrentDirectory();
    // TODO : this has to be done nicely
    if (cwd == null && (null != root && !root.isServerStorage())) {
        final Uri uri = DocumentsContract.buildDocumentUri(root.authority, root.documentId);
        DocumentInfo result;
        try {
            result = DocumentInfo.fromUri(getContentResolver(), uri);
            if (result != null) {
                mState.stack.push(result);
                mState.stackTouched = true;
                cwd = result;
            }
        } catch (FileNotFoundException e) {
            CrashReportingManager.logException(e);
        }
    }
    if (!SettingsActivity.getFolderAnimation(this)) {
        anim = 0;
    }
    mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);
    if (cwd == null) {
        // No directory means recents
        if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) {
            RecentsCreateFragment.show(fm);
        } else {
            if (root.isHome()) {
                HomeFragment.show(fm);
            } else if (root.isConnections()) {
                ConnectionsFragment.show(fm);
            } else if (root.isServerStorage()) {
                ServerFragment.show(fm, root);
            } else {
                DirectoryFragment.showRecentsOpen(fm, anim);
                // Start recents in grid when requesting visual things
                // MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, mState.acceptMimes);
                final boolean visualMimes = true;
                mState.userMode = visualMimes ? MODE_GRID : MODE_LIST;
                mState.derivedMode = mState.userMode;
            }
        }
    } else {
        if (mState.currentSearch != null && mSearchResultShown) {
            // Ongoing search
            DirectoryFragment.showSearch(fm, root, cwd, mState.currentSearch, anim);
            mSearchResultShown = false;
        } else {
            // Normal boring directory
            DirectoryFragment.showNormal(fm, root, cwd, anim);
        }
    }
    // Forget any replacement target
    if (mState.action == ACTION_CREATE) {
        final SaveFragment save = SaveFragment.get(fm);
        if (save != null) {
            save.setReplaceTarget(null);
        }
    }
    if (mState.action == ACTION_OPEN_TREE) {
        final PickFragment pick = PickFragment.get(fm);
        if (pick != null) {
            final CharSequence displayName = (mState.stack.size() <= 1) && null != root ? root.title : cwd.displayName;
            pick.setPickTarget(cwd, displayName);
        }
    }
    final MoveFragment move = MoveFragment.get(fm);
    if (move != null) {
        move.setReplaceTarget(cwd);
    }
    final RootsFragment roots = RootsFragment.get(fm);
    if (roots != null) {
        roots.onCurrentRootChanged();
    }
    updateActionBar();
    invalidateMenu();
    dumpStack();
    if (!Utils.isOtherBuild() && !isTelevision()) {
        AppRate.with(this, mRateContainer).listener(mOnShowListener).checkAndShow();
    }
}
Also used : FragmentManager(android.app.FragmentManager) RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) FileNotFoundException(java.io.FileNotFoundException) SaveFragment(dev.dworks.apps.anexplorer.fragment.SaveFragment) RootsFragment(dev.dworks.apps.anexplorer.fragment.RootsFragment) Uri(android.net.Uri) PickFragment(dev.dworks.apps.anexplorer.fragment.PickFragment) MoveFragment(dev.dworks.apps.anexplorer.fragment.MoveFragment) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo) TargetApi(android.annotation.TargetApi)

Aggregations

FragmentManager (android.app.FragmentManager)2 MoveFragment (dev.dworks.apps.anexplorer.fragment.MoveFragment)2 FileNotFoundException (java.io.FileNotFoundException)2 TargetApi (android.annotation.TargetApi)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 SQLiteFullException (android.database.sqlite.SQLiteFullException)1 Uri (android.net.Uri)1 PickFragment (dev.dworks.apps.anexplorer.fragment.PickFragment)1 RootsFragment (dev.dworks.apps.anexplorer.fragment.RootsFragment)1 SaveFragment (dev.dworks.apps.anexplorer.fragment.SaveFragment)1 DocumentInfo (dev.dworks.apps.anexplorer.model.DocumentInfo)1 RootInfo (dev.dworks.apps.anexplorer.model.RootInfo)1 File (java.io.File)1 IOException (java.io.IOException)1