Commit 8a955ff6 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Adding commands the Google services settings

Adding list of commands for each switch to toggle from the Google
services settings (see the screenshot). To associate those commands to
each UISwitch, SyncSwitchItem.commandID is added.

GoogleServicesSettingsViewController calls the right command on its
|commandHandler| when a switched is toggled.

GoogleServicesSettingsMediator implements
GoogleServicesSettingsCommandHandler to modify the model when the user
toggles the switches. The coordinator sets the mediator to be the
command handler for the view controller.

Screenshot: https://drive.google.com/open?id=1hvi5LyGjBDODkRQymvC5sbUjSN9tafFz

This patch is to replace: crrev.com/c/1146730

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ica05f255bc2af154033a53cd1a1365c43775f9c7
Reviewed-on: https://chromium-review.googlesource.com/1155587
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579365}
parent 33517519
......@@ -42,6 +42,7 @@ source_set("settings") {
"dataplan_usage_collection_view_controller.mm",
"do_not_track_collection_view_controller.h",
"do_not_track_collection_view_controller.mm",
"google_services_settings_command_handler.h",
"google_services_settings_consumer.h",
"google_services_settings_coordinator.h",
"google_services_settings_coordinator.mm",
......
......@@ -28,6 +28,9 @@
// SyncSetupService::SyncableDatatype value for the item.
@property(nonatomic, assign) NSInteger dataType;
// Command to trigger when the switch is toggled. The default value is 0.
@property(nonatomic, assign) NSInteger commandID;
@end
// Cell representation for AccountSignInItem.
......
......@@ -38,6 +38,7 @@ const CGFloat kHorizontalSwitchPadding = 10;
@synthesize on = _on;
@synthesize enabled = _enabled;
@synthesize dataType = _dataType;
@synthesize commandID = _commandID;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
......
// Copyright 2018 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_SETTINGS_GOOGLE_SERVICES_SETTINGS_COMMAND_HANDLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_COMMAND_HANDLER_H_
// List of Google Services Settings commands.
typedef NS_ENUM(NSInteger, GoogleServicesSettingsCommandID) {
// Does nothing.
GoogleServicesSettingsCommandIDNoOp,
// Enabble/disable all the Google services.
GoogleServicesSettingsCommandIDToggleSyncEverything,
// Enable/disabble bookmark sync.
GoogleServicesSettingsCommandIDToggleBookmarkSync,
// Enable/disabble history sync.
GoogleServicesSettingsCommandIDToggleHistorySync,
// Enable/disabble passwords sync.
GoogleServicesSettingsCommandIDTogglePasswordsSync,
// Enable/disabble open tabs sync.
GoogleServicesSettingsCommandIDToggleOpenTabsSync,
// Enable/disabble autofill sync.
GoogleServicesSettingsCommandIDToggleAutofillSync,
// Enable/disabble settings sync.
GoogleServicesSettingsCommandIDToggleSettingsSync,
// Enable/disabble reading list sync.
GoogleServicesSettingsCommandIDToggleReadingListSync,
// Enable/disable activity and interactions service.
GoogleServicesSettingsCommandIDToggleActivityAndInteractionsService,
// Enable/disabble autocomplete searches service.
GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService,
// Enable/disabble preload pages service.
GoogleServicesSettingsCommandIDTogglePreloadPagesService,
// Enable/disabble improve chrome service.
GoogleServicesSettingsCommandIDToggleImproveChromeService,
// Enable/disabble better search and browsing service.
GoogleServicesSettingsCommandIDToggleBetterSearchAndBrowsingService,
};
// Protocol to handle Google services settings commands.
@protocol GoogleServicesSettingsCommandHandler<NSObject>
// Called when GoogleServicesSettingsCommandIDToggleSyncEverything is triggered.
- (void)toggleSyncEverythingWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDToggleBookmarkSync is triggered.
- (void)toggleBookmarksSyncWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDToggleHistorySync is triggered.
- (void)toggleHistorySyncWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDTogglePasswordsSync is triggered.
- (void)togglePasswordsSyncWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDToggleOpenTabsSync is triggered.
- (void)toggleOpenTabSyncWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDToggleAutofillSync is triggered.
- (void)toggleAutofillWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDToggleSettingsSync is triggered.
- (void)toggleSettingsWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDToggleReadingListSync is
// triggered.
- (void)toggleReadingListWithValue:(BOOL)on;
// Called when
// GoogleServicesSettingsCommandIDToggleActivityAndInteractionsService is
// triggered.
- (void)toggleActivityAndInteractionsServiceWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService
// is triggered.
- (void)toggleAutocompleteSearchesServiceWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDTogglePreloadPagesService is
// triggered.
- (void)togglePreloadPagesServiceWithValue:(BOOL)on;
// Called when GoogleServicesSettingsCommandIDToggleImproveChromeService is
// triggered.
- (void)toggleImproveChromeServiceWithValue:(BOOL)on;
// Called when
// GoogleServicesSettingsCommandIDToggleBetterSearchAndBrowsingService is
// triggered.
- (void)toggleBetterSearchAndBrowsingServiceWithValue:(BOOL)on;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_COMMAND_HANDLER_H_
......@@ -41,6 +41,7 @@
self.mediator.authService =
AuthenticationServiceFactory::GetForBrowserState(self.browserState);
controller.modelDelegate = self.mediator;
controller.commandHandler = self.mediator;
DCHECK(self.navigationController);
[self.navigationController pushViewController:self.viewController
animated:YES];
......
......@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/settings/google_services_settings_command_handler.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_consumer.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_view_controller_model_delegate.h"
......@@ -17,7 +18,8 @@ class PrefService;
// Mediator for the Google services settings.
@interface GoogleServicesSettingsMediator
: NSObject<GoogleServicesSettingsViewControllerModelDelegate>
: NSObject<GoogleServicesSettingsCommandHandler,
GoogleServicesSettingsViewControllerModelDelegate>
// Designated initializer. |prefService| should not be null.
- (instancetype)initWithPrefService:(PrefService*)prefService
......
......@@ -107,6 +107,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_SYNC_EVERYTHING);
item.enabled = YES;
item.on = [self isConsentGiven];
item.commandID = GoogleServicesSettingsCommandIDToggleSyncEverything;
return item;
}
......@@ -166,6 +167,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[[SyncSwitchItem alloc] initWithType:SyncBookmarksItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_BOOKMARKS_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleBookmarkSync;
return item;
}
......@@ -175,6 +177,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[[SyncSwitchItem alloc] initWithType:SyncHistoryItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_HISTORY_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleHistorySync;
return item;
}
......@@ -184,6 +187,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[[SyncSwitchItem alloc] initWithType:SyncPasswordsItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_PASSWORD_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDTogglePasswordsSync;
return item;
}
......@@ -193,6 +197,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[[SyncSwitchItem alloc] initWithType:SyncOpenTabsItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_OPENTABS_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleOpenTabsSync;
return item;
}
......@@ -202,6 +207,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[[SyncSwitchItem alloc] initWithType:SyncAutofillItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOFILL_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleAutofillSync;
return item;
}
......@@ -211,6 +217,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[[SyncSwitchItem alloc] initWithType:SyncReadingListItemType];
item.text = GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_READING_LIST_TEXT);
item.enabled = self.isAuthenticated;
item.commandID = GoogleServicesSettingsCommandIDToggleReadingListSync;
return item;
}
......@@ -223,6 +230,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
item.detailText = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_ACTIVITY_AND_INTERACTIONS_DETAIL);
item.enabled = self.isAuthenticated;
item.commandID =
GoogleServicesSettingsCommandIDToggleActivityAndInteractionsService;
return item;
}
......@@ -311,6 +320,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_TEXT);
item.detailText = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_DETAIL);
item.commandID =
GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService;
item.enabled = YES;
return item;
}
......@@ -323,6 +334,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
item.detailText =
GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_PRELOAD_PAGES_DETAIL);
item.enabled = YES;
item.commandID = GoogleServicesSettingsCommandIDTogglePreloadPagesService;
return item;
}
......@@ -334,6 +346,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
item.detailText =
GetNSString(IDS_IOS_GOOGLE_SERVICES_SETTINGS_IMPROVE_CHROME_DETAIL);
item.enabled = YES;
item.commandID = GoogleServicesSettingsCommandIDToggleImproveChromeService;
return item;
}
......@@ -346,6 +359,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
item.detailText = GetNSString(
IDS_IOS_GOOGLE_SERVICES_SETTINGS_BETTER_SEARCH_AND_BROWSING_DETAIL);
item.enabled = YES;
item.commandID =
GoogleServicesSettingsCommandIDToggleBetterSearchAndBrowsingService;
return item;
}
......@@ -372,4 +387,58 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self loadNonPersonalizedSection];
}
#pragma mark - GoogleServicesSettingsCommandHandler
- (void)toggleSyncEverythingWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleBookmarksSyncWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleHistorySyncWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)togglePasswordsSyncWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleOpenTabSyncWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleAutofillWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleSettingsWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleReadingListWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleActivityAndInteractionsServiceWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleAutocompleteSearchesServiceWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)togglePreloadPagesServiceWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleImproveChromeServiceWithValue:(BOOL)on {
// Needs to be implemented.
}
- (void)toggleBetterSearchAndBrowsingServiceWithValue:(BOOL)on {
// Needs to be implemented.
}
@end
......@@ -10,6 +10,7 @@
#import "ios/chrome/browser/ui/settings/google_services_settings_consumer.h"
@class GoogleServicesSettingsViewController;
@protocol GoogleServicesSettingsCommandHandler;
@protocol GoogleServicesSettingsViewControllerModelDelegate;
// Delegate for presentation events related to
......@@ -34,6 +35,10 @@
@property(nonatomic, weak) id<GoogleServicesSettingsViewControllerModelDelegate>
modelDelegate;
// Handler for GoogleServicesSettingsCommand.
@property(nonatomic, weak) id<GoogleServicesSettingsCommandHandler>
commandHandler;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_VIEW_CONTROLLER_H_
......@@ -4,11 +4,13 @@
#import "ios/chrome/browser/ui/settings/google_services_settings_view_controller.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_collapsible_item.h"
#import "ios/chrome/browser/ui/settings/cells/sync_switch_item.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_command_handler.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_view_controller_model_delegate.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -17,10 +19,19 @@
#error "This file requires ARC support."
#endif
namespace {
// Constants used to convert NSIndexPath into a tag. Used as:
// item + section * kSectionOffset
constexpr NSInteger kSectionOffset = 1000;
} // namespace
@implementation GoogleServicesSettingsViewController
@synthesize modelDelegate = _modelDelegate;
@synthesize presentationDelegate = _presentationDelegate;
@synthesize modelDelegate = _modelDelegate;
@synthesize commandHandler = _commandHandler;
- (instancetype)initWithLayout:(UICollectionViewLayout*)layout
style:(CollectionViewControllerStyle)style {
......@@ -70,6 +81,87 @@
cellForItemAtIndexPath:indexPath];
[cell setCollapsed:shouldCollapse animated:YES];
}
#pragma mark - Private
- (NSInteger)tagForIndexPath:(NSIndexPath*)indexPath {
return indexPath.item + indexPath.section * kSectionOffset;
}
- (NSIndexPath*)indexPathForTag:(NSInteger)tag {
NSInteger section = tag / kSectionOffset;
NSInteger item = tag - (section * kSectionOffset);
return [NSIndexPath indexPathForItem:item inSection:section];
}
- (void)switchAction:(UISwitch*)sender {
NSIndexPath* indexPath = [self indexPathForTag:sender.tag];
SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>(
[self.collectionViewModel itemAtIndexPath:indexPath]);
BOOL isOn = sender.isOn;
GoogleServicesSettingsCommandID commandID =
static_cast<GoogleServicesSettingsCommandID>(syncSwitchItem.commandID);
switch (commandID) {
case GoogleServicesSettingsCommandIDNoOp:
NOTREACHED();
break;
case GoogleServicesSettingsCommandIDToggleSyncEverything:
[self.commandHandler toggleSyncEverythingWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleBookmarkSync:
[self.commandHandler toggleBookmarksSyncWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleHistorySync:
[self.commandHandler toggleHistorySyncWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDTogglePasswordsSync:
[self.commandHandler togglePasswordsSyncWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleOpenTabsSync:
[self.commandHandler toggleOpenTabSyncWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleAutofillSync:
[self.commandHandler toggleAutofillWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleSettingsSync:
[self.commandHandler toggleSettingsWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleReadingListSync:
[self.commandHandler toggleReadingListWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleActivityAndInteractionsService:
[self.commandHandler toggleActivityAndInteractionsServiceWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleAutocompleteSearchesService:
[self.commandHandler toggleAutocompleteSearchesServiceWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDTogglePreloadPagesService:
[self.commandHandler togglePreloadPagesServiceWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleImproveChromeService:
[self.commandHandler toggleImproveChromeServiceWithValue:isOn];
break;
case GoogleServicesSettingsCommandIDToggleBetterSearchAndBrowsingService:
[self.commandHandler toggleBetterSearchAndBrowsingServiceWithValue:isOn];
break;
}
}
#pragma mark - UICollectionViewDataSource
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
cellForItemAtIndexPath:(NSIndexPath*)indexPath {
UICollectionViewCell* cell =
[super collectionView:collectionView cellForItemAtIndexPath:indexPath];
if ([cell isKindOfClass:[SyncSwitchCell class]]) {
SyncSwitchCell* switchCell =
base::mac::ObjCCastStrict<SyncSwitchCell>(cell);
[switchCell.switchView addTarget:self
action:@selector(switchAction:)
forControlEvents:UIControlEventValueChanged];
switchCell.switchView.tag = [self tagForIndexPath:indexPath];
}
return cell;
}
#pragma mark - CollectionViewController
......
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