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

Commit 2d19a69f authored by Steve McKay's avatar Steve McKay
Browse files

Minor cleanups to SelectionManager interface.

This is a small grab-bag of fixes:
- Address comments from ag/2768118
- Address comments from ag/2758092
- Address comments from ag/2767710
Rename the selection collector method from getSelection(Selection) to copySelection.
    + Don't return the selection.
Improve docs in some locations and drop TODOs for interface-smells
    in need of further attention.

Bug: 64847011
Change-Id: Ibe4038ed7fcd4bc5dd0bec3a8ada5f46b77932b7
Test: Passing.
parent 878b2717
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -533,7 +533,9 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
    }

    protected Selection getStableSelection() {
        return mSelectionMgr.getSelection(new Selection());
        Selection selection = new Selection();
        mSelectionMgr.copySelection(selection);
        return selection;
    }

    @Override
+2 −2
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class ActionModeController

    @Override
    public void onSelectionChanged() {
        mSelectionMgr.getSelection(mSelected);
        mSelectionMgr.copySelection(mSelected);
        if (mSelected.size() > 0) {
            if (mActionMode == null) {
                if (DEBUG) Log.d(TAG, "Starting action mode.");
@@ -99,7 +99,7 @@ public class ActionModeController

    @Override
    public void onSelectionRestored() {
        mSelectionMgr.getSelection(mSelected);
        mSelectionMgr.copySelection(mSelected);
        if (mSelected.size() > 0) {
            if (mActionMode == null) {
                if (DEBUG) Log.d(TAG, "Starting action mode.");
+9 −9
Original line number Diff line number Diff line
@@ -43,20 +43,20 @@ public final class DocsSelectionManager implements SelectionManager {

    public SelectionManager reset(
            RecyclerView.Adapter<?> adapter,
            SelectionManager.Environment idLookup,
            SelectionManager.SelectionPredicate canSetState) {
            StableIdProvider stableIds,
            SelectionPredicate canSetState) {

        if (mDelegate != null) {
            mDelegate.clearSelection();
        }

        mDelegate = new DefaultSelectionManager(mSelectionMode, adapter, idLookup, canSetState);
        mDelegate = new DefaultSelectionManager(mSelectionMode, adapter, stableIds, canSetState);
        return this;
    }

    @Override
    public void bindContoller(BandController controller) {
        mDelegate.bindContoller(controller);
    public void bindController(BandController controller) {
        mDelegate.bindController(controller);
    }

    @Override
@@ -75,14 +75,14 @@ public final class DocsSelectionManager implements SelectionManager {
    }

    @Override
    public Selection getSelection(Selection dest) {
        return mDelegate.getSelection(dest);
    public void copySelection(Selection dest) {
        mDelegate.copySelection(dest);
    }

    @Override
    @VisibleForTesting
    public void replaceSelection(Iterable<String> ids) {
        mDelegate.replaceSelection(ids);
        mDelegate.clearSelection();
        mDelegate.setItemsSelected(ids, true);
    }

    @Override
+1 −2
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import com.android.documentsui.base.State;
import com.android.documentsui.dirlist.AnimationView;
import com.android.documentsui.queries.SearchViewManager;
import com.android.documentsui.roots.ProvidersAccess;
import com.android.documentsui.selection.DefaultSelectionManager;

import java.util.Collection;

@@ -57,7 +56,7 @@ final class RootsMonitor<T extends Activity & CommonAddons> {
        mReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                new HandleRootsChangedTask<T>(
                new HandleRootsChangedTask<>(
                        activity,
                        actions,
                        providers,
+5 −3
Original line number Diff line number Diff line
@@ -430,7 +430,8 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    }

    public void retainState(RetainedState state) {
        state.selection = mSelectionMgr.getSelection(new Selection());
        state.selection = new Selection();
        mSelectionMgr.copySelection(state.selection);
    }

    @Override
@@ -610,7 +611,8 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    }

    private boolean handleMenuItemClick(MenuItem item) {
        Selection selection = mSelectionMgr.getSelection(new Selection());
        Selection selection = new Selection();
        mSelectionMgr.copySelection(selection);

        switch (item.getItemId()) {
            case R.id.action_menu_open:
Loading