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

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

Move selection manager extras to separate package.

Tighten up public interfaces of classes.
Move BandController and GestureSelector to different package in-part to eliminate access
    to <default access> methods on Selection. Goal is to force all mutation operations through
    SelectionManager so that change notfication can be rationalize
    (and by "rationalized" I mean understandable).
Eliminate documentsui dependency in GridModel.
Eliminate another Java 8 dependency (IntPredicate). Consolidate w/ SelectionPredicate.
Don't implement listener interfaces directly in top level classes. use inner classes.

Bug: 64847011
Test: Passing.
Change-Id: I5291ad27fc1b39648d72eb87bff3c844b0af5ab9
parent 8fc9d89b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.annotation.Nullable;
import android.util.Log;

import com.android.documentsui.base.Shared;
import com.android.documentsui.selection.BandController;
import com.android.documentsui.selection.addons.BandController;

/**
 * A lock used by {@link DirectoryLoader} and {@link BandController} to ensure refresh is blocked
+11 −6
Original line number Diff line number Diff line
@@ -115,18 +115,18 @@ public final class DocsSelectionManager implements SelectionManager {
    }

    @Override
    public void snapProvisionalRangeSelection(int pos) {
        mDelegate.snapProvisionalRangeSelection(pos);
    public void formNewSelectionRange(int startPos, int endPos) {
        mDelegate.formNewSelectionRange(startPos, endPos);
    }

    @Override
    public void formNewSelectionRange(int startPos, int endPos) {
        mDelegate.formNewSelectionRange(startPos, endPos);
    public void snapProvisionalRangeSelection(int pos) {
        mDelegate.snapProvisionalRangeSelection(pos);
    }

    @Override
    public void cancelProvisionalSelection() {
        mDelegate.cancelProvisionalSelection();
    public void clearProvisionalSelection() {
        mDelegate.clearProvisionalSelection();
    }

    @Override
@@ -134,6 +134,11 @@ public final class DocsSelectionManager implements SelectionManager {
        mDelegate.setProvisionalSelection(newSelection);
    }

    @Override
    public void mergeProvisionalSelection() {
        mDelegate.mergeProvisionalSelection();
    }

    @Override
    public void endRangeSelection() {
        mDelegate.endRangeSelection();
+5 −4
Original line number Diff line number Diff line
@@ -130,9 +130,10 @@ public class Injector<T extends ActionHandler> {

    /**
     * Obtains action handler and resets it if necessary.
     * @param reloadLock the lock held by {@link com.android.documentsui.selection.BandController}
     *                   to prevent loader from updating result during band selection. May be
     *                   {@code null} if called from
     *
     * @param reloadLock the lock held by
     *            {@link com.android.documentsui.selection.addons.BandController} to prevent loader
     *            from updating result during band selection. May be {@code null} if called from
     *            {@link com.android.documentsui.sidebar.RootsFragment}.
     * @return the action handler
     */
+33 −13
Original line number Diff line number Diff line
@@ -90,11 +90,11 @@ import com.android.documentsui.clipping.DocumentClipper;
import com.android.documentsui.clipping.UrisSupplier;
import com.android.documentsui.dirlist.AnimationView.AnimationType;
import com.android.documentsui.picker.PickActivity;
import com.android.documentsui.selection.BandController;
import com.android.documentsui.selection.GestureSelector;
import com.android.documentsui.selection.Selection;
import com.android.documentsui.selection.SelectionManager;
import com.android.documentsui.selection.SelectionManager.SelectionPredicate;
import com.android.documentsui.selection.addons.BandController;
import com.android.documentsui.selection.addons.GestureSelector;
import com.android.documentsui.services.FileOperation;
import com.android.documentsui.services.FileOperationService;
import com.android.documentsui.services.FileOperationService.OpType;
@@ -316,8 +316,33 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
        mModel.addUpdateListener(mAdapter.getModelUpdateListener());
        mModel.addUpdateListener(mModelUpdateListener);

        SelectionManager.SelectionPredicate canSelect = this::canSetSelectionState;
        mSelectionMgr = mInjector.getSelectionManager(mAdapter, canSelect);
        SelectionPredicate selectionPredicate = new SelectionPredicate() {

            @Override
            public boolean canSetStateForId(String id, boolean nextState) {
                return canSetSelectionState(id, nextState);
            }

            @Override
            public boolean canSetStateAtPosition(int position, boolean nextState) {
                // This method features a nextState arg for symmetry.
                // But, there are no current uses for checking un-selecting state by position.
                // So rather than have some unsuspecting client think canSetState(int, false)
                // will ever do anything. Let's just be grumpy about it.
                assert nextState == true;

                // NOTE: Given that we have logic in some places disallowing selection,
                // it may be a bug that Band and Gesture based selections don't
                // also verify something can be unselected.

                // The band selection model only operates on documents and directories.
                // Exclude other types of adapter items like whitespace and dividers.
                RecyclerView.ViewHolder vh = mRecView.findViewHolderForAdapterPosition(position);
                return ModelBackedDocumentsAdapter.isContentType(vh.getItemViewType());
            }
        };

        mSelectionMgr = mInjector.getSelectionManager(mAdapter, selectionPredicate);
        mFocusManager = mInjector.getFocusManager(mRecView, mModel);
        mActions = mInjector.getActionHandler(mReloadLock);

@@ -332,16 +357,11 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
        if (mState.allowMultiple) {
            mBandController = new BandController(
                    mRecView,
                    mAdapter,
                    mAdapter,  // stableIds provider.
                    mSelectionMgr,
                    canSelect,
                    mReloadLock,
                    (int pos) -> {
                        // The band selection model only operates on documents and directories.
                        // Exclude other types of adapter items like whitespace and dividers.
                        RecyclerView.ViewHolder vh = mRecView.findViewHolderForAdapterPosition(pos);
                        return ModelBackedDocumentsAdapter.isContentType(vh.getItemViewType());
                    });
                    selectionPredicate,
                    mReloadLock);

            mBandSelectStarted = mFocusManager::clearFocus;
            mBandController.addBandSelectStartedListener(mBandSelectStarted);
        }
+0 −4
Original line number Diff line number Diff line
@@ -68,10 +68,6 @@ public abstract class DocumentsAdapter
        throw new UnsupportedOperationException();
    }

    public boolean hasModelIds() {
        return !getStableIds().isEmpty();
    }

    static boolean isDirectory(Cursor cursor) {
        final String mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
        return Document.MIME_TYPE_DIR.equals(mimeType);
Loading