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

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

Issue 2749893003: Add More action to Content Suggestions (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 83866cc2b435f2d28cee5b235171caf7f5b8dad3..ee0f2048beb7027c49dbde1da124275bd466a787 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
@@ -16,6 +16,7 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_source.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandable_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_item.h"
+#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fetcher.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_information.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_item.h"
@@ -37,6 +38,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeExpand,
ItemTypeStack,
ItemTypeFavicon,
+ ItemTypeFooter,
};
typedef NS_ENUM(NSInteger, SectionIdentifier) {
@@ -244,6 +246,8 @@ SectionIdentifier SectionIdentifierForInfo(
[model addSectionWithIdentifier:sectionIdentifier];
self.sectionInfoBySectionIdentifier[@(sectionIdentifier)] = sectionInfo;
[indexSet addIndex:[model sectionForSectionIdentifier:sectionIdentifier]];
+
+ [self addFooterIfNeeded:suggestion.suggestionIdentifier.sectionInfo];
}
}
return indexSet;
@@ -281,6 +285,28 @@ SectionIdentifier SectionIdentifierForInfo(
#pragma mark - Private methods
+// Adds a footer to the section identified by |sectionInfo| if there is none
+// present and the section info contains a title for it.
+- (void)addFooterIfNeeded:(ContentSuggestionsSectionInformation*)sectionInfo {
+ NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
+
+ __weak ContentSuggestionsCollectionUpdater* weakSelf = self;
+ if (sectionInfo.footerTitle &&
+ ![self.collectionViewController.collectionViewModel
+ footerForSectionWithIdentifier:sectionIdentifier]) {
+ ContentSuggestionsFooterItem* footer = [[ContentSuggestionsFooterItem alloc]
+ initWithType:ItemTypeFooter
+ title:sectionInfo.footerTitle
+ block:^{
+ [weakSelf runAdditionalActionForSection:sectionInfo];
+ }];
+
+ [self.collectionViewController.collectionViewModel
+ setFooter:footer
+ forSectionWithIdentifier:sectionIdentifier];
+ }
+}
+
// Resets the models, removing the current CollectionViewItem and the
// SectionInfo.
- (void)resetModels {
@@ -288,4 +314,35 @@ SectionIdentifier SectionIdentifierForInfo(
self.sectionInfoBySectionIdentifier = [[NSMutableDictionary alloc] init];
}
+// Runs the additional action for the section identified by |sectionInfo|.
+- (void)runAdditionalActionForSection:
+ (ContentSuggestionsSectionInformation*)sectionInfo {
+ SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
+
+ NSMutableArray<ContentSuggestionIdentifier*>* knownSuggestionIdentifiers =
+ [NSMutableArray array];
+
+ NSArray<CollectionViewItem<ContentSuggestionIdentification>*>*
+ knownSuggestions = [self.collectionViewController.collectionViewModel
+ itemsInSectionWithIdentifier:sectionIdentifier];
+ for (CollectionViewItem<ContentSuggestionIdentification>* suggestion in
+ knownSuggestions) {
+ [knownSuggestionIdentifiers addObject:suggestion.suggestionIdentifier];
+ }
+
+ __weak ContentSuggestionsCollectionUpdater* weakSelf = self;
+ [self.dataSource
+ fetchMoreSuggestionsKnowing:knownSuggestionIdentifiers
+ fromSectionInfo:sectionInfo
+ callback:^(NSArray<ContentSuggestion*>* suggestions) {
+ [weakSelf moreSuggestionsFetched:suggestions];
+ }];
+}
+
+// Adds the |suggestions| to the collection view. All the suggestions must have
+// the same sectionInfo.
+- (void)moreSuggestionsFetched:(NSArray<ContentSuggestion*>*)suggestions {
+ [self.collectionViewController addSuggestions:suggestions];
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698