| 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_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/core/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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 self.alertCoordinator = [[ActionSheetCoordinator alloc] | 132 self.alertCoordinator = [[ActionSheetCoordinator alloc] |
| 129 initWithBaseViewController:self.navigationController | 133 initWithBaseViewController:self.navigationController |
| 130 title:nil | 134 title:nil |
| 131 message:nil | 135 message:nil |
| 132 rect:CGRectMake(touchLocation.x, touchLocation.y, 0, | 136 rect:CGRectMake(touchLocation.x, touchLocation.y, 0, |
| 133 0) | 137 0) |
| 134 view:self.suggestionsViewController.collectionView]; | 138 view:self.suggestionsViewController.collectionView]; |
| 135 | 139 |
| 136 __weak ContentSuggestionsCoordinator* weakSelf = self; | 140 __weak ContentSuggestionsCoordinator* weakSelf = self; |
| 137 GURL articleURL = articleItem.articleURL; | 141 GURL articleURL = articleItem.articleURL; |
| 142 NSString* articleTitle = articleItem.title; |
| 138 __weak ContentSuggestionsArticleItem* weakArticle = articleItem; | 143 __weak ContentSuggestionsArticleItem* weakArticle = articleItem; |
| 139 | 144 |
| 140 NSString* openInNewTabTitle = | 145 NSString* openInNewTabTitle = |
| 141 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); | 146 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| 142 [self.alertCoordinator | 147 [self.alertCoordinator |
| 143 addItemWithTitle:openInNewTabTitle | 148 addItemWithTitle:openInNewTabTitle |
| 144 action:^{ | 149 action:^{ |
| 145 // TODO(crbug.com/691979): Add metrics. | 150 // TODO(crbug.com/691979): Add metrics. |
| 146 [weakSelf openNewTabWithURL:articleURL incognito:NO]; | 151 [weakSelf openNewTabWithURL:articleURL incognito:NO]; |
| 147 } | 152 } |
| 148 style:UIAlertActionStyleDefault]; | 153 style:UIAlertActionStyleDefault]; |
| 149 | 154 |
| 150 NSString* openInNewTabIncognitoTitle = | 155 NSString* openInNewTabIncognitoTitle = |
| 151 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB); | 156 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB); |
| 152 [self.alertCoordinator | 157 [self.alertCoordinator |
| 153 addItemWithTitle:openInNewTabIncognitoTitle | 158 addItemWithTitle:openInNewTabIncognitoTitle |
| 154 action:^{ | 159 action:^{ |
| 155 // TODO(crbug.com/691979): Add metrics. | 160 // TODO(crbug.com/691979): Add metrics. |
| 156 [weakSelf openNewTabWithURL:articleURL incognito:YES]; | 161 [weakSelf openNewTabWithURL:articleURL incognito:YES]; |
| 157 } | 162 } |
| 158 style:UIAlertActionStyleDefault]; | 163 style:UIAlertActionStyleDefault]; |
| 159 | 164 |
| 165 NSString* readLaterTitle = |
| 166 l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_ADDTOREADINGLIST); |
| 167 [self.alertCoordinator |
| 168 addItemWithTitle:readLaterTitle |
| 169 action:^{ |
| 170 ContentSuggestionsCoordinator* strongSelf = weakSelf; |
| 171 if (!strongSelf) |
| 172 return; |
| 173 |
| 174 base::RecordAction( |
| 175 base::UserMetricsAction("MobileReadingListAdd")); |
| 176 // TODO(crbug.com/691979): Add metrics. |
| 177 |
| 178 ReadingListModel* readingModel = |
| 179 ReadingListModelFactory::GetForBrowserState( |
| 180 strongSelf.browserState); |
| 181 readingModel->AddEntry(articleURL, |
| 182 base::SysNSStringToUTF8(articleTitle), |
| 183 reading_list::ADDED_VIA_CURRENT_APP); |
| 184 } |
| 185 style:UIAlertActionStyleDefault]; |
| 186 |
| 160 NSString* deleteTitle = | 187 NSString* deleteTitle = |
| 161 l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_DELETE); | 188 l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_DELETE); |
| 162 [self.alertCoordinator addItemWithTitle:deleteTitle | 189 [self.alertCoordinator addItemWithTitle:deleteTitle |
| 163 action:^{ | 190 action:^{ |
| 164 // TODO(crbug.com/691979): Add metrics. | 191 // TODO(crbug.com/691979): Add metrics. |
| 165 [weakSelf dismissArticle:weakArticle | 192 [weakSelf dismissArticle:weakArticle |
| 166 atIndexPath:indexPath]; | 193 atIndexPath:indexPath]; |
| 167 } | 194 } |
| 168 style:UIAlertActionStyleDefault]; | 195 style:UIAlertActionStyleDefault]; |
| 169 | 196 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 200 if (!article) | 227 if (!article) |
| 201 return; | 228 return; |
| 202 | 229 |
| 203 // TODO(crbug.com/691979): Add metrics. | 230 // TODO(crbug.com/691979): Add metrics. |
| 204 [self.contentSuggestionsMediator | 231 [self.contentSuggestionsMediator |
| 205 dismissSuggestion:article.suggestionIdentifier]; | 232 dismissSuggestion:article.suggestionIdentifier]; |
| 206 [self.suggestionsViewController dismissEntryAtIndexPath:indexPath]; | 233 [self.suggestionsViewController dismissEntryAtIndexPath:indexPath]; |
| 207 } | 234 } |
| 208 | 235 |
| 209 @end | 236 @end |
| OLD | NEW |