| Index: ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm
|
| diff --git a/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm b/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm
|
| index 5104b68a259a490fc94e029c46cc2b7493508d32..e0cf332a3e43234af723a7f7157e764fbed72d60 100644
|
| --- a/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm
|
| +++ b/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm
|
| @@ -6,9 +6,12 @@
|
|
|
| #include "base/mac/scoped_nsobject.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| +#include "components/ntp_snippets/content_suggestions_service.h"
|
| +#include "components/ntp_snippets/remote/remote_suggestions_scheduler.h"
|
| #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h"
|
| #include "ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service_factory.h"
|
| #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
|
| +#import "ios/chrome/browser/ui/content_suggestions/content_suggestion_identifier.h"
|
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.h"
|
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.h"
|
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h"
|
| @@ -22,16 +25,21 @@
|
| #error "This file requires ARC support."
|
| #endif
|
|
|
| -@interface ContentSuggestionsCoordinator ()<ContentSuggestionsCommands> {
|
| - ContentSuggestionsMediator* _contentSuggestionsMediator;
|
| -}
|
| +@interface ContentSuggestionsCoordinator ()<ContentSuggestionsCommands>
|
|
|
| @property(nonatomic, strong) AlertCoordinator* alertCoordinator;
|
| @property(nonatomic, strong) UINavigationController* navigationController;
|
| @property(nonatomic, strong)
|
| ContentSuggestionsViewController* suggestionsViewController;
|
| +@property(nonatomic, strong)
|
| + ContentSuggestionsMediator* contentSuggestionsMediator;
|
|
|
| +// Opens the |URL| in a new tab |incognito| or not.
|
| - (void)openNewTabWithURL:(const GURL&)URL incognito:(BOOL)incognito;
|
| +// Dismisses the |article|, removing it from the content service, and dismisses
|
| +// the item at |indexPath| in the view controller.
|
| +- (void)dismissArticle:(ContentSuggestionsArticleItem*)article
|
| + atIndexPath:(NSIndexPath*)indexPath;
|
|
|
| @end
|
|
|
| @@ -43,6 +51,7 @@
|
| @synthesize suggestionsViewController = _suggestionsViewController;
|
| @synthesize URLLoader = _URLLoader;
|
| @synthesize visible = _visible;
|
| +@synthesize contentSuggestionsMediator = _contentSuggestionsMediator;
|
|
|
| - (void)start {
|
| if (self.visible || !self.browserState) {
|
| @@ -53,13 +62,17 @@
|
|
|
| _visible = YES;
|
|
|
| - _contentSuggestionsMediator = [[ContentSuggestionsMediator alloc]
|
| - initWithContentService:IOSChromeContentSuggestionsServiceFactory::
|
| - GetForBrowserState(self.browserState)];
|
| + ntp_snippets::ContentSuggestionsService* contentSuggestionsService =
|
| + IOSChromeContentSuggestionsServiceFactory::GetForBrowserState(
|
| + self.browserState);
|
| + contentSuggestionsService->remote_suggestions_scheduler()->OnNTPOpened();
|
| +
|
| + self.contentSuggestionsMediator = [[ContentSuggestionsMediator alloc]
|
| + initWithContentService:contentSuggestionsService];
|
|
|
| self.suggestionsViewController = [[ContentSuggestionsViewController alloc]
|
| initWithStyle:CollectionViewControllerStyleDefault
|
| - dataSource:_contentSuggestionsMediator];
|
| + dataSource:self.contentSuggestionsMediator];
|
|
|
| self.suggestionsViewController.suggestionCommandHandler = self;
|
| _navigationController = [[UINavigationController alloc]
|
| @@ -82,6 +95,7 @@
|
| dismissViewControllerAnimated:YES
|
| completion:nil];
|
| self.navigationController = nil;
|
| + self.contentSuggestionsMediator = nil;
|
| _visible = NO;
|
| }
|
|
|
| @@ -108,7 +122,8 @@
|
| }
|
|
|
| - (void)displayContextMenuForArticle:(ContentSuggestionsArticleItem*)articleItem
|
| - atPoint:(CGPoint)touchLocation {
|
| + atPoint:(CGPoint)touchLocation
|
| + atIndexPath:(NSIndexPath*)indexPath {
|
| NSString* urlString = base::SysUTF8ToNSString(articleItem.articleURL.spec());
|
| self.alertCoordinator = [[ActionSheetCoordinator alloc]
|
| initWithBaseViewController:self.navigationController
|
| @@ -120,6 +135,7 @@
|
|
|
| __weak ContentSuggestionsCoordinator* weakSelf = self;
|
| GURL articleURL = articleItem.articleURL;
|
| + __weak ContentSuggestionsArticleItem* weakArticle = articleItem;
|
|
|
| NSString* openInNewTabTitle =
|
| l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB);
|
| @@ -146,7 +162,8 @@
|
| [self.alertCoordinator addItemWithTitle:deleteTitle
|
| action:^{
|
| // TODO(crbug.com/691979): Add metrics.
|
| - [weakSelf removeEntry];
|
| + [weakSelf dismissArticle:weakArticle
|
| + atIndexPath:indexPath];
|
| }
|
| style:UIAlertActionStyleDefault];
|
|
|
| @@ -173,8 +190,15 @@
|
| [self stop];
|
| }
|
|
|
| -- (void)removeEntry {
|
| +- (void)dismissArticle:(ContentSuggestionsArticleItem*)article
|
| + atIndexPath:(NSIndexPath*)indexPath {
|
| + if (!article)
|
| + return;
|
| +
|
| // TODO(crbug.com/691979): Add metrics.
|
| + [self.contentSuggestionsMediator
|
| + dismissSuggestion:article.suggestionIdentifier];
|
| + [self.suggestionsViewController dismissEntryAtIndexPath:indexPath];
|
| }
|
|
|
| @end
|
|
|