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

Unified Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm

Issue 2751653008: Add header for the Content Suggestions (Closed)
Patch Set: Address comment Created 3 years, 9 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 | ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm
diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm
index ee0f2048beb7027c49dbde1da124275bd466a787..2443888b73e5a5b07393c9f65d10368be682dc07 100644
--- a/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm
+++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/time/time.h"
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
@@ -39,6 +40,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeStack,
ItemTypeFavicon,
ItemTypeFooter,
+ ItemTypeHeader,
};
typedef NS_ENUM(NSInteger, SectionIdentifier) {
@@ -166,8 +168,13 @@ SectionIdentifier SectionIdentifierForInfo(
- (void)reloadAllData {
[self resetModels];
- [self.collectionViewController
- addSuggestions:[self.dataSource allSuggestions]];
+
+ // The data is reset, add the new data directly in the model then reload the
+ // collection.
+ NSArray<ContentSuggestion*>* suggestions = [self.dataSource allSuggestions];
+ [self addSectionsForSuggestionsToModel:suggestions];
+ [self addSuggestionsToModel:suggestions];
+ [self.collectionViewController.collectionView reloadData];
}
- (void)clearSection:(ContentSuggestionsSectionInformation*)sectionInfo {
@@ -247,6 +254,7 @@ SectionIdentifier SectionIdentifierForInfo(
self.sectionInfoBySectionIdentifier[@(sectionIdentifier)] = sectionInfo;
[indexSet addIndex:[model sectionForSectionIdentifier:sectionIdentifier]];
+ [self addHeader:suggestion.suggestionIdentifier.sectionInfo];
[self addFooterIfNeeded:suggestion.suggestionIdentifier.sectionInfo];
}
}
@@ -307,6 +315,21 @@ SectionIdentifier SectionIdentifierForInfo(
}
}
+// Adds the header corresponding to |sectionInfo| to the section.
+- (void)addHeader:(ContentSuggestionsSectionInformation*)sectionInfo {
+ NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
+
+ if (![self.collectionViewController.collectionViewModel
+ headerForSectionWithIdentifier:sectionIdentifier]) {
+ CollectionViewTextItem* header =
+ [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
+ header.text = sectionInfo.title;
+ [self.collectionViewController.collectionViewModel
+ setHeader:header
+ forSectionWithIdentifier:sectionIdentifier];
+ }
+}
+
// Resets the models, removing the current CollectionViewItem and the
// SectionInfo.
- (void)resetModels {
« no previous file with comments | « no previous file | ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698