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

Commit c5421cd3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I92af2e4f,Ie90b783c

* changes:
  Decouple SelectionManager from DocumentsAdapter.
  Unify selection listeners under single interface.
parents 307cc15f 82cc533f
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ import java.util.function.IntConsumer;
 * A controller that listens to selection changes and manages life cycles of action modes.
 */
public class ActionModeController
        implements SelectionManager.Callback, ActionMode.Callback, ActionModeAddons {
        implements SelectionManager.EventListener, ActionMode.Callback, ActionModeAddons {

    private static final String TAG = "ActionModeController";

@@ -122,6 +122,16 @@ public class ActionModeController
        }
    }

    @Override
    public void onItemStateChanged(String id, boolean selected) {
        // Not utilized.
    }

    @Override
    public void onSelectionReset() {
        // Not utilized.
    }

    // Called when the user exits the action mode
    @Override
    public void onDestroyActionMode(ActionMode mode) {
+2 −2
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ public final class FocusManager implements FocusHandler {
            return;
        }

        int pos = mScope.adapter.getModelIds().indexOf(mScope.pendingFocusId);
        int pos = mScope.adapter.getStableIds().indexOf(mScope.pendingFocusId);
        if (pos != -1) {
            focusItem(pos);
        }
@@ -558,7 +558,7 @@ public final class FocusManager implements FocusHandler {
            int itemCount = mScope.adapter.getItemCount();
            List<String> index = new ArrayList<>(itemCount);
            for (int i = 0; i < itemCount; i++) {
                String modelId = mScope.adapter.getModelId(i);
                String modelId = mScope.adapter.getStableId(i);
                Cursor cursor = mScope.model.getItem(modelId);
                if (modelId != null && cursor != null) {
                    String title = getCursorString(cursor, Document.COLUMN_DISPLAY_NAME);
+1 −1
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ public class Injector<T extends ActionHandler> {

    public SelectionManager getSelectionManager(
            DocumentsAdapter adapter, SelectionPredicate canSetState) {
        return selectionMgr.reset(adapter, canSetState);
        return selectionMgr.reset(adapter, adapter, canSetState);
    }

    public final ActionModeController getActionModeController(
+6 −6
Original line number Diff line number Diff line
@@ -238,8 +238,8 @@ final class DirectoryAddonsAdapter extends DocumentsAdapter {
    }

    @Override
    public List<String> getModelIds() {
        return mDelegate.getModelIds();
    public List<String> getStableIds() {
        return mDelegate.getStableIds();
    }

    @Override
@@ -248,7 +248,7 @@ final class DirectoryAddonsAdapter extends DocumentsAdapter {
    }

    @Override
    public String getModelId(int p) {
    public String getStableId(int p) {
        if (p == mBreakPosition) {
            return null;
        }
@@ -261,12 +261,12 @@ final class DirectoryAddonsAdapter extends DocumentsAdapter {
            return null;
        }

        return mDelegate.getModelId(toDelegatePosition(p));
        return mDelegate.getStableId(toDelegatePosition(p));
    }

    @Override
    public void onItemSelectionChanged(String id) {
        mDelegate.onItemSelectionChanged(id);
    public void onSelectionStateChanged(String id) {
        mDelegate.onSelectionStateChanged(id);
    }

    // Listener we add to our delegate. This allows us to relay events published
+2 −3
Original line number Diff line number Diff line
@@ -94,7 +94,6 @@ 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.SelectionMetadata;
import com.android.documentsui.services.FileOperation;
import com.android.documentsui.services.FileOperationService;
import com.android.documentsui.services.FileOperationService.OpType;
@@ -324,7 +323,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
                new AccessibilityEventRouter(mRecView,
                        (View child) -> onAccessibilityClick(child)));
        mSelectionMetadata = new SelectionMetadata(mModel::getItem);
        mSelectionMgr.addItemCallback(mSelectionMetadata);
        mSelectionMgr.addEventListener(mSelectionMetadata);

        GestureSelector gestureSel = GestureSelector.create(mSelectionMgr, mRecView, mReloadLock);

@@ -386,7 +385,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
                mSelectionMetadata,
                this::handleMenuItemClick);

        mSelectionMgr.addCallback(mActionModeController);
        mSelectionMgr.addEventListener(mActionModeController);

        final ActivityManager am = (ActivityManager) mActivity.getSystemService(
                Context.ACTIVITY_SERVICE);
Loading