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

Commit 30b0dc18 authored by Ben Lin's avatar Ben Lin
Browse files

Fix a bug where dropping on Root never works.

DragEvent gets recycled, so by passing a DragEvent reference directly to
ActionHandler#dropOn, by the time the callback occurs, DragEvent is
updated to ACTION_DRAG_ENDED. ACTION_DRAG_ENDED events have no ClipData
and no localState, so the file operation never will occur.

Also added tests that involved ... refactoring lots of things.

Change-Id: I87daf1a4ec4e536701e03fd6dc53fc55829e5e51
parent 15ed8b2c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.documentsui.dirlist.DocumentDetails;
import com.android.documentsui.dirlist.FocusHandler;
import com.android.documentsui.files.LauncherActivity;
import com.android.documentsui.queries.SearchViewManager;
import com.android.documentsui.roots.GetRootDocumentTask;
import com.android.documentsui.roots.LoadRootTask;
import com.android.documentsui.roots.RootsAccess;
import com.android.documentsui.selection.Selection;
@@ -61,6 +62,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

import javax.annotation.Nullable;

@@ -141,6 +143,18 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
                listener).executeOnExecutor(ProviderExecutor.forAuthority(root.authority));
    }

    @Override
    public void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback) {
        GetRootDocumentTask task = new GetRootDocumentTask(
                root,
                mActivity,
                timeout,
                mDocs,
                callback);

        task.executeOnExecutor(mExecutors.lookup(root.authority));
    }

    @Override
    public void refreshDocument(DocumentInfo doc, BooleanConsumer callback) {
        RefreshTask task = new RefreshTask(
+10 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.dirlist.DocumentDetails;

import java.util.function.Consumer;

import javax.annotation.Nullable;

public interface ActionHandler {
@@ -44,6 +46,14 @@ public interface ActionHandler {
     */
    void ejectRoot(RootInfo root, BooleanConsumer listener);


    /**
     * Attempts to fetch the DocumentInfo for the supplied root. Returns the DocumentInfo to the
     * callback. If the task times out, callback will be called with null DocumentInfo. Supply
     * {@link TimeoutTask#DEFAULT_TIMEOUT} if you don't want to the task to ever time out.
     */
    void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback);

    /**
     * Attempts to refresh the given DocumentInfo, which should be at the top of the state stack.
     * Returns a boolean answer to the callback, given by {@link ContentProvider#refresh}.
+3 −4
Original line number Diff line number Diff line
@@ -309,11 +309,10 @@ public abstract class BaseActivity
        if (mRoots.isRecentsRoot(root)) {
            refreshCurrentRootAndDirectory(AnimationView.ANIM_NONE);
        } else {
            new GetRootDocumentTask(
            mInjector.actions.getRootDocument(
                    root,
                    this,
                    mInjector.actions::openRootDocument)
                    .executeOnExecutor(getExecutorForCurrentDirectory());
                    TimeoutTask.DEFAULT_TIMEOUT,
                    mInjector.actions::openRootDocument);
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public class DocumentsApplication extends Application {
        mClipStore = new ClipStorage(
                ClipStorage.prepareStorage(getCacheDir()),
                getSharedPreferences(ClipStorage.PREF_NAME, 0));
        mClipper = new DocumentClipper(this, mClipStore);
        mClipper = DocumentClipper.create(this, mClipStore);

        final IntentFilter packageFilter = new IntentFilter();
        packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
+1 −2
Original line number Diff line number Diff line
@@ -52,14 +52,13 @@ public class RefreshTask extends TimeoutTask<Void, Boolean> {

    public RefreshTask(Features features, State state, DocumentInfo doc, long timeout,
            @ApplicationScope Context context, Check check, BooleanConsumer callback) {
        super(check);
        super(check, timeout);
        mFeatures = features;
        mState = state;
        mDoc = doc;
        mContext = context;
        mCallback = callback;
        mSignal = new CancellationSignal();
        setTimeout(timeout);
    }

    @Override
Loading