Search in sources :

Example 1 with PickFragment

use of dev.dworks.apps.anexplorer.fragment.PickFragment 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

TargetApi (android.annotation.TargetApi)1 FragmentManager (android.app.FragmentManager)1 Uri (android.net.Uri)1 MoveFragment (dev.dworks.apps.anexplorer.fragment.MoveFragment)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 FileNotFoundException (java.io.FileNotFoundException)1