Chromium Code Reviews| Index: ios/showcase/content_suggestions/sc_content_suggestions_data_source.mm |
| diff --git a/ios/showcase/content_suggestions/sc_content_suggestions_data_source.mm b/ios/showcase/content_suggestions/sc_content_suggestions_data_source.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f2b031cb4d8048ab1cf0d15e7c19ae5fd1d3426c |
| --- /dev/null |
| +++ b/ios/showcase/content_suggestions/sc_content_suggestions_data_source.mm |
| @@ -0,0 +1,105 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/showcase/content_suggestions/sc_content_suggestions_data_source.h" |
| + |
| +#include "base/time/time.h" |
| +#include "components/strings/grit/components_strings.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fetcher.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion_identifier.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestions_section_information.h" |
| +#include "ios/chrome/grit/ios_strings.h" |
| +#include "ui/base/l10n/l10n_util_mac.h" |
| +#include "ui/gfx/image/image.h" |
| +#include "url/gurl.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +@interface SCContentSuggestionsDataSource ()<ContentSuggestionsImageFetcher> |
| + |
| +@property(nonatomic, strong) ContentSuggestionsSectionInformation* sectionInfo; |
|
lpromero
2017/03/24 12:10:17
Comment.
gambard
2017/03/24 15:12:49
Done.
|
| + |
| +@end |
| + |
| +@implementation SCContentSuggestionsDataSource |
| + |
| +@synthesize dataSink = _dataSink; |
| +@synthesize sectionInfo = _sectionInfo; |
| + |
| +#pragma mark - ContentSuggestionsDataSource |
| + |
| +- (nonnull NSArray<ContentSuggestion*>*)allSuggestions { |
|
lpromero
2017/03/24 12:10:17
No need for nullability annotations in the impl fi
gambard
2017/03/24 15:12:49
Done.
|
| + ContentSuggestion* suggestion = [self createContentSuggestions]; |
| + suggestion.title = @"Title of the first suggestion"; |
| + suggestion.text = |
| + @"Description of the first suggestion, can span on two lines if needed."; |
| + suggestion.publisher = @"Publisher of the new"; |
| + suggestion.publishDate = base::Time::Now(); |
| + suggestion.url = GURL("http://url.of.the.first.suggestion"); |
| + return @[ suggestion ]; |
| +} |
| + |
| +- (nonnull NSArray<ContentSuggestion*>*)suggestionsForSection: |
| + (nonnull ContentSuggestionsSectionInformation*)sectionInfo { |
| + ContentSuggestion* suggestion = [self createContentSuggestions]; |
| + suggestion.title = @"Title of the first suggestions"; |
| + suggestion.text = |
| + @"Description of the first suggestion, can span on two lines if needed."; |
| + suggestion.publisher = @"Publisher of the new"; |
| + suggestion.publishDate = base::Time::Now(); |
| + suggestion.url = GURL("http://url.of.the.first.suggestion"); |
| + return @[ suggestion ]; |
| +} |
| + |
| +- (nullable id<ContentSuggestionsImageFetcher>)imageFetcher { |
| + return self; |
| +} |
| + |
| +- (void)fetchMoreSuggestionsKnowing: |
| + (nullable NSArray<ContentSuggestionIdentifier*>*)knownSuggestions |
| + fromSectionInfo: |
| + (nonnull ContentSuggestionsSectionInformation*) |
| + sectionInfo |
| + callback:(nullable MoreSuggestionsFetched)callback { |
| +} |
| + |
| +#pragma mark - ContentSuggestionsImageFetcher |
| + |
| +- (void)fetchImageForSuggestion: |
| + (ContentSuggestionIdentifier*)suggestionIdentifier |
| + callback:(void (^)(const gfx::Image&))callback { |
| + if (callback) { |
| + callback(gfx::Image([UIImage imageNamed:@"reading_list_empty_state"])); |
| + } |
| +} |
| + |
| +#pragma mark - Property |
| + |
| +- (ContentSuggestionsSectionInformation*)sectionInfo { |
| + if (!_sectionInfo) { |
| + _sectionInfo = [[ContentSuggestionsSectionInformation alloc] |
| + initWithSectionID:ContentSuggestionsSectionArticles]; |
| + _sectionInfo.title = |
| + l10n_util::GetNSString(IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER); |
| + _sectionInfo.footerTitle = |
| + l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_FOOTER_TITLE); |
| + } |
| + return _sectionInfo; |
| +} |
| + |
| +#pragma mark - Private |
| + |
| +- (ContentSuggestion*)createContentSuggestions { |
| + ContentSuggestion* suggestion = [[ContentSuggestion alloc] init]; |
| + suggestion.type = ContentSuggestionTypeArticle; |
| + suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init]; |
| + suggestion.suggestionIdentifier.sectionInfo = self.sectionInfo; |
| + return suggestion; |
| +} |
| + |
| +@end |