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

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

Issue 2635993002: 📰 Reset the view for items that stop being dismissable (Closed)
Patch Set: Move callback to recyclerview 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 | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java ('k') | no next file » | 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/SuggestionsSection.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java
index 0b0ed0ec58ec9a4dce1b61cb4dfe394f1aa607f7..68c846edd288becd7bd243c4eac93fff84df3f88 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java
@@ -114,7 +114,7 @@ public void offlinePageDeleted(long offlineId, ClientId clientId) {
};
mOfflinePageBridge.addObserver(mOfflinePageObserver);
- refreshChildrenVisibility();
+ mStatus.setVisible(!hasSuggestions());
}
private static class SuggestionsList extends ChildNode implements Iterable<SnippetArticle> {
@@ -240,8 +240,15 @@ public void detach() {
super.detach();
}
- private void refreshChildrenVisibility() {
- mStatus.setVisible(!hasSuggestions());
+ private void onSuggestionsListCountChanged(int oldSuggestionsCount) {
+ int newSuggestionsCount = getSuggestionsCount();
+ if ((newSuggestionsCount == 0) == (oldSuggestionsCount == 0)) return;
+
+ mStatus.setVisible(newSuggestionsCount == 0);
+
+ // When the ActionItem stops being dismissable, it is possible that it was being interacted
+ // with. We need to reset the view's related property changes.
+ mMoreButton.notifyItemChanged(0, NewTabPageRecyclerView.RESET_FOR_DISMISS_CALLBACK);
}
@Override
@@ -258,7 +265,13 @@ public void dismissItem(int position, Callback<String> itemRemovedCallback) {
@Override
public void onItemRangeRemoved(TreeNode child, int index, int count) {
super.onItemRangeRemoved(child, index, count);
- if (child == mSuggestionsList) refreshChildrenVisibility();
+ if (child == mSuggestionsList) onSuggestionsListCountChanged(getSuggestionsCount() + count);
+ }
+
+ @Override
+ public void onItemRangeInserted(TreeNode child, int index, int count) {
+ super.onItemRangeInserted(child, index, count);
+ if (child == mSuggestionsList) onSuggestionsListCountChanged(getSuggestionsCount() - count);
}
@Override
@@ -407,8 +420,6 @@ public void setSuggestions(List<SnippetArticle> suggestions, @CategoryStatusEnum
updateSnippetOfflineAvailability(article);
}
}
-
- refreshChildrenVisibility();
}
private void updateSnippetOfflineAvailability(final SnippetArticle article) {
@@ -447,7 +458,6 @@ public void onFetchStarted() {
public void setStatus(@CategoryStatusEnum int status) {
if (!SnippetsBridge.isCategoryStatusAvailable(status)) mSuggestionsList.clear();
mProgressIndicator.setVisible(SnippetsBridge.isCategoryLoading(status));
- refreshChildrenVisibility();
}
@CategoryInt
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698