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

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

Issue 2169393002: [M53] 📰Stop clearing suggestions to show the RELOAD card. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 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
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
index 217949aa121b78293dc4e0111fbf2811855e41e9..99fd54a359498fe0ce5a37d79c3f2cd2611282a0 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
@@ -50,7 +50,7 @@
private final List<NewTabPageListItem> mNewTabPageListItems;
private final ItemTouchCallbacks mItemTouchCallbacks;
private NewTabPageRecyclerView mRecyclerView;
- private boolean mWantsSnippets;
+ private int mServiceStatus;
private SnippetsBridge mSnippetsBridge;
@@ -119,7 +119,7 @@ public NewTabPageAdapter(NewTabPageManager manager, NewTabPageLayout newTabPageL
mHeaderListItem = new SnippetHeaderListItem();
mItemTouchCallbacks = new ItemTouchCallbacks();
mNewTabPageListItems = new ArrayList<NewTabPageListItem>();
- mWantsSnippets = true;
+ mServiceStatus = DisabledReason.NONE;
mSnippetsBridge = snippetsBridge;
mStatusListItem = StatusListItem.create(snippetsBridge.getDisabledReason(), this, manager);
@@ -134,7 +134,13 @@ public NewTabPageAdapter(NewTabPageManager manager, NewTabPageLayout newTabPageL
@Override
public void onSnippetsReceived(List<SnippetArticle> listSnippets) {
- if (!mWantsSnippets) return;
+ // We never want to refresh the suggestions if we already have some content.
+ if (hasSuggestions()) return;
+
+ if (!(mServiceStatus == DisabledReason.NONE
+ || mServiceStatus == DisabledReason.HISTORY_SYNC_STATE_UNKNOWN)) {
+ return;
+ }
int newSnippetCount = listSnippets.size();
Log.d(TAG, "Received %d new snippets.", newSnippetCount);
@@ -144,8 +150,6 @@ public void onSnippetsReceived(List<SnippetArticle> listSnippets) {
loadSnippets(listSnippets);
- // We don't want to get notified of other changes.
- mWantsSnippets = false;
NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_SHOWN);
}
@@ -154,18 +158,23 @@ public void onDisabledReasonChanged(int disabledReason) {
// Observers should not be registered for that state
assert disabledReason != DisabledReason.EXPLICITLY_DISABLED;
- mStatusListItem = StatusListItem.create(disabledReason, this, mNewTabPageManager);
- if (getItemCount() > 4 /* above-the-fold + header + card + spacing */) {
+ mServiceStatus = disabledReason;
+ mStatusListItem = StatusListItem.create(mServiceStatus, this, mNewTabPageManager);
+
+ // We had suggestions but we just got notified about the service being enabled. Nothing to
+ // do then.
+ if (disabledReason == DisabledReason.NONE && hasSuggestions()) return;
+
+ if (hasSuggestions()) {
// We had many items, implies that the service was previously enabled and just
- // transitioned. to a disabled state. We now clear it.
+ // transitioned to a disabled state. We now clear it.
loadSnippets(new ArrayList<SnippetArticle>());
} else {
mNewTabPageListItems.set(FIRST_CARD_POSITION, mStatusListItem);
- notifyItemRangeChanged(FIRST_CARD_POSITION, 2); // Update both the first card and the
- // spacing item coming after it.
- }
- if (disabledReason == DisabledReason.NONE) mWantsSnippets = true;
+ // Update both the first card and the spacing item coming after it.
+ notifyItemRangeChanged(FIRST_CARD_POSITION, 2);
+ }
}
@Override
@@ -213,7 +222,6 @@ public int getItemCount() {
/** Start a request for new snippets. */
public void reloadSnippets() {
- mWantsSnippets = true;
SnippetsBridge.fetchSnippets();
}
@@ -292,6 +300,11 @@ private void addStatusCardIfNecessary() {
}
}
+ /** Returns whether we have some suggested content to display. */
+ private boolean hasSuggestions() {
+ return getItemViewType(FIRST_CARD_POSITION) == NewTabPageListItem.VIEW_TYPE_SNIPPET;
+ }
+
List<NewTabPageListItem> getItemsForTesting() {
return mNewTabPageListItems;
}

Powered by Google App Engine
This is Rietveld 408576698