Merge "leanback: ArrayObjectAdapter.setItems() with no DiffCallback" into oc-mr1-dev
am: 0ebd974f8f
Change-Id: Ib2e6b4e46cab80eb66497a89db34225cfd94fc3e
diff --git a/v17/leanback/src/android/support/v17/leanback/widget/ArrayObjectAdapter.java b/v17/leanback/src/android/support/v17/leanback/widget/ArrayObjectAdapter.java
index 88de24c..00bc073 100644
--- a/v17/leanback/src/android/support/v17/leanback/widget/ArrayObjectAdapter.java
+++ b/v17/leanback/src/android/support/v17/leanback/widget/ArrayObjectAdapter.java
@@ -230,10 +230,17 @@
* specified position.
*
* @param itemList List of new Items
- * @param callback DiffCallback Object to compute the difference between the old data set and
- * new data set.
+ * @param callback Optional DiffCallback Object to compute the difference between the old data
+ * set and new data set. When null, {@link #notifyChanged()} will be fired.
*/
public void setItems(final List itemList, final DiffCallback callback) {
+ if (callback == null) {
+ // shortcut when DiffCallback is not provided
+ mItems.clear();
+ mItems.addAll(itemList);
+ notifyChanged();
+ return;
+ }
mOldItems.clear();
mOldItems.addAll(mItems);
diff --git a/v17/leanback/tests/java/android/support/v17/leanback/widget/ObjectAdapterTest.java b/v17/leanback/tests/java/android/support/v17/leanback/widget/ObjectAdapterTest.java
index 6ed7045..48fdbbd 100644
--- a/v17/leanback/tests/java/android/support/v17/leanback/widget/ObjectAdapterTest.java
+++ b/v17/leanback/tests/java/android/support/v17/leanback/widget/ObjectAdapterTest.java
@@ -23,6 +23,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import android.content.Context;
import android.os.Bundle;
@@ -377,6 +378,28 @@
assertTrue(mAdapter.isImmediateNotifySupported());
}
+
+ @Test
+ public void testSetItemsNoDiffCallback() {
+ mItems.add(new AdapterItem(1, "a"));
+ mItems.add(new AdapterItem(2, "b"));
+ mItems.add(new AdapterItem(3, "c"));
+ mAdapter.setItems(mItems, null);
+ Mockito.verify(mObserver, times(1)).onChanged();
+ Mockito.verify(mObserver, never()).onItemRangeInserted(anyInt(), anyInt());
+ Mockito.verify(mObserver, never()).onItemRangeRemoved(anyInt(), anyInt());
+ Mockito.verify(mObserver, never()).onItemRangeMoved(anyInt(), anyInt(), anyInt());
+
+ mItems.add(new AdapterItem(4, "a"));
+ mItems.add(new AdapterItem(5, "b"));
+ mItems.add(new AdapterItem(6, "c"));
+ mAdapter.setItems(mItems, null);
+ Mockito.verify(mObserver, times(2)).onChanged();
+ Mockito.verify(mObserver, never()).onItemRangeInserted(anyInt(), anyInt());
+ Mockito.verify(mObserver, never()).onItemRangeRemoved(anyInt(), anyInt());
+ Mockito.verify(mObserver, never()).onItemRangeMoved(anyInt(), anyInt(), anyInt());
+ }
+
/**
* The following test cases are mainly focused on the basic functionality provided by setItems
* function