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

Commit 2d6caf33 authored by Ben Lin's avatar Ben Lin
Browse files

Crash fixes for Gesture selection in Picker mode.

- Prevent Gesture selection from starting if multiple selection is not
  allowed.
- Prevent startRange getting called on longPress if the item is not
  selectable.

Bug: 31440944
Bug: 31439376
Change-Id: I7ccf54378698c5cc5c70284592d40be4441921d9
parent e5d6ca2c
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -23,4 +23,22 @@ package com.android.documentsui.base;
@FunctionalInterface
public interface EventHandler<T> {
    boolean accept(T event);

    public static <T> EventHandler<T> createStub(boolean reply) {
        return new Stub<T>(reply);
    }

    public static final class Stub<T> implements EventHandler<T> {

        private boolean mReply;

        private Stub(boolean reply) {
            mReply = reply;}

        @Override
        public boolean accept(T event) {
            return mReply;
        }

    }
}
 No newline at end of file
+5 −1
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ import com.android.documentsui.RecentsLoader;
import com.android.documentsui.Snackbars;
import com.android.documentsui.ThumbnailCache;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.EventListener;
import com.android.documentsui.base.Events.InputEvent;
import com.android.documentsui.base.Events.MotionInputEvent;
@@ -332,6 +333,9 @@ public class DirectoryFragment extends Fragment
                        getContext().getDrawable(com.android.internal.R.drawable.ic_doc_generic))
                : DragStartListener.DUMMY;

        EventHandler<InputEvent> gestureHandler = state.allowMultiple
                ? gestureSel::start
                : EventHandler.createStub(false);
        mInputHandler = new UserInputHandler<>(
                mSelectionMgr,
                mFocusManager,
@@ -345,7 +349,7 @@ public class DirectoryFragment extends Fragment
                (DocumentDetails details) -> mTuner.onDocumentPicked(details.getModelId()),
                (DocumentDetails ignored) -> onDeleteSelectedDocuments(), // delete handler
                mDragStartListener::onTouchDragEvent,
                gestureSel::start);
                gestureHandler);

        new ListeningGestureDetector(
                this.getContext(),
+5 −1
Original line number Diff line number Diff line
@@ -279,7 +279,11 @@ public final class UserInputHandler<T extends InputEvent>
            } else {
                if (!mSelectionMgr.getSelection().contains(doc.getModelId())) {
                    selectDocument(doc);
                    // If we cannot select it, we didn't apply anchoring - therefore should not
                    // start gesture selection
                    if (mSelectable.test(doc)) {
                        mGestureSelectHandler.accept(event);
                    }
                } else {
                    // We only initiate drag and drop on long press for touch to allow regular
                    // touch-based scrolling