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

Commit c95d87c9 authored by Steve McKay's avatar Steve McKay
Browse files

Don't restore stack when picking copy destination.

Move fancy drawer "fiddling" to FilesActivity.
Rename the various "Restore" tasks to better reflect their roles.

Change-Id: I7f5c3dee11112bf0a31e6219d09c572c5651629d
parent 0ffd49cb
Loading
Loading
Loading
Loading
+11 −32
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -66,9 +65,6 @@ import java.util.concurrent.Executor;
public abstract class BaseActivity extends Activity
        implements SearchManagerListener, NavigationView.Environment {

    // See comments where this const is referenced for details.
    private static final int DRAWER_NO_FIDDLE_DELAY = 1500;

    State mState;
    RootsCache mRoots;
    SearchViewManager mSearchManager;
@@ -80,10 +76,6 @@ public abstract class BaseActivity extends Activity
    @LayoutRes
    private int mLayoutId;

    // Track the time we opened the drawer in response to back being pressed.
    // We use the time gap to figure out whether to close app or reopen the drawer.
    private long mDrawerLastFiddled;

    private boolean mNavDrawerHasFocus;

    public abstract void onDocumentPicked(DocumentInfo doc, Model model);
@@ -368,6 +360,11 @@ public abstract class BaseActivity extends Activity
        invalidateOptionsMenu();
    }

    final void loadRoot(final Uri uri) {
        new LoadRootTask(this, uri).executeOnExecutor(
                ProviderExecutor.forAuthority(uri.getAuthority()));
    }

    /**
     * Called when search results changed.
     * Refreshes the content of the directory. It doesn't refresh elements on the action bar.
@@ -543,34 +540,16 @@ public abstract class BaseActivity extends Activity
            return;
        }

        int size = mState.stack.size();

        // Do some "do what a I want" drawer fiddling, but don't
        // do it if user already hit back recently and we recently
        // did some fiddling.
        if (mDrawer.isPresent()
                && (System.currentTimeMillis() - mDrawerLastFiddled) > DRAWER_NO_FIDDLE_DELAY) {
            // Close drawer if it is open.
            if (mDrawer.isOpen()) {
                mDrawer.setOpen(false);
                mDrawerLastFiddled = System.currentTimeMillis();
        if (onBeforePopDir() || popDir()) {
            return;
        }

            // Open the Close drawer if it is closed and we're at the top of a root.
            if (size == 1) {
                mDrawer.setOpen(true);
                // Remember so we don't just close it again if back is pressed again.
                mDrawerLastFiddled = System.currentTimeMillis();
                return;
            }
        }

        if (popDir()) {
            return;
        super.onBackPressed();
    }

        super.onBackPressed();
    boolean onBeforePopDir() {
        // Files app overrides this with some fancy logic.
        return false;
    }

    public void onStackPicked(DocumentStack stack) {
+26 −9
Original line number Diff line number Diff line
@@ -95,13 +95,27 @@ public class DocumentsActivity extends BaseActivity {
            RootsFragment.show(getFragmentManager(), null);
        }

        if (!mState.restored) {
            // In this case, we set the activity title in AsyncTask.onPostExecute().  To prevent
            // talkback from reading aloud the default title, we clear it here.
        if (mState.restored) {
            refreshCurrentRootAndDirectory(ANIM_NONE);
        } else {
            // We set the activity title in AsyncTask.onPostExecute().
            // To prevent talkback from reading aloud the default title, we clear it here.
            setTitle("");
            new RestoreStackTask(this).execute();

            // As a matter of policy we don't load the last used stack for the copy
            // destination picker (user is already in Files app).
            // 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 (DEBUG) Log.d(TAG, "Launching directly into Home directory.");
                Uri homeUri = DocumentsContract.buildHomeUri();
                new LoadRootTask(this, homeUri).executeOnExecutor(
                        ProviderExecutor.forAuthority(homeUri.getAuthority()));
            } else {
            refreshCurrentRootAndDirectory(ANIM_NONE);
                if (DEBUG) Log.d(TAG, "Attempting to load last used stack for calling package.");
                new LoadLastUsedStackTask(this).execute();
            }
        }
    }

@@ -443,16 +457,19 @@ public class DocumentsActivity extends BaseActivity {
    }

    /**
     * Restores the stack from Recents for the specified package.
     * Loads the last used path (stack) from Recents (history).
     * The path selected is based on the calling package name. So the last
     * path for an app like Gmail can be different than the last path
     * for an app like DropBox.
     */
    private static final class RestoreStackTask
    private static final class LoadLastUsedStackTask
            extends PairedTask<DocumentsActivity, Void, Void> {

        private volatile boolean mRestoredStack;
        private volatile boolean mExternal;
        private State mState;

        public RestoreStackTask(DocumentsActivity activity) {
        public LoadLastUsedStackTask(DocumentsActivity activity) {
            super(activity);
            mState = activity.mState;
        }
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public class DownloadsActivity extends BaseActivity {
            // talkback from reading aloud the default title, we clear it here.
            setTitle("");
            final Uri rootUri = getIntent().getData();
            new RestoreRootTask(this, rootUri).executeOnExecutor(getExecutorForCurrentDirectory());
            new LoadRootTask(this, rootUri).executeOnExecutor(getExecutorForCurrentDirectory());
        } else {
            refreshCurrentRootAndDirectory(ANIM_NONE);
        }
+36 −4
Original line number Diff line number Diff line
@@ -62,6 +62,12 @@ public class FilesActivity extends BaseActivity {

    public static final String TAG = "FilesActivity";

    // See comments where this const is referenced for details.
    private static final int DRAWER_NO_FIDDLE_DELAY = 1500;

    // Track the time we opened the drawer in response to back being pressed.
    // We use the time gap to figure out whether to close app or reopen the drawer.
    private long mDrawerLastFiddled;
    private DocumentClipper mClipper;

    public FilesActivity() {
@@ -102,14 +108,12 @@ public class FilesActivity extends BaseActivity {
            if (DEBUG) Log.d(TAG, "Launching with root URI.");
            // If we've got a specific root to display, restore that root using a dedicated
            // authority. That way a misbehaving provider won't result in an ANR.
            new RestoreRootTask(this, uri).executeOnExecutor(
                    ProviderExecutor.forAuthority(uri.getAuthority()));
            loadRoot(uri);
        } else {
            if (DEBUG) Log.d(TAG, "Launching into Home directory.");
            // If all else fails, try to load "Home" directory.
            final Uri homeUri = DocumentsContract.buildHomeUri();
            new RestoreRootTask(this, homeUri).executeOnExecutor(
                    ProviderExecutor.forAuthority(homeUri.getAuthority()));
            loadRoot(homeUri);
        }

        final @DialogType int dialogType = intent.getIntExtra(
@@ -340,6 +344,34 @@ public class FilesActivity extends BaseActivity {
        }
    }

    // Do some "do what a I want" drawer fiddling, but don't
    // do it if user already hit back recently and we recently
    // did some fiddling.
    @Override
    boolean onBeforePopDir() {
        int size = mState.stack.size();

        if (mDrawer.isPresent()
                && (System.currentTimeMillis() - mDrawerLastFiddled) > DRAWER_NO_FIDDLE_DELAY) {
            // Close drawer if it is open.
            if (mDrawer.isOpen()) {
                mDrawer.setOpen(false);
                mDrawerLastFiddled = System.currentTimeMillis();
                return true;
            }

            // Open the Close drawer if it is closed and we're at the top of a root.
            if (size == 1) {
                mDrawer.setOpen(true);
                // Remember so we don't just close it again if back is pressed again.
                mDrawerLastFiddled = System.currentTimeMillis();
                return true;
            }
        }

        return false;
    }

    // Turns out only DocumentsActivity was ever calling saveStackBlocking.
    // There may be a  case where we want to contribute entries from
    // Behavior here in FilesActivity, but it isn't yet obvious.
+2 −2
Original line number Diff line number Diff line
@@ -22,12 +22,12 @@ import android.util.Log;

import com.android.documentsui.model.RootInfo;

final class RestoreRootTask extends PairedTask<BaseActivity, Void, RootInfo> {
final class LoadRootTask extends PairedTask<BaseActivity, Void, RootInfo> {
    private static final String TAG = "RestoreRootTask";

    private final Uri mRootUri;

    public RestoreRootTask(BaseActivity activity, Uri rootUri) {
    public LoadRootTask(BaseActivity activity, Uri rootUri) {
        super(activity);
        mRootUri = rootUri;
    }
Loading