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

Commit b58ad42f authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by android-build-merger
Browse files

Do not allow to select non-selectable items via mouse.

am: 5e02d30

* commit '5e02d303c07d428970e25b315061c61287df153d':
  Do not allow to select non-selectable items via mouse.

Change-Id: Idad7af7e19d2afbb0a4a5d842717b81fc1b4cd05
parents 6b9773ef 0ad227ef
Loading
Loading
Loading
Loading
+24 −1
Original line number Original line Diff line number Diff line
@@ -1268,6 +1268,11 @@ public final class MultiSelectManager {
            notifySelectionChanged();
            notifySelectionChanged();
        }
        }


        @Override
        public boolean onBeforeItemStateChange(String id, boolean nextState) {
            return notifyBeforeItemStateChange(id, nextState);
        }

        private class ViewScroller implements Runnable {
        private class ViewScroller implements Runnable {
            /**
            /**
             * The number of milliseconds of scrolling at which scroll speed continues to increase.
             * The number of milliseconds of scrolling at which scroll speed continues to increase.
@@ -1655,8 +1660,10 @@ public final class MultiSelectManager {
                        if (id != null) {
                        if (id != null) {
                            // The adapter inserts items for UI layout purposes that aren't associated
                            // The adapter inserts items for UI layout purposes that aren't associated
                            // with files.  Those will have a null model ID.  Don't select them.
                            // with files.  Those will have a null model ID.  Don't select them.
                            if (canSelect(id)) {
                                mSelection.add(id);
                                mSelection.add(id);
                            }
                            }
                        }
                        if (isPossiblePositionNearestOrigin(column, columnStartIndex, columnEndIndex,
                        if (isPossiblePositionNearestOrigin(column, columnStartIndex, columnEndIndex,
                                row, rowStartIndex, rowEndIndex)) {
                                row, rowStartIndex, rowEndIndex)) {
                            // If this is the position nearest the origin, record it now so that it
                            // If this is the position nearest the origin, record it now so that it
@@ -1668,6 +1675,21 @@ public final class MultiSelectManager {
            }
            }
        }
        }


        /**
         * @return True if the item is selectable.
         */
        private boolean canSelect(String id) {
            // TODO: Simplify the logic, so the check whether we can select is done in one place.
            // Consider injecting FragmentTuner, or move the checks from MultiSelectManager to
            // Selection.
            for (OnSelectionChangedListener listener : mOnSelectionChangedListeners) {
                if (!listener.onBeforeItemStateChange(id, true)) {
                    return false;
                }
            }
            return true;
        }

        /**
        /**
         * @return Returns true if the position is the nearest to the origin, or, in the case of the
         * @return Returns true if the position is the nearest to the origin, or, in the case of the
         *     lower-right corner, whether it is possible that the position is the nearest to the
         *     lower-right corner, whether it is possible that the position is the nearest to the
@@ -1700,6 +1722,7 @@ public final class MultiSelectManager {
         */
         */
        static interface OnSelectionChangedListener {
        static interface OnSelectionChangedListener {
            public void onSelectionChanged(Set<String> updatedSelection);
            public void onSelectionChanged(Set<String> updatedSelection);
            public boolean onBeforeItemStateChange(String id, boolean nextState);
        }
        }


        void addOnSelectionChangedListener(OnSelectionChangedListener listener) {
        void addOnSelectionChangedListener(OnSelectionChangedListener listener) {
+5 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,11 @@ public class MultiSelectManager_GridModelTest extends AndroidTestCase {
                    public void onSelectionChanged(Set<String> updatedSelection) {
                    public void onSelectionChanged(Set<String> updatedSelection) {
                        lastSelection = updatedSelection;
                        lastSelection = updatedSelection;
                    }
                    }

                    @Override
                    public boolean onBeforeItemStateChange(String id, boolean nextState) {
                        return true;
                    }
                });
                });
    }
    }