Loading packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +22 −14 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); } } } Loading packages/DocumentsUI/src/com/android/documentsui/RootsCache.java +12 −0 Original line number Diff line number Diff line Loading @@ -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<>(); Loading Loading
packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +22 −14 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); } } } Loading
packages/DocumentsUI/src/com/android/documentsui/RootsCache.java +12 −0 Original line number Diff line number Diff line Loading @@ -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<>(); Loading