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

Side by Side Diff: ios/showcase/content_suggestions/sc_content_suggestions_data_source.mm

Issue 2769063005: Add CSDataSource in showcase (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/showcase/content_suggestions/sc_content_suggestions_data_source.h"
6
7 #include "base/time/time.h"
8 #include "components/strings/grit/components_strings.h"
9 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
10 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h"
11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet cher.h"
12 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
13 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h"
14 #include "ios/chrome/grit/ios_strings.h"
15 #include "ui/base/l10n/l10n_util_mac.h"
16 #include "ui/gfx/image/image.h"
17 #include "url/gurl.h"
18
19 #if !defined(__has_feature) || !__has_feature(objc_arc)
20 #error "This file requires ARC support."
21 #endif
22
23 @interface SCContentSuggestionsDataSource ()<ContentSuggestionsImageFetcher>
24
25 @property(nonatomic, strong) ContentSuggestionsSectionInformation* sectionInfo;
lpromero 2017/03/24 12:10:17 Comment.
gambard 2017/03/24 15:12:49 Done.
26
27 @end
28
29 @implementation SCContentSuggestionsDataSource
30
31 @synthesize dataSink = _dataSink;
32 @synthesize sectionInfo = _sectionInfo;
33
34 #pragma mark - ContentSuggestionsDataSource
35
36 - (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.
37 ContentSuggestion* suggestion = [self createContentSuggestions];
38 suggestion.title = @"Title of the first suggestion";
39 suggestion.text =
40 @"Description of the first suggestion, can span on two lines if needed.";
41 suggestion.publisher = @"Publisher of the new";
42 suggestion.publishDate = base::Time::Now();
43 suggestion.url = GURL("http://url.of.the.first.suggestion");
44 return @[ suggestion ];
45 }
46
47 - (nonnull NSArray<ContentSuggestion*>*)suggestionsForSection:
48 (nonnull ContentSuggestionsSectionInformation*)sectionInfo {
49 ContentSuggestion* suggestion = [self createContentSuggestions];
50 suggestion.title = @"Title of the first suggestions";
51 suggestion.text =
52 @"Description of the first suggestion, can span on two lines if needed.";
53 suggestion.publisher = @"Publisher of the new";
54 suggestion.publishDate = base::Time::Now();
55 suggestion.url = GURL("http://url.of.the.first.suggestion");
56 return @[ suggestion ];
57 }
58
59 - (nullable id<ContentSuggestionsImageFetcher>)imageFetcher {
60 return self;
61 }
62
63 - (void)fetchMoreSuggestionsKnowing:
64 (nullable NSArray<ContentSuggestionIdentifier*>*)knownSuggestions
65 fromSectionInfo:
66 (nonnull ContentSuggestionsSectionInformation*)
67 sectionInfo
68 callback:(nullable MoreSuggestionsFetched)callback {
69 }
70
71 #pragma mark - ContentSuggestionsImageFetcher
72
73 - (void)fetchImageForSuggestion:
74 (ContentSuggestionIdentifier*)suggestionIdentifier
75 callback:(void (^)(const gfx::Image&))callback {
76 if (callback) {
77 callback(gfx::Image([UIImage imageNamed:@"reading_list_empty_state"]));
78 }
79 }
80
81 #pragma mark - Property
82
83 - (ContentSuggestionsSectionInformation*)sectionInfo {
84 if (!_sectionInfo) {
85 _sectionInfo = [[ContentSuggestionsSectionInformation alloc]
86 initWithSectionID:ContentSuggestionsSectionArticles];
87 _sectionInfo.title =
88 l10n_util::GetNSString(IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER);
89 _sectionInfo.footerTitle =
90 l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_FOOTER_TITLE);
91 }
92 return _sectionInfo;
93 }
94
95 #pragma mark - Private
96
97 - (ContentSuggestion*)createContentSuggestions {
98 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
99 suggestion.type = ContentSuggestionTypeArticle;
100 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
101 suggestion.suggestionIdentifier.sectionInfo = self.sectionInfo;
102 return suggestion;
103 }
104
105 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698