@Test public void testAfterChangeOrder_orderIsChangeIsNotified1() throws Exception { detector.newData(adapter, ImmutableList.of(new Cat(0), new Cat(1)), false); reset(adapter); detector.newData(adapter, ImmutableList.of(new Cat(1), new Cat(0)), false); verify(adapter).notifyItemMoved(1, 0); verifyNoMoreInteractions(adapter); }
public void newData(@Nonnull ChangesAdapter adapter, @Nonnull List<? extends T> values, boolean force) { checkNotNull(adapter); checkNotNull(values); final H[] list = apply(values); final ArrayList<H> objects = new ArrayList<H>(mItems.length); Collections.addAll(objects, mItems); clearState(); int offset = 0; int successPosition = 0; for (; successPosition < list.length; ) { final H item = list[successPosition]; final int i = indexOfItem(objects, offset, item); if (i < 0) { executeAction(adapter, ACTION_INSERT, offset); objects.add(offset, item); offset += 1; successPosition += 1; } else if (i == offset) { if (force || !mDetector.same(item, objects.get(offset))) { executeAction(adapter, ACTION_CHANGED, offset); } else { executeAction(adapter, ACTION_NONE, -1); } offset += 1; successPosition += 1; } else { final H first = objects.get(offset); if (existInList(list, successPosition + 1, first)) { executeAction(adapter, ACTION_NONE, -1); adapter.notifyItemMoved(i, offset); if (force || !mDetector.same(item, objects.get(i))) { executeAction(adapter, ACTION_CHANGED, offset); } objects.add(offset, objects.remove(i)); offset += 1; successPosition += 1; } else { executeAction(adapter, ACTION_REMOVE, offset); objects.remove(0); } } } executeAction(adapter, ACTION_NONE, -1); final int realSize = objects.size(); if (realSize > list.length) { adapter.notifyItemRangeRemoved(offset, realSize - list.length); objects.clear(); } mItems = list; }
ChangesDetector { public void newData(@Nonnull ChangesAdapter adapter, @Nonnull List<? extends T> values, boolean force) { checkNotNull(adapter); checkNotNull(values); final H[] list = apply(values); final ArrayList<H> objects = new ArrayList<H>(mItems.length); Collections.addAll(objects, mItems); clearState(); int offset = 0; int successPosition = 0; for (; successPosition < list.length; ) { final H item = list[successPosition]; final int i = indexOfItem(objects, offset, item); if (i < 0) { executeAction(adapter, ACTION_INSERT, offset); objects.add(offset, item); offset += 1; successPosition += 1; } else if (i == offset) { if (force || !mDetector.same(item, objects.get(offset))) { executeAction(adapter, ACTION_CHANGED, offset); } else { executeAction(adapter, ACTION_NONE, -1); } offset += 1; successPosition += 1; } else { final H first = objects.get(offset); if (existInList(list, successPosition + 1, first)) { executeAction(adapter, ACTION_NONE, -1); adapter.notifyItemMoved(i, offset); if (force || !mDetector.same(item, objects.get(i))) { executeAction(adapter, ACTION_CHANGED, offset); } objects.add(offset, objects.remove(i)); offset += 1; successPosition += 1; } else { executeAction(adapter, ACTION_REMOVE, offset); objects.remove(0); } } } executeAction(adapter, ACTION_NONE, -1); final int realSize = objects.size(); if (realSize > list.length) { adapter.notifyItemRangeRemoved(offset, realSize - list.length); objects.clear(); } mItems = list; } }
ChangesDetector { public void newData(@Nonnull ChangesAdapter adapter, @Nonnull List<? extends T> values, boolean force) { checkNotNull(adapter); checkNotNull(values); final H[] list = apply(values); final ArrayList<H> objects = new ArrayList<H>(mItems.length); Collections.addAll(objects, mItems); clearState(); int offset = 0; int successPosition = 0; for (; successPosition < list.length; ) { final H item = list[successPosition]; final int i = indexOfItem(objects, offset, item); if (i < 0) { executeAction(adapter, ACTION_INSERT, offset); objects.add(offset, item); offset += 1; successPosition += 1; } else if (i == offset) { if (force || !mDetector.same(item, objects.get(offset))) { executeAction(adapter, ACTION_CHANGED, offset); } else { executeAction(adapter, ACTION_NONE, -1); } offset += 1; successPosition += 1; } else { final H first = objects.get(offset); if (existInList(list, successPosition + 1, first)) { executeAction(adapter, ACTION_NONE, -1); adapter.notifyItemMoved(i, offset); if (force || !mDetector.same(item, objects.get(i))) { executeAction(adapter, ACTION_CHANGED, offset); } objects.add(offset, objects.remove(i)); offset += 1; successPosition += 1; } else { executeAction(adapter, ACTION_REMOVE, offset); objects.remove(0); } } } executeAction(adapter, ACTION_NONE, -1); final int realSize = objects.size(); if (realSize > list.length) { adapter.notifyItemRangeRemoved(offset, realSize - list.length); objects.clear(); } mItems = list; } ChangesDetector(@Nonnull Detector<T, H> detector); }
ChangesDetector { public void newData(@Nonnull ChangesAdapter adapter, @Nonnull List<? extends T> values, boolean force) { checkNotNull(adapter); checkNotNull(values); final H[] list = apply(values); final ArrayList<H> objects = new ArrayList<H>(mItems.length); Collections.addAll(objects, mItems); clearState(); int offset = 0; int successPosition = 0; for (; successPosition < list.length; ) { final H item = list[successPosition]; final int i = indexOfItem(objects, offset, item); if (i < 0) { executeAction(adapter, ACTION_INSERT, offset); objects.add(offset, item); offset += 1; successPosition += 1; } else if (i == offset) { if (force || !mDetector.same(item, objects.get(offset))) { executeAction(adapter, ACTION_CHANGED, offset); } else { executeAction(adapter, ACTION_NONE, -1); } offset += 1; successPosition += 1; } else { final H first = objects.get(offset); if (existInList(list, successPosition + 1, first)) { executeAction(adapter, ACTION_NONE, -1); adapter.notifyItemMoved(i, offset); if (force || !mDetector.same(item, objects.get(i))) { executeAction(adapter, ACTION_CHANGED, offset); } objects.add(offset, objects.remove(i)); offset += 1; successPosition += 1; } else { executeAction(adapter, ACTION_REMOVE, offset); objects.remove(0); } } } executeAction(adapter, ACTION_NONE, -1); final int realSize = objects.size(); if (realSize > list.length) { adapter.notifyItemRangeRemoved(offset, realSize - list.length); objects.clear(); } mItems = list; } ChangesDetector(@Nonnull Detector<T, H> detector); void newData(@Nonnull ChangesAdapter adapter,
                        @Nonnull List<? extends T> values,
                        boolean force); }
