Commit 72d70865 authored by adamta's avatar adamta Committed by Commit Bot

[iOS] Discover feed header menu

Loads action sheet on bottom of page when selecting the menu button
from the NTP Discover feed header. Adds 2 actions: 'Manage Interests'
and 'Learn More' which both open a URL in the current tab.

Bug: 1085419
Change-Id: Ieaa7785d5dfb0c34575828d5551b53b4b8b1a0fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2305910Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Adam Trudeau-Arcaro <adamta@google.com>
Cr-Commit-Position: refs/heads/master@{#791334}
parent d1b51391
......@@ -704,6 +704,12 @@ Because your account is managed by <ph name="HOSTED_DOMAIN">$1<ex>google.com</ex
<message name="IDS_IOS_DISCOVER_FEED_TITLE" desc="The title in the Discover feed menu.">
Discover
</message>
<message name="IDS_IOS_DISCOVER_FEED_MENU_LEARN_MORE_ITEM" desc="The 'Learn More' action for the Discover feed header menu.">
Learn More
</message>
<message name="IDS_IOS_DISCOVER_FEED_MENU_MANAGE_INTERESTS_ITEM" desc="The 'Manage Interests' action for the Discover feed header menu.">
Manage Interests
</message>
<message name="IDS_IOS_DOWNLOAD_MANAGER_CANNOT_DETERMINE_FILE_SIZE" desc="Message displayed when the size of the file to be downloaded is unknown. [Length: 30em] [iOS only]">
Cannot determine file size.
</message>
......
386edfc33603b4fadb60c3558fed234446b3a470
\ No newline at end of file
386edfc33603b4fadb60c3558fed234446b3a470
\ No newline at end of file
......@@ -124,6 +124,7 @@ source_set("content_suggestions_ui") {
"content_suggestions_view_controller.h",
"content_suggestions_view_controller.mm",
"content_suggestions_view_controller_audience.h",
"discover_feed_menu_commands.h",
"ntp_home_consumer.h",
"theme_change_delegate.h",
"user_account_image_update_delegate.h",
......
......@@ -68,6 +68,7 @@ const CGFloat kHeaderMargin = 25;
_menuButton.translatesAutoresizingMaskIntoConstraints = NO;
_menuButton.accessibilityIdentifier =
kContentSuggestionsDiscoverHeaderButtonIdentifier;
// TODO(crbug.com/1085419): Change icon to proper one for feed (TBD by UX).
[_menuButton setImage:[UIImage imageNamed:@"infobar_settings_icon"]
forState:UIControlStateNormal];
......@@ -97,4 +98,11 @@ const CGFloat kHeaderMargin = 25;
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
[self.menuButton removeTarget:nil
action:nil
forControlEvents:UIControlEventAllEvents];
}
@end
......@@ -35,6 +35,8 @@
- (void)handlePromoTapped;
// Handles the actions following a tap on the "Learn more" item.
- (void)handleLearnMoreTapped;
// Handles the actions following a tap on the "Manage Interests" item.
- (void)handleManageInterestsTapped;
@end
......
......@@ -28,6 +28,7 @@
#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
......@@ -40,6 +41,7 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_metrics_recorder.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller_audience.h"
#import "ios/chrome/browser/ui/content_suggestions/discover_feed_menu_commands.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_mediator.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_metrics.h"
......@@ -52,8 +54,10 @@
#import "ios/chrome/browser/url_loading/url_loading_browser_agent.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/voice/voice_search_availability.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/discover_feed/discover_feed_provider.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -61,6 +65,7 @@
@interface ContentSuggestionsCoordinator () <
ContentSuggestionsViewControllerAudience,
DiscoverFeedMenuCommands,
OverscrollActionsControllerDelegate,
ThemeChangeDelegate,
URLDropDelegate> {
......@@ -78,7 +83,7 @@
@property(nonatomic, strong) NTPHomeMediator* NTPMediator;
@property(nonatomic, strong) UIViewController* discoverFeedViewController;
@property(nonatomic, strong) URLDragDropHandler* dragDropHandler;
@property(nonatomic, strong) ActionSheetCoordinator* alertCoordinator;
// Redefined as readwrite.
@property(nonatomic, strong, readwrite)
ContentSuggestionsHeaderViewController* headerController;
......@@ -122,15 +127,12 @@
ntp_home::RecordNTPImpression(ntp_home::LOCAL_SUGGESTIONS);
}
UrlLoadingBrowserAgent* URLLoader =
UrlLoadingBrowserAgent::FromBrowser(self.browser);
self.NTPMediator = [[NTPHomeMediator alloc]
initWithWebState:self.webState
templateURLService:ios::TemplateURLServiceFactory::
GetForBrowserState(
self.browser->GetBrowserState())
URLLoader:URLLoader
URLLoader:UrlLoadingBrowserAgent::FromBrowser(self.browser)
authService:AuthenticationServiceFactory::GetForBrowserState(
self.browser->GetBrowserState())
identityManager:IdentityManagerFactory::GetForBrowserState(
......@@ -214,6 +216,7 @@
id<SnackbarCommands> dispatcher = HandlerForProtocol(
self.browser->GetCommandDispatcher(), SnackbarCommands);
self.suggestionsViewController.dispatcher = dispatcher;
self.suggestionsViewController.discoverFeedMenuHandler = self;
self.NTPMediator.consumer = self.headerController;
// TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
......@@ -352,6 +355,35 @@
->Load(UrlLoadParams::InCurrentTab(URL));
}
#pragma mark - DiscoverFeedMenuCommands
- (void)openDiscoverFeedMenu:(UIView*)menuButton {
self.alertCoordinator = [[ActionSheetCoordinator alloc]
initWithBaseViewController:self.suggestionsViewController
browser:self.browser
title:nil
message:nil
rect:menuButton.frame
view:menuButton.superview];
__weak ContentSuggestionsCoordinator* weakSelf = self;
[self.alertCoordinator
addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_DISCOVER_FEED_MENU_MANAGE_INTERESTS_ITEM)
action:^{
[weakSelf.NTPMediator handleManageInterestsTapped];
}
style:UIAlertActionStyleDefault];
[self.alertCoordinator
addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_DISCOVER_FEED_MENU_LEARN_MORE_ITEM)
action:^{
[weakSelf.NTPMediator handleLearnMoreTapped];
}
style:UIAlertActionStyleDefault];
[self.alertCoordinator start];
}
#pragma mark - Public methods
- (UIView*)view {
......
......@@ -16,6 +16,7 @@
@protocol ContentSuggestionsHeaderSynchronizing;
@protocol ContentSuggestionsMetricsRecording;
@protocol ContentSuggestionsViewControllerAudience;
@protocol DiscoverFeedMenuCommands;
@protocol OverscrollActionsControllerDelegate;
@protocol SnackbarCommands;
@protocol SuggestedContent;
......@@ -49,6 +50,7 @@ extern NSString* const
overscrollDelegate;
// Delegate for handling theme changes (dark/light theme).
@property(nonatomic, weak) id<ThemeChangeDelegate> themeChangeDelegate;
@property(nonatomic, weak) id<DiscoverFeedMenuCommands> discoverFeedMenuHandler;
@property(nonatomic, weak) id<ContentSuggestionsMetricsRecording>
metricsRecorder;
......
......@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_cell.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_discover_header_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_discover_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_cell.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/suggested_content.h"
......@@ -22,6 +23,7 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_layout.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_metrics_recording.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller_audience.h"
#import "ios/chrome/browser/ui/content_suggestions/discover_feed_menu_commands.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
#import "ios/chrome/browser/ui/content_suggestions/theme_change_delegate.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h"
......@@ -422,6 +424,25 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
return cell;
}
#pragma mark - UICollectionViewDataSource
- (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView
viewForSupplementaryElementOfKind:(NSString*)kind
atIndexPath:(NSIndexPath*)indexPath {
UICollectionReusableView* cell = [super collectionView:collectionView
viewForSupplementaryElementOfKind:kind
atIndexPath:indexPath];
if ([kind isEqualToString:UICollectionElementKindSectionHeader] &&
[self.collectionUpdater isDiscoverSection:indexPath.section]) {
ContentSuggestionsDiscoverHeaderCell* discoverFeedHeader =
base::mac::ObjCCastStrict<ContentSuggestionsDiscoverHeaderCell>(cell);
[discoverFeedHeader.menuButton addTarget:self
action:@selector(openDiscoverFeedMenu:)
forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView*)collectionView
......@@ -744,4 +765,9 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
_initialContentOffset = NAN;
}
// Opens top-level feed menu when pressing |menuButton|.
- (void)openDiscoverFeedMenu:(id)menuButton {
[self.discoverFeedMenuHandler openDiscoverFeedMenu:menuButton];
}
@end
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_DISCOVER_FEED_MENU_COMMANDS_H_
#define IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_DISCOVER_FEED_MENU_COMMANDS_H_
// Protocol for actions relating to the Discover feed top-level control menu.
@protocol DiscoverFeedMenuCommands
// Opens Discover feed control menu.
- (void)openDiscoverFeedMenu:(UIView*)menuButton;
@end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_DISCOVER_FEED_MENU_COMMANDS_H_
......@@ -65,6 +65,9 @@
#endif
namespace {
// URL for 'Manage Interests' item in the Discover feed menu.
const char kFeedManageInterestsURL[] =
"https://google.com/preferences/interests";
// URL for the page displaying help for the NTP.
const char kNTPHelpURL[] =
"https://support.google.com/chrome/?p=ios_new_tab&ios=1";
......@@ -376,6 +379,15 @@ const char kNTPHelpURL[] =
NOTREACHED() << "Promo type is neither URL or command.";
}
- (void)handleManageInterestsTapped {
NewTabPageTabHelper* NTPHelper =
NewTabPageTabHelper::FromWebState(self.webState);
if (NTPHelper && NTPHelper->IgnoreLoadRequests())
return;
_URLLoader->Load(UrlLoadParams::InCurrentTab(GURL(kFeedManageInterestsURL)));
// TODO(crbug.com/1085419): Add metrics.
}
- (void)handleLearnMoreTapped {
NewTabPageTabHelper* NTPHelper =
NewTabPageTabHelper::FromWebState(self.webState);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment