summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/widget/WidgetsDiffReporter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/widget/WidgetsDiffReporter.java')
-rw-r--r--src/com/android/launcher3/widget/WidgetsDiffReporter.java37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/com/android/launcher3/widget/WidgetsDiffReporter.java b/src/com/android/launcher3/widget/WidgetsDiffReporter.java
index 52deec32b..d67f40365 100644
--- a/src/com/android/launcher3/widget/WidgetsDiffReporter.java
+++ b/src/com/android/launcher3/widget/WidgetsDiffReporter.java
@@ -16,6 +16,7 @@
package com.android.launcher3.widget;
+import android.support.v7.widget.RecyclerView;
import android.util.Log;
import com.android.launcher3.IconCache;
@@ -26,26 +27,18 @@ import java.util.ArrayList;
import java.util.Iterator;
/**
- * Do diff on widget's tray list items and call the {@link NotifyListener} methods accordingly.
+ * Do diff on widget's tray list items and call the {@link RecyclerView.Adapter}
+ * methods accordingly.
*/
public class WidgetsDiffReporter {
- private final boolean DEBUG = false;
- private final String TAG = "WidgetsDiffReporter";
- private final IconCache mIconCache;
- private NotifyListener mListener;
+ private static final boolean DEBUG = false;
+ private static final String TAG = "WidgetsDiffReporter";
- public interface NotifyListener {
- void notifyDataSetChanged();
- void notifyItemChanged(int index);
- void notifyItemInserted(int index);
- void notifyItemRemoved(int index);
- }
+ private final IconCache mIconCache;
+ private final RecyclerView.Adapter mListener;
- public WidgetsDiffReporter(IconCache iconCache) {
+ public WidgetsDiffReporter(IconCache iconCache, RecyclerView.Adapter listener) {
mIconCache = iconCache;
- }
-
- public void setListener(NotifyListener listener) {
mListener = listener;
}
@@ -55,9 +48,17 @@ public class WidgetsDiffReporter {
Log.d(TAG, "process oldEntries#=" + currentEntries.size()
+ " newEntries#=" + newEntries.size());
}
- if (currentEntries.size() == 0 && newEntries.size() > 0) {
- currentEntries.addAll(newEntries);
- mListener.notifyDataSetChanged();
+ // Early exit if either of the list is empty
+ if (currentEntries.isEmpty() || newEntries.isEmpty()) {
+ // Skip if both list are empty.
+ // On rotation, we open the widget tray with empty. Then try to fetch the list again
+ // when the animation completes (which still gives empty). And we get the final result
+ // when the bind actually completes.
+ if (currentEntries.size() != newEntries.size()) {
+ currentEntries.clear();
+ currentEntries.addAll(newEntries);
+ mListener.notifyDataSetChanged();
+ }
return;
}
ArrayList<WidgetListRowEntry> orgEntries =