Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 793f8591 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fallback to Recents when Downloads is not available." into nyc-dev

parents cd681aab 30616fcd
Loading
Loading
Loading
Loading
+22 −14
Original line number Diff line number Diff line
@@ -793,7 +793,7 @@ public abstract class BaseActivity extends Activity

    private static final class HandleRootsChangedTask
            extends PairedTask<BaseActivity, RootInfo, RootInfo> {
        DocumentInfo mDownloadsDocument;
        DocumentInfo mDefaultRootDocument;

        public HandleRootsChangedTask(BaseActivity activity) {
            super(activity);
@@ -805,28 +805,36 @@ public abstract class BaseActivity extends Activity

            final RootInfo currentRoot = roots[0];
            final Collection<RootInfo> cachedRoots = mOwner.mRoots.getRootsBlocking();
            RootInfo downloadsRoot = null;
            for (final RootInfo root : cachedRoots) {
                if (root.isDownloads()) {
                    downloadsRoot = root;
                }
                if (root.getUri().equals(currentRoot.getUri())) {
                    // We don't need to change the current root as the current root was not removed.
                    return null;
                }
            }
            assert(downloadsRoot != null);
            mDownloadsDocument = mOwner.getRootDocumentBlocking(downloadsRoot);
            return downloadsRoot;

            // Choose the default root.
            final RootInfo defaultRoot = mOwner.mRoots.getDefaultRootBlocking(mOwner.mState);
            assert(defaultRoot != null);
            if (!defaultRoot.isRecents()) {
                mDefaultRootDocument = mOwner.getRootDocumentBlocking(defaultRoot);
            }
            return defaultRoot;
        }

        @Override
        protected void finish(RootInfo downloadsRoot) {
            if (downloadsRoot != null && mDownloadsDocument != null) {
                // Clear entire backstack and start in new root
                mOwner.mState.onRootChanged(downloadsRoot);
                mOwner.mSearchManager.update(downloadsRoot);
                mOwner.openContainerDocument(mDownloadsDocument);
        protected void finish(RootInfo defaultRoot) {
            if (defaultRoot == null) {
                return;
            }

            // Clear entire backstack and start in new root.
            mOwner.mState.onRootChanged(defaultRoot);
            mOwner.mSearchManager.update(defaultRoot);

            if (defaultRoot.isRecents()) {
                mOwner.refreshCurrentRootAndDirectory(AnimationView.ANIM_NONE);
            } else {
                mOwner.openContainerDocument(mDefaultRootDocument);
            }
        }
    }
+12 −0
Original line number Diff line number Diff line
@@ -445,6 +445,18 @@ public class RootsCache {
        mCacheUpdateListener = cacheUpdateListener;
    }

    /**
     * Returns the default root for the specified state.
     */
    public RootInfo getDefaultRootBlocking(State state) {
        for (RootInfo root : getMatchingRoots(getRootsBlocking(), state)) {
            if (root.isDownloads()) {
                return root;
            }
        }
        return mRecentsRoot;
    }

    @VisibleForTesting
    static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
        final List<RootInfo> matching = new ArrayList<>();