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

Unified Diff: ios/chrome/browser/content_suggestions/mediator_util.mm

Issue 2877513003: ContentSuggestionsDataSource returns CollectionViewItem (Closed)
Patch Set: Address comments Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/content_suggestions/mediator_util.mm
diff --git a/ios/chrome/browser/content_suggestions/mediator_util.mm b/ios/chrome/browser/content_suggestions/mediator_util.mm
index d4ea2f9dd6876ac1e4cfac70ddad913c1ba73e00..5b428bae14afb906c8f09541fc0924f0502738a9 100644
--- a/ios/chrome/browser/content_suggestions/mediator_util.mm
+++ b/ios/chrome/browser/content_suggestions/mediator_util.mm
@@ -10,6 +10,10 @@
#include "components/rappor/rappor_service_impl.h"
#include "ios/chrome/browser/application_context.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.h"
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
+#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_item.h"
+#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h"
+#import "ios/chrome/browser/ui/content_suggestions/cells/suggested_content.h"
#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion_identifier.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
@@ -29,15 +33,6 @@ void BindWrapper(
}
}
-ContentSuggestionType TypeForCategory(ntp_snippets::Category category) {
- if (category.IsKnownCategory(ntp_snippets::KnownCategories::ARTICLES))
- return ContentSuggestionTypeArticle;
- if (category.IsKnownCategory(ntp_snippets::KnownCategories::READING_LIST))
- return ContentSuggestionTypeReadingList;
-
- return ContentSuggestionTypeEmpty;
-}
-
ContentSuggestionsSectionID SectionIDForCategory(
ntp_snippets::Category category) {
if (category.IsKnownCategory(ntp_snippets::KnownCategories::ARTICLES))
@@ -48,19 +43,15 @@ ContentSuggestionsSectionID SectionIDForCategory(
return ContentSuggestionsSectionUnknown;
}
-ContentSuggestionsSectionLayout SectionLayoutForLayout(
- ntp_snippets::ContentSuggestionsCardLayout layout) {
- // For now, only cards are relevant.
- return ContentSuggestionsSectionLayoutCard;
-}
-
-ContentSuggestion* ConvertContentSuggestion(
- const ntp_snippets::ContentSuggestion& contentSuggestion) {
- ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
-
- suggestion.title = base::SysUTF16ToNSString(contentSuggestion.title());
- suggestion.text = base::SysUTF16ToNSString(contentSuggestion.snippet_text());
- suggestion.url = contentSuggestion.url();
+CollectionViewItem<SuggestedContent>* ConvertSuggestion(
+ const ntp_snippets::ContentSuggestion& contentSuggestion,
+ ContentSuggestionsSectionInformation* sectionInfo,
+ ntp_snippets::Category category) {
+ ContentSuggestionsItem* suggestion = [[ContentSuggestionsItem alloc]
+ initWithType:0
+ title:base::SysUTF16ToNSString(contentSuggestion.title())
+ subtitle:base::SysUTF16ToNSString(contentSuggestion.snippet_text())
+ url:contentSuggestion.url()];
suggestion.publisher =
base::SysUTF16ToNSString(contentSuggestion.publisher_name());
@@ -69,6 +60,15 @@ ContentSuggestion* ConvertContentSuggestion(
suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
suggestion.suggestionIdentifier.IDInSection =
contentSuggestion.id().id_within_category();
+ suggestion.suggestionIdentifier.sectionInfo = sectionInfo;
+
+ if (category.IsKnownCategory(ntp_snippets::KnownCategories::READING_LIST)) {
+ suggestion.availableOffline =
+ contentSuggestion.reading_list_suggestion_extra()->distilled;
+ }
+ if (category.IsKnownCategory(ntp_snippets::KnownCategories::ARTICLES)) {
+ suggestion.hasImage = YES;
+ }
return suggestion;
}
@@ -80,7 +80,7 @@ ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
[[ContentSuggestionsSectionInformation alloc]
initWithSectionID:SectionIDForCategory(category)];
if (categoryInfo) {
- sectionInfo.layout = SectionLayoutForLayout(categoryInfo->card_layout());
+ sectionInfo.layout = ContentSuggestionsSectionLayoutCard;
sectionInfo.showIfEmpty = categoryInfo->show_if_empty();
sectionInfo.emptyText =
base::SysUTF16ToNSString(categoryInfo->no_suggestions_message());
@@ -100,14 +100,6 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
return ntp_snippets::ContentSuggestion::ID(category.category, id_in_category);
}
-ContentSuggestion* EmptySuggestion() {
- ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
- suggestion.type = ContentSuggestionTypeEmpty;
- suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
-
- return suggestion;
-}
-
ContentSuggestionsSectionInformation* MostVisitedSectionInformation() {
ContentSuggestionsSectionInformation* sectionInfo =
[[ContentSuggestionsSectionInformation alloc]
@@ -130,15 +122,18 @@ void RecordPageImpression(const ntp_tiles::NTPTilesVector& mostVisited) {
tiles, GetApplicationContext()->GetRapporServiceImpl());
}
-ContentSuggestion* ConvertNTPTile(const ntp_tiles::NTPTile& tile) {
- ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
+CollectionViewItem<SuggestedContent>* ConvertNTPTile(
+ const ntp_tiles::NTPTile& tile,
+ ContentSuggestionsSectionInformation* sectionInfo) {
+ ContentSuggestionsMostVisitedItem* suggestion =
+ [[ContentSuggestionsMostVisitedItem alloc] initWithType:0];
suggestion.title = base::SysUTF16ToNSString(tile.title);
- suggestion.url = tile.url;
- suggestion.type = ContentSuggestionTypeMostVisited;
+ suggestion.URL = tile.url;
suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
suggestion.suggestionIdentifier.IDInSection = tile.url.spec();
+ suggestion.suggestionIdentifier.sectionInfo = sectionInfo;
return suggestion;
}
« no previous file with comments | « ios/chrome/browser/content_suggestions/mediator_util.h ('k') | ios/chrome/browser/ui/content_suggestions/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698