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

Side by Side Diff: ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm

Issue 2766713002: Add "Read Later" action to ContentSuggestions' context menu (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
« no previous file with comments | « ios/chrome/browser/content_suggestions/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_coordinator. h" 5 #import "ios/chrome/browser/content_suggestions/content_suggestions_coordinator. h"
6 6
7 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.h"
8 #include "base/metrics/user_metrics.h"
9 #include "base/metrics/user_metrics_action.h"
8 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
9 #include "components/ntp_snippets/content_suggestions_service.h" 11 #include "components/ntp_snippets/content_suggestions_service.h"
10 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" 12 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h"
13 #include "components/reading_list/ios/reading_list_model.h"
11 #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h" 14 #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h"
12 #include "ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service _factory.h" 15 #include "ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service _factory.h"
16 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
13 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" 17 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
14 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art icle_item.h" 18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art icle_item.h"
15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands. h" 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands. h"
16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h" 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h"
17 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h" 21 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
18 #import "ios/chrome/browser/ui/url_loader.h" 22 #import "ios/chrome/browser/ui/url_loader.h"
19 #include "ios/chrome/grit/ios_strings.h" 23 #include "ios/chrome/grit/ios_strings.h"
20 #include "ios/web/public/referrer.h" 24 #include "ios/web/public/referrer.h"
21 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/strings/grit/ui_strings.h" 26 #include "ui/strings/grit/ui_strings.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 self.alertCoordinator = [[ActionSheetCoordinator alloc] 133 self.alertCoordinator = [[ActionSheetCoordinator alloc]
130 initWithBaseViewController:self.navigationController 134 initWithBaseViewController:self.navigationController
131 title:articleItem.title 135 title:articleItem.title
132 message:urlString 136 message:urlString
133 rect:CGRectMake(touchLocation.x, touchLocation.y, 0, 137 rect:CGRectMake(touchLocation.x, touchLocation.y, 0,
134 0) 138 0)
135 view:self.suggestionsViewController.collectionView]; 139 view:self.suggestionsViewController.collectionView];
136 140
137 __weak ContentSuggestionsCoordinator* weakSelf = self; 141 __weak ContentSuggestionsCoordinator* weakSelf = self;
138 GURL articleURL = articleItem.articleURL; 142 GURL articleURL = articleItem.articleURL;
143 NSString* articleTitle = articleItem.title;
139 __weak ContentSuggestionsArticleItem* weakArticle = articleItem; 144 __weak ContentSuggestionsArticleItem* weakArticle = articleItem;
140 145
141 NSString* openInNewTabTitle = 146 NSString* openInNewTabTitle =
142 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); 147 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB);
143 [self.alertCoordinator 148 [self.alertCoordinator
144 addItemWithTitle:openInNewTabTitle 149 addItemWithTitle:openInNewTabTitle
145 action:^{ 150 action:^{
146 // TODO(crbug.com/691979): Add metrics. 151 // TODO(crbug.com/691979): Add metrics.
147 [weakSelf openNewTabWithURL:articleURL incognito:NO]; 152 [weakSelf openNewTabWithURL:articleURL incognito:NO];
148 } 153 }
149 style:UIAlertActionStyleDefault]; 154 style:UIAlertActionStyleDefault];
150 155
151 NSString* openInNewTabIncognitoTitle = 156 NSString* openInNewTabIncognitoTitle =
152 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB); 157 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB);
153 [self.alertCoordinator 158 [self.alertCoordinator
154 addItemWithTitle:openInNewTabIncognitoTitle 159 addItemWithTitle:openInNewTabIncognitoTitle
155 action:^{ 160 action:^{
156 // TODO(crbug.com/691979): Add metrics. 161 // TODO(crbug.com/691979): Add metrics.
157 [weakSelf openNewTabWithURL:articleURL incognito:YES]; 162 [weakSelf openNewTabWithURL:articleURL incognito:YES];
158 } 163 }
159 style:UIAlertActionStyleDefault]; 164 style:UIAlertActionStyleDefault];
160 165
166 NSString* readLaterTitle =
Olivier 2017/03/22 08:28:43 if (reading_list::switches::IsReadingListEnabled()
gambard 2017/03/22 08:37:54 Done.
167 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_ADDTOREADINGLIST);
168 [self.alertCoordinator
169 addItemWithTitle:readLaterTitle
170 action:^{
171 ContentSuggestionsCoordinator* strongSelf = weakSelf;
172 if (!strongSelf)
173 return;
174
175 base::RecordAction(
176 base::UserMetricsAction("MobileReadingListAdd"));
177 // TODO(crbug.com/691979): Add metrics.
178
179 ReadingListModel* readingModel =
180 ReadingListModelFactory::GetForBrowserState(
181 strongSelf.browserState);
182 readingModel->AddEntry(articleURL,
183 base::SysNSStringToUTF8(articleTitle),
184 reading_list::ADDED_VIA_CURRENT_APP);
185 }
186 style:UIAlertActionStyleDefault];
187
161 NSString* deleteTitle = 188 NSString* deleteTitle =
162 l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_DELETE); 189 l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_DELETE);
163 [self.alertCoordinator addItemWithTitle:deleteTitle 190 [self.alertCoordinator addItemWithTitle:deleteTitle
164 action:^{ 191 action:^{
165 // TODO(crbug.com/691979): Add metrics. 192 // TODO(crbug.com/691979): Add metrics.
166 [weakSelf dismissArticle:weakArticle 193 [weakSelf dismissArticle:weakArticle
167 atIndexPath:indexPath]; 194 atIndexPath:indexPath];
168 } 195 }
169 style:UIAlertActionStyleDefault]; 196 style:UIAlertActionStyleDefault];
170 197
(...skipping 30 matching lines...) Expand all
201 if (!article) 228 if (!article)
202 return; 229 return;
203 230
204 // TODO(crbug.com/691979): Add metrics. 231 // TODO(crbug.com/691979): Add metrics.
205 [self.contentSuggestionsMediator 232 [self.contentSuggestionsMediator
206 dismissSuggestion:article.suggestionIdentifier]; 233 dismissSuggestion:article.suggestionIdentifier];
207 [self.suggestionsViewController dismissEntryAtIndexPath:indexPath]; 234 [self.suggestionsViewController dismissEntryAtIndexPath:indexPath];
208 } 235 }
209 236
210 @end 237 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/content_suggestions/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698