Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3337)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ChildNode.java

Issue 2658163003: [Android NTP] Cache number of items under child nodes (Closed)
Patch Set: review Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/InnerNode.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ChildNode.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ChildNode.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ChildNode.java
index 79344e1f4eec3fef45558f8e9c30cf29ecc9e7f8..585082cae81fa136d22d1f02e963ac3ae35ebb1f 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ChildNode.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ChildNode.java
@@ -13,10 +13,10 @@ import android.support.annotation.CallSuper;
*/
public abstract class ChildNode implements TreeNode {
private NodeParent mParent;
+ private int mNumItems = 0;
@Override
- @CallSuper
- public void setParent(NodeParent parent) {
+ public final void setParent(NodeParent parent) {
assert mParent == null;
assert parent != null;
mParent = parent;
@@ -29,6 +29,12 @@ public abstract class ChildNode implements TreeNode {
mParent = null;
}
+ @Override
+ public final int getItemCount() {
+ assert mNumItems == getItemCountForDebugging();
+ return mNumItems;
+ }
+
protected void notifyItemRangeChanged(int index, int count, Object payload) {
if (mParent != null) mParent.onItemRangeChanged(this, index, count, payload);
}
@@ -38,10 +44,14 @@ public abstract class ChildNode implements TreeNode {
}
protected void notifyItemRangeInserted(int index, int count) {
+ mNumItems += count;
+ assert mNumItems == getItemCountForDebugging();
if (mParent != null) mParent.onItemRangeInserted(this, index, count);
}
protected void notifyItemRangeRemoved(int index, int count) {
+ mNumItems -= count;
+ assert mNumItems == getItemCountForDebugging();
if (mParent != null) mParent.onItemRangeRemoved(this, index, count);
}
@@ -66,4 +76,12 @@ public abstract class ChildNode implements TreeNode {
throw new IndexOutOfBoundsException(position + "/" + getItemCount());
}
}
+
+ /**
+ * @return The actual (non-cached) number of items under this node. The implementation of this
+ * method should not rely on {@link #getItemCount}, but instead derive the number of items
+ * directly from the underlying data model. Any time this value changes, an appropriate
+ * notification should be sent.
+ */
+ protected abstract int getItemCountForDebugging();
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/InnerNode.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698