Merge "Fallback to Recents when Downloads is not available." into nyc-dev
am: 793f859
* commit '793f859123ae77c9925d18f2c46c3fea5497b4de':
Fallback to Recents when Downloads is not available.
Change-Id: I057f45aabba52347764a9021172468193d18df04
This commit is contained in:
@@ -793,7 +793,7 @@ public abstract class BaseActivity extends Activity
|
|||||||
|
|
||||||
private static final class HandleRootsChangedTask
|
private static final class HandleRootsChangedTask
|
||||||
extends PairedTask<BaseActivity, RootInfo, RootInfo> {
|
extends PairedTask<BaseActivity, RootInfo, RootInfo> {
|
||||||
DocumentInfo mDownloadsDocument;
|
DocumentInfo mDefaultRootDocument;
|
||||||
|
|
||||||
public HandleRootsChangedTask(BaseActivity activity) {
|
public HandleRootsChangedTask(BaseActivity activity) {
|
||||||
super(activity);
|
super(activity);
|
||||||
@@ -805,28 +805,36 @@ public abstract class BaseActivity extends Activity
|
|||||||
|
|
||||||
final RootInfo currentRoot = roots[0];
|
final RootInfo currentRoot = roots[0];
|
||||||
final Collection<RootInfo> cachedRoots = mOwner.mRoots.getRootsBlocking();
|
final Collection<RootInfo> cachedRoots = mOwner.mRoots.getRootsBlocking();
|
||||||
RootInfo downloadsRoot = null;
|
|
||||||
for (final RootInfo root : cachedRoots) {
|
for (final RootInfo root : cachedRoots) {
|
||||||
if (root.isDownloads()) {
|
|
||||||
downloadsRoot = root;
|
|
||||||
}
|
|
||||||
if (root.getUri().equals(currentRoot.getUri())) {
|
if (root.getUri().equals(currentRoot.getUri())) {
|
||||||
// We don't need to change the current root as the current root was not removed.
|
// We don't need to change the current root as the current root was not removed.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(downloadsRoot != null);
|
|
||||||
mDownloadsDocument = mOwner.getRootDocumentBlocking(downloadsRoot);
|
// Choose the default root.
|
||||||
return downloadsRoot;
|
final RootInfo defaultRoot = mOwner.mRoots.getDefaultRootBlocking(mOwner.mState);
|
||||||
|
assert(defaultRoot != null);
|
||||||
|
if (!defaultRoot.isRecents()) {
|
||||||
|
mDefaultRootDocument = mOwner.getRootDocumentBlocking(defaultRoot);
|
||||||
|
}
|
||||||
|
return defaultRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finish(RootInfo downloadsRoot) {
|
protected void finish(RootInfo defaultRoot) {
|
||||||
if (downloadsRoot != null && mDownloadsDocument != null) {
|
if (defaultRoot == null) {
|
||||||
// Clear entire backstack and start in new root
|
return;
|
||||||
mOwner.mState.onRootChanged(downloadsRoot);
|
}
|
||||||
mOwner.mSearchManager.update(downloadsRoot);
|
|
||||||
mOwner.openContainerDocument(mDownloadsDocument);
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -445,6 +445,18 @@ public class RootsCache {
|
|||||||
mCacheUpdateListener = cacheUpdateListener;
|
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
|
@VisibleForTesting
|
||||||
static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
|
static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
|
||||||
final List<RootInfo> matching = new ArrayList<>();
|
final List<RootInfo> matching = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user