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

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

Issue 2739153002: Reload all ContentSuggestions on notification (Closed)
Patch Set: Rebase 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
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 d7204595f08fce6a632e2edfe45f59b3e1866a7f..273dc3f6f2e87a36f134715b6a73ff27b1051a6f 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
@@ -87,8 +87,6 @@ SectionIdentifier SectionIdentifierForInfo(
NSMutableDictionary<NSNumber*, ContentSuggestionsSectionInformation*>*
sectionInfoBySectionIdentifier;
-// Reloads all the data from the data source, deleting all the current items.
-- (void)reloadData;
// Adds a new section if needed and returns the section identifier.
- (NSInteger)addSectionIfNeeded:
(ContentSuggestionsSectionInformation*)sectionInformation;
@@ -120,13 +118,13 @@ SectionIdentifier SectionIdentifierForInfo(
(ContentSuggestionsViewController*)collectionViewController {
_collectionViewController = collectionViewController;
- [self reloadData];
+ [self reloadAllData];
}
#pragma mark - ContentSuggestionsDataSink
- (void)dataAvailable {
- [self reloadData];
+ [self reloadAllData];
}
- (void)clearSuggestion:(ContentSuggestionIdentifier*)suggestionIdentifier {
@@ -159,6 +157,37 @@ SectionIdentifier SectionIdentifierForInfo(
[self.collectionViewController dismissEntryAtIndexPath:indexPath];
}
+- (void)reloadAllData {
+ [self resetModels];
+ CollectionViewModel* model =
+ self.collectionViewController.collectionViewModel;
+
+ NSArray<ContentSuggestion*>* suggestions = [self.dataSource allSuggestions];
+
+ for (ContentSuggestion* suggestion in suggestions) {
+ NSInteger sectionIdentifier =
+ [self addSectionIfNeeded:suggestion.suggestionIdentifier.sectionInfo];
+ ContentSuggestionsArticleItem* articleItem =
+ [[ContentSuggestionsArticleItem alloc]
+ initWithType:ItemTypeForContentSuggestionType(suggestion.type)
+ title:suggestion.title
+ subtitle:suggestion.text
+ delegate:self
+ url:suggestion.url];
+
+ articleItem.publisher = suggestion.publisher;
+ articleItem.publishDate = suggestion.publishDate;
+
+ articleItem.suggestionIdentifier = suggestion.suggestionIdentifier;
+
+ [model addItem:articleItem toSectionWithIdentifier:sectionIdentifier];
+ }
+
+ if ([self.collectionViewController isViewLoaded]) {
+ [self.collectionViewController.collectionView reloadData];
+ }
+}
+
#pragma mark - Public methods
- (BOOL)shouldUseCustomStyleForSection:(NSInteger)section {
@@ -206,37 +235,6 @@ SectionIdentifier SectionIdentifierForInfo(
#pragma mark - Private methods
-- (void)reloadData {
- [self resetModels];
- CollectionViewModel* model =
- self.collectionViewController.collectionViewModel;
-
- NSArray<ContentSuggestion*>* suggestions = [self.dataSource allSuggestions];
-
- for (ContentSuggestion* suggestion in suggestions) {
- NSInteger sectionIdentifier =
- [self addSectionIfNeeded:suggestion.suggestionIdentifier.sectionInfo];
- ContentSuggestionsArticleItem* articleItem =
- [[ContentSuggestionsArticleItem alloc]
- initWithType:ItemTypeForContentSuggestionType(suggestion.type)
- title:suggestion.title
- subtitle:suggestion.text
- delegate:self
- url:suggestion.url];
-
- articleItem.publisher = suggestion.publisher;
- articleItem.publishDate = suggestion.publishDate;
-
- articleItem.suggestionIdentifier = suggestion.suggestionIdentifier;
-
- [model addItem:articleItem toSectionWithIdentifier:sectionIdentifier];
- }
-
- if ([self.collectionViewController isViewLoaded]) {
- [self.collectionViewController.collectionView reloadData];
- }
-}
-
- (NSInteger)addSectionIfNeeded:
(ContentSuggestionsSectionInformation*)sectionInformation {
NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInformation);

Powered by Google App Engine
This is Rietveld 408576698