Loading src/com/android/documentsui/selection/DefaultSelectionHelper.java +26 −18 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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()); } /** Loading Loading @@ -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(); } Loading @@ -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 Loading tests/unit/com/android/documentsui/selection/DefaultSelectionHelperTest.java +7 −1 Original line number Diff line number Diff line Loading @@ -111,7 +111,6 @@ public class DefaultSelectionHelperTest { mListener.assertSelectionChanged(); } @Test public void testSelect_NotifiesAdapterOfSelect() { mHelper.select(mItems.get(7)); Loading Loading @@ -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<>(); Loading Loading
src/com/android/documentsui/selection/DefaultSelectionHelper.java +26 −18 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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()); } /** Loading Loading @@ -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(); } Loading @@ -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 Loading
tests/unit/com/android/documentsui/selection/DefaultSelectionHelperTest.java +7 −1 Original line number Diff line number Diff line Loading @@ -111,7 +111,6 @@ public class DefaultSelectionHelperTest { mListener.assertSelectionChanged(); } @Test public void testSelect_NotifiesAdapterOfSelect() { mHelper.select(mItems.get(7)); Loading Loading @@ -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<>(); Loading