Commit 7e037be1 authored by gambard's avatar gambard Committed by Commit Bot

Don't show section title if there is one section

The titles should be shown only if there are more than two sections.
This applies only to the section from ContentSuggestionsService.

Bug: 749125
Change-Id: If9d8320baa9f5cad287d47b70202cbe203f06727
Reviewed-on: https://chromium-review.googlesource.com/596050
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarJean-François Geyelin <jif@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491370}
parent 854935d9
......@@ -119,6 +119,12 @@ SectionIdentifier SectionIdentifierForInfo(
}
}
// Returns whether this |sectionIdentifier| comes from ContentSuggestions.
BOOL IsFromContentSuggestions(NSInteger sectionIdentifier) {
return sectionIdentifier == SectionIdentifierArticles ||
sectionIdentifier == SectionIdentifierReadingList;
}
const CGFloat kNumberOfMostVisitedLines = 2;
} // namespace
......@@ -133,6 +139,9 @@ const CGFloat kNumberOfMostVisitedLines = 2;
@property(nonatomic, assign) CGFloat collectionWidth;
// Whether an item of type ItemTypePromo has already been added to the model.
@property(nonatomic, assign) BOOL promoAdded;
// All SectionIdentifier from ContentSuggestions.
@property(nonatomic, strong)
NSMutableSet<NSNumber*>* sectionIdentifiersFromContentSuggestions;
@end
......@@ -143,6 +152,8 @@ const CGFloat kNumberOfMostVisitedLines = 2;
@synthesize sectionInfoBySectionIdentifier = _sectionInfoBySectionIdentifier;
@synthesize collectionWidth = _collectionWidth;
@synthesize promoAdded = _promoAdded;
@synthesize sectionIdentifiersFromContentSuggestions =
_sectionIdentifiersFromContentSuggestions;
- (instancetype)initWithDataSource:
(id<ContentSuggestionsDataSource>)dataSource {
......@@ -151,6 +162,7 @@ const CGFloat kNumberOfMostVisitedLines = 2;
_promoAdded = NO;
_dataSource = dataSource;
_dataSource.dataSink = self;
_sectionIdentifiersFromContentSuggestions = [[NSMutableSet alloc] init];
}
return self;
}
......@@ -500,22 +512,58 @@ addSuggestionsToModel:(NSArray<CSCollectionViewItem*>*)suggestions
// Adds the header corresponding to |sectionInfo| to the section if there is
// none present and the section info contains a title.
// In addition to that, if the section is for a content suggestion, only show a
// title if there are more than 1 occurence of a content suggestion section.
- (void)addHeaderIfNeeded:(ContentSuggestionsSectionInformation*)sectionInfo {
NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
if (![self.collectionViewController.collectionViewModel
headerForSectionWithIdentifier:sectionIdentifier] &&
CSCollectionViewModel* model =
self.collectionViewController.collectionViewModel;
if (![model headerForSectionWithIdentifier:sectionIdentifier] &&
sectionInfo.title) {
CollectionViewTextItem* header =
[[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
header.text = sectionInfo.title;
header.textColor = [[MDCPalette greyPalette] tint500];
[self.collectionViewController.collectionViewModel
setHeader:header
forSectionWithIdentifier:sectionIdentifier];
BOOL addHeader = YES;
if (IsFromContentSuggestions(sectionIdentifier)) {
addHeader = NO;
if ([self.sectionIdentifiersFromContentSuggestions
containsObject:@(sectionIdentifier)]) {
return;
}
if ([self.sectionIdentifiersFromContentSuggestions count] == 1) {
NSNumber* existingSectionIdentifier =
[self.sectionIdentifiersFromContentSuggestions anyObject];
ContentSuggestionsSectionInformation* existingSectionInfo =
self.sectionInfoBySectionIdentifier[existingSectionIdentifier];
[model setHeader:[self headerForSectionInfo:existingSectionInfo]
forSectionWithIdentifier:[existingSectionIdentifier integerValue]];
addHeader = YES;
} else if ([self.sectionIdentifiersFromContentSuggestions count] > 1) {
addHeader = YES;
}
[self.sectionIdentifiersFromContentSuggestions
addObject:@(sectionIdentifier)];
}
if (addHeader) {
[model setHeader:[self headerForSectionInfo:sectionInfo]
forSectionWithIdentifier:sectionIdentifier];
}
}
}
// Returns the header for this |sectionInfo|.
- (CollectionViewItem*)headerForSectionInfo:
(ContentSuggestionsSectionInformation*)sectionInfo {
CollectionViewTextItem* header =
[[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
header.text = sectionInfo.title;
header.textColor = [[MDCPalette greyPalette] tint500];
return header;
}
// Adds the header for the first section, containing the logo and the omnibox,
// if there is no header for the section.
- (void)addLogoHeaderIfNeeded {
......
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