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

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

Exclude all MessageHolder types from selection.

Bug: 78683813
Test: Added new functional coverage of directory message functionality.
Change-Id: Idf6396c7bf9a5afa4dbddd2f3b75dcbab5f4359e
parent 8f606029
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -335,8 +335,8 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
        mSelectionMgr.addObserver(mSelectionMetadata);
        mDetailsLookup = new DocsItemDetailsLookup(mRecView);

        GestureSelectionHelper gestureHelper =
                GestureSelectionHelper.create(mSelectionMgr, mRecView, mContentLock);
        GestureSelectionHelper gestureHelper = GestureSelectionHelper.create(
                mSelectionMgr, mRecView, mContentLock, mDetailsLookup);

        if (mState.allowMultiple) {
            mBandSelector = new BandSelectionHelper(
+15 −3
Original line number Diff line number Diff line
@@ -41,17 +41,29 @@ final class DocsItemDetailsLookup extends ItemDetailsLookup {

    @Override
    public boolean overStableItem(MotionEvent e) {
        return overItem(e) && getItemDetails(e).hasStableId();
    if (!overItem(e)) {
        return false;
    }
    ItemDetails details = getItemDetails(e);
    return details != null && details.hasStableId();
    }

    @Override
    public boolean inItemDragRegion(MotionEvent e) {
        return overItem(e) && getItemDetails(e).inDragRegion(e);
    if (!overItem(e)) {
        return false;
    }
    ItemDetails details = getItemDetails(e);
    return details != null && details.inDragRegion(e);
    }

    @Override
    public boolean inItemSelectRegion(MotionEvent e) {
        return overItem(e) && getItemDetails(e).inSelectionHotspot(e);
    if (!overItem(e)) {
        return false;
    }
    ItemDetails details = getItemDetails(e);
    return details != null && details.inSelectionHotspot(e);
    }

    @Override
+4 −1
Original line number Diff line number Diff line
@@ -94,7 +94,10 @@ public abstract class DocumentHolder
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        assert(mKeyEventListener != null);
        return mKeyEventListener.onKey(getItemDetails(),  keyCode,  event);
        ItemDetails details = getItemDetails();
        return (details == null)
            ? false
            : mKeyEventListener.onKey(getItemDetails(),  keyCode,  event);
    }

    /**
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.documentsui.dirlist;

import com.android.documentsui.selection.ItemDetailsLookup.ItemDetails;

import android.content.Context;
import android.view.MotionEvent;
import android.view.ViewGroup;
@@ -34,7 +36,7 @@ abstract class MessageHolder extends DocumentHolder {
    }

    @Override
    public boolean inDragRegion(MotionEvent event) {
        return false;
    public ItemDetails getItemDetails() {
        return null;
    }
}
+26 −12
Original line number Diff line number Diff line
@@ -45,8 +45,9 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo
    private final Runnable mScroller;
    private final ViewDelegate mView;
    private final ContentLock mLock;
    private final ItemDetailsLookup mItemLookup;

    private int mLastStartedItemPos = -1;
    private int mLastTouchedItemPosition = -1;
    private boolean mStarted = false;
    private Point mLastInterceptedPoint;

@@ -58,15 +59,18 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo
    GestureSelectionHelper(
            SelectionHelper selectionHelper,
            ViewDelegate view,
            ContentLock lock) {
            ContentLock lock,
            ItemDetailsLookup itemLookup) {

        checkArgument(selectionHelper != null);
        checkArgument(view != null);
        checkArgument(lock != null);
        checkArgument(itemLookup != null);

        mSelectionMgr = selectionHelper;
        mView = view;
        mLock = lock;
        mItemLookup = itemLookup;

        mScroller = new ViewAutoScroller(this, mView);
    }
@@ -81,7 +85,7 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo
        // See: b/70518185. It appears start() is being called via onLongPress
        // even though we never received an intial handleInterceptedDownEvent
        // where we would usually initialize mLastStartedItemPos.
        if (mLastStartedItemPos < 0){
        if (mLastTouchedItemPosition < 0){
          Log.w(TAG, "Illegal state. Can't start without valid mLastStartedItemPos.");
          return;
        }
@@ -142,11 +146,17 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo
    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {}

    // Called when an ACTION_DOWN event is intercepted.
    // Called when an ACTION_DOWN event is intercepted. See onInterceptTouchEvent
    // for additional notes.
    // If down event happens on an item, we mark that item's position as last started.
    private boolean handleInterceptedDownEvent(MotionEvent e) {
        mLastStartedItemPos = mView.getItemUnder(e);
        return mLastStartedItemPos != RecyclerView.NO_POSITION;
        // Ignore events where details provider doesn't return details.
        // These objects don't participate in selection.
        if (mItemLookup.getItemDetails(e) == null) {
            return false;
        }
        mLastTouchedItemPosition = mView.getItemUnder(e);
        return mLastTouchedItemPosition != RecyclerView.NO_POSITION;
    }

    // Called when ACTION_UP event is to be handled.
@@ -155,8 +165,8 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo
    private void handleUpEvent(MotionEvent e) {
        mSelectionMgr.mergeProvisionalSelection();
        endSelection();
        if (mLastStartedItemPos > -1) {
            mSelectionMgr.startRange(mLastStartedItemPos);
        if (mLastTouchedItemPosition > -1) {
            mSelectionMgr.startRange(mLastTouchedItemPosition);
        }
    }

@@ -171,7 +181,7 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo
    private void endSelection() {
        checkState(mStarted);

        mLastStartedItemPos = -1;
        mLastTouchedItemPosition = -1;
        mStarted = false;
        mLock.unblock();
    }
@@ -227,13 +237,17 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo
    }

    /**
     * Returns a new instance of GestureSelectionHelper.
     * Returns a new instance of GestureSelectionHelper, wrapping the
     * RecyclerView in a test friendly wrapper.
     */
    public static GestureSelectionHelper create(
            SelectionHelper selectionMgr, RecyclerView recycler, ContentLock lock) {
            SelectionHelper selectionMgr,
            RecyclerView recycler,
            ContentLock lock,
            ItemDetailsLookup itemLookup) {

        return new GestureSelectionHelper(
                selectionMgr, new RecyclerViewDelegate(recycler), lock);
                selectionMgr, new RecyclerViewDelegate(recycler), lock, itemLookup);
    }

    @VisibleForTesting
Loading