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

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

Issue 2166753003: 📰 Stop clearing suggestions to show the RELOAD card. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments 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
« no previous file with comments | « no previous file | chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.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/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 69ccca4556404bf62277b00a7ce2326223eb1f7f..78e85e47a85fee6de3296c0055850b7117fe92fb 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<SnippetArticleListItem> 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<SnippetArticleListItem> 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
tschumann 2016/07/22 08:58:57 I wonder if we should verify the bit "was previous
Philipp Keck 2016/07/22 09:07:28 FYI: My upcoming CL replaces DisabledReason with C
dgn 2016/07/22 09:47:14 We already check above (l166) that we are in the e
tschumann 2016/07/22 10:00:51 ok, given that Philipp is changing this anyways, l
dgn 2016/07/22 10:10:30 Ok, I'll look at his CL after the merge to see how
- // transitioned. to a disabled state. We now clear it.
+ // transitioned to a disabled state. We now clear it.
loadSnippets(new ArrayList<SnippetArticleListItem>());
} 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
@@ -214,7 +223,6 @@ public int getItemCount() {
/** Start a request for new snippets. */
public void reloadSnippets() {
- mWantsSnippets = true;
SnippetsBridge.fetchSnippets();
}
@@ -294,6 +302,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;
}
« no previous file with comments | « no previous file | chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698