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

Commit c56fb4e0 authored by Ben Kwa's avatar Ben Kwa
Browse files

Fix various band select instabilities.

- Guard against OutOfBoundsExceptions by checking for
  RecyclerView.NO_POSITION before attempting to retrieve model IDs in
  various places.

- Fix a spot where the default return value of
  SparseIntArray.get (i.e. 0) was causing item 0 to incorrectly get
  selected.

BUGS=26249027,26309874

Change-Id: I08d2e8c90bdd40a4738bdcf357de31e8fe6ddecf
parent c3c20f2b
Loading
Loading
Loading
Loading
+29 −19
Original line number Diff line number Diff line
@@ -383,6 +383,10 @@ public final class MultiSelectManager implements View.OnKeyListener {
     * @param position
     */
    void setSelectionRangeBegin(int position) {
        if (position == RecyclerView.NO_POSITION) {
            return;
        }

        if (mSelection.contains(mEnvironment.getModelIdFromAdapterPosition(position))) {
            mRanger = new Range(position);
        }
@@ -1160,13 +1164,15 @@ public final class MultiSelectManager implements View.OnKeyListener {
            mSelection.applyProvisionalSelection();
            mModel.endSelection();
            int firstSelected = mModel.getPositionNearestOrigin();
            if (!mSelection.contains(mEnvironment.getModelIdFromAdapterPosition(firstSelected))) {
                Log.w(TAG, "First selected by band is NOT in selection!");
                // Sadly this is really happening. Need to figure out what's going on.
            } else if (firstSelected != NOT_SET) {
            if (firstSelected != NOT_SET) {
                if (mSelection.contains(mEnvironment.getModelIdFromAdapterPosition(firstSelected))) {
                    // TODO: firstSelected should really be lastSelected, we want to anchor the item
                    // where the mouse-up occurred.
                    setSelectionRangeBegin(firstSelected);
                } else {
                    // TODO: Check if this is really happening.
                    Log.w(TAG, "First selected by band is NOT in selection!");
                }
            }

            mModel = null;
@@ -1558,7 +1564,10 @@ public final class MultiSelectManager implements View.OnKeyListener {
            for (int column = columnStartIndex; column <= columnEndIndex; column++) {
                SparseIntArray items = mColumns.get(mColumnBounds.get(column).lowerLimit);
                for (int row = rowStartIndex; row <= rowEndIndex; row++) {
                    int position = items.get(items.keyAt(row));
                    // The default return value for SparseIntArray.get is 0, which is a valid
                    // position. Use a sentry value to prevent erroneously selecting item 0.
                    int position = items.get(items.keyAt(row), NOT_SET);
                    if (position != NOT_SET) {
                        String id = mHelper.getModelIdFromAdapterPosition(position);
                        if (id != null) {
                            // The adapter inserts items for UI layout purposes that aren't associated
@@ -1574,6 +1583,7 @@ public final class MultiSelectManager implements View.OnKeyListener {
                    }
                }
            }
        }

        /**
         * @return Returns true if the position is the nearest to the origin, or, in the case of the