| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h" | 5 #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h" |
| 6 | 6 |
| 7 #include "base/mac/bind_objc_block.h" | 7 #include "base/mac/bind_objc_block.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/optional.h" | 9 #include "base/optional.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "components/ntp_snippets/category.h" | 11 #include "components/ntp_snippets/category.h" |
| 12 #include "components/ntp_snippets/content_suggestion.h" | 12 #include "components/ntp_snippets/content_suggestion.h" |
| 13 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra
pper.h" | 13 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra
pper.h" |
| 14 #import "ios/chrome/browser/content_suggestions/content_suggestions_service_brid
ge_observer.h" | 14 #import "ios/chrome/browser/content_suggestions/content_suggestions_service_brid
ge_observer.h" |
| 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" | 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
| 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion_identifier
.h" | 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion_identifier
.h" |
| 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" | 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" |
| 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet
cher.h" | 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet
cher.h" |
| 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i
nformation.h" | 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i
nformation.h" |
| 20 #include "ios/chrome/grit/ios_strings.h" |
| 21 #include "ui/base/l10n/l10n_util_mac.h" |
| 20 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 21 | 23 |
| 22 #if !defined(__has_feature) || !__has_feature(objc_arc) | 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 23 #error "This file requires ARC support." | 25 #error "This file requires ARC support." |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 // TODO(crbug.com/701275): Once base::BindBlock supports the move semantics, | 30 // TODO(crbug.com/701275): Once base::BindBlock supports the move semantics, |
| 29 // remove this wrapper. | 31 // remove this wrapper. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 const ntp_snippets::Category& category) { | 93 const ntp_snippets::Category& category) { |
| 92 ContentSuggestionsSectionInformation* sectionInfo = | 94 ContentSuggestionsSectionInformation* sectionInfo = |
| 93 [[ContentSuggestionsSectionInformation alloc] | 95 [[ContentSuggestionsSectionInformation alloc] |
| 94 initWithSectionID:SectionIDForCategory(category)]; | 96 initWithSectionID:SectionIDForCategory(category)]; |
| 95 if (categoryInfo) { | 97 if (categoryInfo) { |
| 96 sectionInfo.layout = SectionLayoutForLayout(categoryInfo->card_layout()); | 98 sectionInfo.layout = SectionLayoutForLayout(categoryInfo->card_layout()); |
| 97 if (categoryInfo->show_if_empty()) { | 99 if (categoryInfo->show_if_empty()) { |
| 98 // TODO(crbug.com/686728): Creates an item to display information when the | 100 // TODO(crbug.com/686728): Creates an item to display information when the |
| 99 // section is empty. | 101 // section is empty. |
| 100 } | 102 } |
| 103 if (categoryInfo->has_fetch_action()) { |
| 104 sectionInfo.footerTitle = |
| 105 l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_FOOTER_TITLE); |
| 106 } |
| 101 sectionInfo.title = base::SysUTF16ToNSString(categoryInfo->title()); | 107 sectionInfo.title = base::SysUTF16ToNSString(categoryInfo->title()); |
| 102 } | 108 } |
| 103 return sectionInfo; | 109 return sectionInfo; |
| 104 } | 110 } |
| 105 | 111 |
| 106 // Returns a ntp_snippets::ID based on a Objective-C Category and the ID in the | 112 // Returns a ntp_snippets::ID based on a Objective-C Category and the ID in the |
| 107 // category. | 113 // category. |
| 108 ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID( | 114 ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID( |
| 109 ContentSuggestionsCategoryWrapper* category, | 115 ContentSuggestionsCategoryWrapper* category, |
| 110 const std::string& id_in_category) { | 116 const std::string& id_in_category) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 [NSMutableArray array]; | 365 [NSMutableArray array]; |
| 360 ntp_snippets::Category category = suggestions[0].id().category(); | 366 ntp_snippets::Category category = suggestions[0].id().category(); |
| 361 [self addSuggestions:suggestions | 367 [self addSuggestions:suggestions |
| 362 fromCategory:category | 368 fromCategory:category |
| 363 toArray:contentSuggestions]; | 369 toArray:contentSuggestions]; |
| 364 callback(contentSuggestions); | 370 callback(contentSuggestions); |
| 365 } | 371 } |
| 366 } | 372 } |
| 367 | 373 |
| 368 @end | 374 @end |
| OLD | NEW |