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

[iOS] Adding Manage sync settings item in Google services settings

Screenshot: https://screenshot.googleplex.com/7Bp9z54Le5s

Bug: 914059
Change-Id: I12ed57a7b2e456f542c14647b959396617ea61c4
Reviewed-on: https://chromium-review.googlesource.com/c/1416144
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625790}
parent 200a953f
......@@ -23,6 +23,9 @@
// Opens the account setting view.
- (void)openAccountSettings;
// Opens the manage sync settings view.
- (void)openManageSyncSettings;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_SETTINGS_COMMAND_HANDLER_H_
......@@ -18,6 +18,7 @@
#import "ios/chrome/browser/ui/settings/google_services_settings_command_handler.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_mediator.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_view_controller.h"
#import "ios/chrome/browser/ui/settings/manage_sync_settings_coordinator.h"
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_coordinator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -26,7 +27,8 @@
@interface GoogleServicesSettingsCoordinator () <
GoogleServicesSettingsCommandHandler,
GoogleServicesSettingsViewControllerPresentationDelegate>
GoogleServicesSettingsViewControllerPresentationDelegate,
ManageSyncSettingsCoordinatorDelegate>
// Google services settings mediator.
@property(nonatomic, strong) GoogleServicesSettingsMediator* mediator;
......@@ -41,6 +43,9 @@
// Settings page.
@property(nonatomic, strong)
SigninInteractionCoordinator* signinInteractionCoordinator;
// Coordinator to present the manage sync settings.
@property(nonatomic, strong)
ManageSyncSettingsCoordinator* manageSyncSettingsCoordinator;
@end
......@@ -162,6 +167,17 @@
[self.navigationController pushViewController:controller animated:YES];
}
- (void)openManageSyncSettings {
DCHECK(!self.manageSyncSettingsCoordinator);
self.manageSyncSettingsCoordinator = [[ManageSyncSettingsCoordinator alloc]
initWithBaseViewController:self.viewController
browserState:self.browserState];
self.manageSyncSettingsCoordinator.navigationController =
self.navigationController;
self.manageSyncSettingsCoordinator.delegate = self;
[self.manageSyncSettingsCoordinator start];
}
#pragma mark - GoogleServicesSettingsViewControllerPresentationDelegate
- (void)googleServicesSettingsViewControllerDidRemove:
......@@ -170,4 +186,12 @@
[self.delegate googleServicesSettingsCoordinatorDidRemove:self];
}
#pragma mark - ManageSyncSettingsCoordinatorDelegate
- (void)manageSyncSettingsCoordinatorWasPopped:
(ManageSyncSettingsCoordinator*)coordinator {
DCHECK_EQ(self.manageSyncSettingsCoordinator, coordinator);
self.manageSyncSettingsCoordinator = nil;
}
@end
......@@ -19,6 +19,7 @@
#import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h"
#import "ios/chrome/browser/ui/settings/cells/account_sign_in_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_image_detail_text_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_multiline_detail_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/sync_utils/sync_util.h"
......@@ -56,6 +57,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
RestartAuthenticationFlowErrorItemType,
ReauthDialogAsSyncIsInAuthErrorItemType,
ShowPassphraseDialogErrorItemType,
ManageSyncItemType,
// NonPersonalizedSectionIdentifier section.
AutocompleteSearchesAndURLsItemType,
PreloadPagesItemType,
......@@ -240,8 +242,10 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)updateSyncSection:(BOOL)notifyConsumer {
BOOL needsAccountSigninItemUpdate = [self updateAccountSignInItem];
BOOL needsSyncErrorItemsUpdate = [self updateSyncErrorItems];
BOOL needsManageSyncItemUpdate = [self updateManageSyncItem];
if (notifyConsumer &&
(needsAccountSigninItemUpdate || needsSyncErrorItemsUpdate)) {
(needsAccountSigninItemUpdate || needsSyncErrorItemsUpdate ||
needsManageSyncItemUpdate)) {
TableViewModel* model = self.consumer.tableViewModel;
NSUInteger sectionIndex =
[model sectionForSectionIdentifier:SyncSectionIdentifier];
......@@ -336,6 +340,29 @@ typedef NS_ENUM(NSInteger, ItemType) {
return YES;
}
// Reloads the manage sync item, and returns YES if the section should be
// reloaded.
- (BOOL)updateManageSyncItem {
TableViewModel* model = self.consumer.tableViewModel;
BOOL hasManageSyncItem = [model hasItemForItemType:ManageSyncItemType
sectionIdentifier:SyncSectionIdentifier];
if (self.isAuthenticated) {
if (hasManageSyncItem)
return NO;
SettingsMultilineDetailItem* item =
[[SettingsMultilineDetailItem alloc] initWithType:ManageSyncItemType];
item.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
item.text = GetNSString(IDS_IOS_MANAGE_SYNC_SETTINGS_TITLE);
[model addItem:item toSectionWithIdentifier:SyncSectionIdentifier];
return YES;
}
if (!hasManageSyncItem)
return NO;
[model removeItemWithType:ManageSyncItemType
fromSectionWithIdentifier:SyncSectionIdentifier];
return YES;
}
#pragma mark - Load non personalized section
// Loads NonPersonalizedSectionIdentifier section.
......@@ -373,6 +400,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
case RestartAuthenticationFlowErrorItemType:
case ReauthDialogAsSyncIsInAuthErrorItemType:
case ShowPassphraseDialogErrorItemType:
case ManageSyncItemType:
NOTREACHED();
break;
}
......@@ -503,6 +531,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
case RestartAuthenticationFlowErrorItemType:
case ReauthDialogAsSyncIsInAuthErrorItemType:
case ShowPassphraseDialogErrorItemType:
case ManageSyncItemType:
NOTREACHED();
break;
}
......@@ -526,6 +555,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
case ShowPassphraseDialogErrorItemType:
[self.commandHandler openPassphraseDialog];
break;
case ManageSyncItemType:
[self.commandHandler openManageSyncSettings];
break;
case AutocompleteSearchesAndURLsItemType:
case PreloadPagesItemType:
case ImproveChromeItemType:
......
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