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

Commit 72f88260 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4407698 from c4a2e69e to pi-release

Change-Id: I9db8621caf0918ce0a6e8bba52a10bfc76a3850c
parents 7c3dca52 c4a2e69e
Loading
Loading
Loading
Loading
+26 −18
Original line number Diff line number Diff line
@@ -343,6 +343,9 @@ public final class DefaultSelectionHelper extends SelectionHelper {
    }

    private void onDataSetChanged() {
        // Update the selection to remove any disappeared IDs.
        mSelection.clearProvisionalSelection();
        mSelection.intersect(mStableIds.getStableIds());
        notifySelectionReset();

        for (String id : mSelection) {
@@ -359,6 +362,27 @@ public final class DefaultSelectionHelper extends SelectionHelper {
                }
            }
        }
        notifySelectionChanged();
    }

    private void onDataSetItemRangeInserted(int startPosition, int itemCount) {
        mSelection.clearProvisionalSelection();
    }

    private void onDataSetItemRangeRemoved(int startPosition, int itemCount) {
        checkArgument(startPosition >= 0);
        checkArgument(itemCount > 0);

        mSelection.clearProvisionalSelection();

        // Remove any disappeared IDs from the selection.
        //
        // Ideally there could be a cheaper approach, checking
        // each position individually, but since the source of
        // truth for stable ids (StableIdProvider) probably
        // it-self no-longer knows about the positions in question
        // we fall back to the sledge hammer approach.
        mSelection.intersect(mStableIds.getStableIds());
    }

    /**
@@ -483,10 +507,6 @@ public final class DefaultSelectionHelper extends SelectionHelper {
    private final class AdapterObserver extends RecyclerView.AdapterDataObserver {
        @Override
        public void onChanged() {
            // Update the selection to remove any disappeared IDs.
            mSelection.clearProvisionalSelection();
            mSelection.intersect(mStableIds.getStableIds());

            onDataSetChanged();
        }

@@ -501,24 +521,12 @@ public final class DefaultSelectionHelper extends SelectionHelper {

        @Override
        public void onItemRangeInserted(int startPosition, int itemCount) {
            mSelection.clearProvisionalSelection();
            onDataSetItemRangeInserted(startPosition, itemCount);
        }

        @Override
        public void onItemRangeRemoved(int startPosition, int itemCount) {
            checkArgument(startPosition >= 0);
            checkArgument(itemCount > 0);

            mSelection.clearProvisionalSelection();

            // Remove any disappeared IDs from the selection.
            //
            // Ideally there could be a cheaper approach, checking
            // each position individually, but since the source of
            // truth for stable ids (StableIdProvider) probably
            // it-self no-longer knows about the positions in question
            // we fall back to the sledge hammer approach.
            mSelection.intersect(mStableIds.getStableIds());
            onDataSetItemRangeRemoved(startPosition, itemCount);
        }

        @Override
+7 −1
Original line number Diff line number Diff line
@@ -111,7 +111,6 @@ public class DefaultSelectionHelperTest {
        mListener.assertSelectionChanged();
    }


    @Test
    public void testSelect_NotifiesAdapterOfSelect() {
        mHelper.select(mItems.get(7));
@@ -382,6 +381,13 @@ public class DefaultSelectionHelperTest {
        mSelection.assertSelection(1, 2, 3);
    }

    @Test
    public void testObserverOnChanged_NotifiesListenersOfChange() {
        mAdapter.notifyDataSetChanged();

        mListener.assertSelectionChanged();
    }

    private Set<String> getItemIds(SparseBooleanArray selection) {
        Set<String> ids = new HashSet<>();