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

Commit 0f5ec83e authored by Steve McKay's avatar Steve McKay
Browse files

Add pick ActionHandler test.

Just basic at this point, only covers initial root loaded when picking copy dest.
Pulled OnRootsChangedTask out of BaseActivity.

Address followups from: https://googleplex-android-review.git.corp.google.com/#/c/1505194/

Change-Id: I2bbf418c8c9c6ad34e6f751e4a69e0f4243cc3c9
parent 44667b85
Loading
Loading
Loading
Loading
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.documentsui;

import android.net.Uri;

import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.PairedTask;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.dirlist.AnimationView;

import java.util.Collection;

final class OnRootsChangedTask
        extends PairedTask<BaseActivity, RootInfo, RootInfo> {
    RootInfo mCurrentRoot;
    DocumentInfo mDefaultRootDocument;

    public OnRootsChangedTask(BaseActivity activity) {
        super(activity);
    }

    @Override
    protected RootInfo run(RootInfo... roots) {
        assert(roots.length == 1);
        mCurrentRoot = roots[0];
        final Collection<RootInfo> cachedRoots = mOwner.mRoots.getRootsBlocking();
        for (final RootInfo root : cachedRoots) {
            if (root.getUri().equals(mCurrentRoot.getUri())) {
                // We don't need to change the current root as the current root was not removed.
                return null;
            }
        }

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

    @Override
    protected void finish(RootInfo defaultRoot) {
        if (defaultRoot == null) {
            return;
        }

        // If the activity has been launched for the specific root and it is removed, finish the
        // activity.
        final Uri uri = mOwner.getIntent().getData();
        if (uri != null && uri.equals(mCurrentRoot.getUri())) {
            mOwner.finish();
            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);
        }
    }
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -35,9 +35,9 @@ import android.provider.DocumentsContract.Root;
import android.text.TextUtils;
import android.util.Log;

import com.android.documentsui.DocumentsAccess;
import com.android.documentsui.IconUtils;
import com.android.documentsui.R;
import com.android.documentsui.roots.RootsAccess;

import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -350,7 +350,7 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
    }

    /**
     * @deprecate use {@link RootsAccess#getRootDocumentBlocking}.
     * @deprecate use {@link DocumentsAccess#getRootDocumentBlocking}.
     */
    @Deprecated
    public @Nullable DocumentInfo getRootDocumentBlocking(Context context) {
+0 −2
Original line number Diff line number Diff line
@@ -461,8 +461,6 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa

        public void reset(Model model, MultiSelectManager selectionMgr) {
            assert(model != null);
            // Allowed to be null in testing, for now.
            // assert(selectionMgr != null);

            this.model = model;
            this.selectionMgr = selectionMgr;
+3 −2
Original line number Diff line number Diff line
@@ -49,9 +49,10 @@ import java.util.List;
public final class QuickViewIntentBuilder {

    // trusted quick view package can be set via system property on debug builds.
    // Unfortunately when the value is set, it interferes with testing.
    // Unfortunately when the value is set, it interferes with testing (supercedes
    // any value set in the resource system).
    // For that reason when trusted quick view package is set to this magic value
    // we won't the system property. It's a gross hack, but stuff's gotta get done.
    // we won't honor the system property.
    public static final String IGNORE_DEBUG_PROP = "*disabled*";

    private static final String TAG = "QuickViewIntentBuilder";
+2 −3
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.documentsui.picker;

import static com.android.documentsui.base.Shared.DEBUG;
import static com.android.documentsui.base.State.ACTION_PICK_COPY_DESTINATION;

import android.app.Activity;
import android.content.Intent;
@@ -33,6 +32,7 @@ import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.Lookup;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.Shared;
import com.android.documentsui.base.State;
import com.android.documentsui.dirlist.DocumentDetails;
import com.android.documentsui.dirlist.FragmentTuner;
@@ -83,7 +83,7 @@ class ActionHandler<T extends Activity & Addons> extends AbstractActionHandler<T
            // Concensus was that the experice was too confusing.
            // In all other cases, where the user is visiting us from another app
            // we restore the stack as last used from that app.
            if (mState.action == ACTION_PICK_COPY_DESTINATION) {
            if (Shared.ACTION_PICK_COPY_DESTINATION.equals(intent.getAction())) {
                if (DEBUG) Log.d(TAG, "Launching directly into Home directory.");
                loadHomeDir();
            } else {
@@ -155,7 +155,6 @@ class ActionHandler<T extends Activity & Addons> extends AbstractActionHandler<T

        public void reset(Model model, MultiSelectManager selectionMgr) {
            assert(model != null);
            assert(selectionMgr != null);

            this.model = model;
            this.selectionMgr = selectionMgr;
Loading