ChangesDetector { public void newData(@Nonnull ChangesAdapter adapter, @Nonnull List<? extends T> values, boolean force) { checkNotNull(adapter); checkNotNull(values); final H[] list = apply(values); final ArrayList<H> objects = new ArrayList<H>(mItems.length); Collections.addAll(objects, mItems); clearState(); int offset = 0; int successPosition = 0; for (; successPosition < list.length; ) { final H item = list[successPosition]; final int i = indexOfItem(objects, offset, item); if (i < 0) { executeAction(adapter, ACTION_INSERT, offset); objects.add(offset, item); offset += 1; successPosition += 1; } else if (i == offset) { if (force || !mDetector.same(item, objects.get(offset))) { executeAction(adapter, ACTION_CHANGED, offset); } else { executeAction(adapter, ACTION_NONE, -1); } offset += 1; successPosition += 1; } else { final H first = objects.get(offset); if (existInList(list, successPosition + 1, first)) { executeAction(adapter, ACTION_NONE, -1); adapter.notifyItemMoved(i, offset); if (force || !mDetector.same(item, objects.get(i))) { executeAction(adapter, ACTION_CHANGED, offset); } objects.add(offset, objects.remove(i)); offset += 1; successPosition += 1; } else { executeAction(adapter, ACTION_REMOVE, offset); objects.remove(0); } } } executeAction(adapter, ACTION_NONE, -1); final int realSize = objects.size(); if (realSize > list.length) { adapter.notifyItemRangeRemoved(offset, realSize - list.length); objects.clear(); } mItems = list; } ChangesDetector(@Nonnull Detector<T, H> detector); void newData(@Nonnull ChangesAdapter adapter,
                        @Nonnull List<? extends T> values,
                        boolean force);  }