Commit 663bdb21 authored by gambard's avatar gambard Committed by Commit bot

Add header for the Content Suggestions

This CL adds headers for the Content Suggestions sections.

BUG=702236

Review-Url: https://codereview.chromium.org/2751653008
Cr-Commit-Position: refs/heads/master@{#457738}
parent e46faca0
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/time/time.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_controller.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h" #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
...@@ -39,6 +40,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -39,6 +40,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeStack, ItemTypeStack,
ItemTypeFavicon, ItemTypeFavicon,
ItemTypeFooter, ItemTypeFooter,
ItemTypeHeader,
}; };
typedef NS_ENUM(NSInteger, SectionIdentifier) { typedef NS_ENUM(NSInteger, SectionIdentifier) {
...@@ -166,8 +168,13 @@ SectionIdentifier SectionIdentifierForInfo( ...@@ -166,8 +168,13 @@ SectionIdentifier SectionIdentifierForInfo(
- (void)reloadAllData { - (void)reloadAllData {
[self resetModels]; [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 { - (void)clearSection:(ContentSuggestionsSectionInformation*)sectionInfo {
...@@ -247,6 +254,7 @@ SectionIdentifier SectionIdentifierForInfo( ...@@ -247,6 +254,7 @@ SectionIdentifier SectionIdentifierForInfo(
self.sectionInfoBySectionIdentifier[@(sectionIdentifier)] = sectionInfo; self.sectionInfoBySectionIdentifier[@(sectionIdentifier)] = sectionInfo;
[indexSet addIndex:[model sectionForSectionIdentifier:sectionIdentifier]]; [indexSet addIndex:[model sectionForSectionIdentifier:sectionIdentifier]];
[self addHeader:suggestion.suggestionIdentifier.sectionInfo];
[self addFooterIfNeeded:suggestion.suggestionIdentifier.sectionInfo]; [self addFooterIfNeeded:suggestion.suggestionIdentifier.sectionInfo];
} }
} }
...@@ -307,6 +315,21 @@ SectionIdentifier SectionIdentifierForInfo( ...@@ -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 // Resets the models, removing the current CollectionViewItem and the
// SectionInfo. // SectionInfo.
- (void)resetModels { - (void)resetModels {
......
...@@ -7,12 +7,10 @@ ...@@ -7,12 +7,10 @@
#import "base/ios/block_types.h" #import "base/ios/block_types.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestion_identifier.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h" #import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
// Item for a footer of a Content Suggestions section. // Item for a footer of a Content Suggestions section.
@interface ContentSuggestionsFooterItem @interface ContentSuggestionsFooterItem : CollectionViewItem
: CollectionViewItem<ContentSuggestionIdentification>
// Initialize a footer with a button taking all the space, with a |title| and a // Initialize a footer with a button taking all the space, with a |title| and a
// |block| run when tapped. // |block| run when tapped.
......
...@@ -27,7 +27,6 @@ const CGFloat kMinimalCellHeight = 44; ...@@ -27,7 +27,6 @@ const CGFloat kMinimalCellHeight = 44;
@synthesize title = _title; @synthesize title = _title;
@synthesize block = _block; @synthesize block = _block;
@synthesize suggestionIdentifier = _suggestionIdentifier;
- (instancetype)initWithType:(NSInteger)type - (instancetype)initWithType:(NSInteger)type
title:(NSString*)title title:(NSString*)title
......
...@@ -184,6 +184,11 @@ const NSTimeInterval kAnimationDuration = 0.35; ...@@ -184,6 +184,11 @@ const NSTimeInterval kAnimationDuration = 0.35;
return NO; return NO;
} }
- (BOOL)collectionView:(UICollectionView*)collectionView
shouldHideHeaderBackgroundForSection:(NSInteger)section {
return YES;
}
- (CGFloat)collectionView:(UICollectionView*)collectionView - (CGFloat)collectionView:(UICollectionView*)collectionView
cellHeightAtIndexPath:(NSIndexPath*)indexPath { cellHeightAtIndexPath:(NSIndexPath*)indexPath {
CollectionViewItem* item = CollectionViewItem* item =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment