| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/settings/sync_settings_collection_view_controller
.h" | 5 #import "ios/chrome/browser/ui/settings/sync_settings_collection_view_controller
.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #import "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h" | 25 #import "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h" |
| 26 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" | 26 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" |
| 27 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 27 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
| 28 #include "ios/chrome/browser/sync/sync_setup_service.h" | 28 #include "ios/chrome/browser/sync/sync_setup_service.h" |
| 29 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 29 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
| 30 #import "ios/chrome/browser/ui/authentication/authentication_flow.h" | 30 #import "ios/chrome/browser/ui/authentication/authentication_flow.h" |
| 31 #import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h" | 31 #import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h" |
| 32 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 32 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 33 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_account_ite
m.h" | 33 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_account_ite
m.h" |
| 34 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" | 34 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" |
| 35 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h
" |
| 35 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 36 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 36 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 37 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 37 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 38 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 38 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 39 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 39 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 40 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 40 #import "ios/chrome/browser/ui/commands/open_url_command.h" | 41 #import "ios/chrome/browser/ui/commands/open_url_command.h" |
| 41 #import "ios/chrome/browser/ui/settings/cells/sync_switch_item.h" | 42 #import "ios/chrome/browser/ui/settings/cells/sync_switch_item.h" |
| 42 #import "ios/chrome/browser/ui/settings/cells/text_and_error_item.h" | 43 #import "ios/chrome/browser/ui/settings/cells/text_and_error_item.h" |
| 43 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" | 44 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" |
| 44 #import "ios/chrome/browser/ui/settings/sync_encryption_collection_view_controll
er.h" | 45 #import "ios/chrome/browser/ui/settings/sync_encryption_collection_view_controll
er.h" |
| 45 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi
ew_controller.h" | 46 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi
ew_controller.h" |
| 46 #import "ios/chrome/browser/ui/sync/sync_util.h" | 47 #import "ios/chrome/browser/ui/sync/sync_util.h" |
| 47 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 48 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 48 #include "ios/chrome/grit/ios_strings.h" | 49 #include "ios/chrome/grit/ios_strings.h" |
| 49 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 50 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 50 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 51 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
| 51 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" | 52 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
| 53 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 54 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 52 #include "ui/base/l10n/l10n_util_mac.h" | 55 #include "ui/base/l10n/l10n_util_mac.h" |
| 53 #include "url/gurl.h" | 56 #include "url/gurl.h" |
| 54 | 57 |
| 55 // The a11y identifier of the view controller's view. | 58 // The a11y identifier of the view controller's view. |
| 56 NSString* const kSettingsSyncId = @"kSettingsSyncId"; | 59 NSString* const kSettingsSyncId = @"kSettingsSyncId"; |
| 57 // Notification when a switch account operation will start. | 60 // Notification when a switch account operation will start. |
| 58 NSString* const kSwitchAccountWillStartNotification = | 61 NSString* const kSwitchAccountWillStartNotification = |
| 59 @"kSwitchAccountWillStartNotification"; | 62 @"kSwitchAccountWillStartNotification"; |
| 60 // Notification when a switch account operation did finish. | 63 // Notification when a switch account operation did finish. |
| 61 NSString* const kSwitchAccountDidFinishNotification = | 64 NSString* const kSwitchAccountDidFinishNotification = |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 266 |
| 264 // Sync to Section. | 267 // Sync to Section. |
| 265 if ([self hasAccountsSection]) { | 268 if ([self hasAccountsSection]) { |
| 266 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = | 269 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = |
| 267 [[[NSMutableDictionary alloc] init] autorelease]; | 270 [[[NSMutableDictionary alloc] init] autorelease]; |
| 268 // Accounts section. Cells enabled if sync is on. | 271 // Accounts section. Cells enabled if sync is on. |
| 269 [model addSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 272 [model addSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
| 270 CollectionViewTextItem* syncToHeader = [[[CollectionViewTextItem alloc] | 273 CollectionViewTextItem* syncToHeader = [[[CollectionViewTextItem alloc] |
| 271 initWithType:ItemTypeHeader] autorelease]; | 274 initWithType:ItemTypeHeader] autorelease]; |
| 272 syncToHeader.text = l10n_util::GetNSString(IDS_IOS_SYNC_TO_TITLE); | 275 syncToHeader.text = l10n_util::GetNSString(IDS_IOS_SYNC_TO_TITLE); |
| 273 syncToHeader.textColor = [[MDCPalette greyPalette] tint500]; | |
| 274 [model setHeader:syncToHeader | 276 [model setHeader:syncToHeader |
| 275 forSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 277 forSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
| 276 ProfileOAuth2TokenService* oauth2_service = | 278 ProfileOAuth2TokenService* oauth2_service = |
| 277 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); | 279 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); |
| 278 AccountTrackerService* accountTracker = | 280 AccountTrackerService* accountTracker = |
| 279 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); | 281 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); |
| 280 | 282 |
| 281 for (const std::string& account_id : oauth2_service->GetAccounts()) { | 283 for (const std::string& account_id : oauth2_service->GetAccounts()) { |
| 282 AccountInfo account = accountTracker->GetAccountInfo(account_id); | 284 AccountInfo account = accountTracker->GetAccountInfo(account_id); |
| 283 ChromeIdentity* identity = ios::GetChromeBrowserProvider() | 285 ChromeIdentity* identity = ios::GetChromeBrowserProvider() |
| 284 ->GetChromeIdentityService() | 286 ->GetChromeIdentityService() |
| 285 ->GetIdentityWithGaiaID(account.gaia); | 287 ->GetIdentityWithGaiaID(account.gaia); |
| 286 CollectionViewItem* accountItem = [self accountItem:identity]; | 288 CollectionViewItem* accountItem = [self accountItem:identity]; |
| 287 [model addItem:accountItem | 289 [model addItem:accountItem |
| 288 toSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 290 toSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
| 289 [mutableIdentityMap setObject:accountItem forKey:identity.gaiaID]; | 291 [mutableIdentityMap setObject:accountItem forKey:identity.gaiaID]; |
| 290 } | 292 } |
| 291 _identityMap.reset([mutableIdentityMap retain]); | 293 _identityMap.reset([mutableIdentityMap retain]); |
| 292 } | 294 } |
| 293 | 295 |
| 294 // Data Types to sync. Enabled if sync is on. | 296 // Data Types to sync. Enabled if sync is on. |
| 295 [model addSectionWithIdentifier:SectionIdentifierSyncServices]; | 297 [model addSectionWithIdentifier:SectionIdentifierSyncServices]; |
| 296 CollectionViewTextItem* syncServicesHeader = [ | 298 CollectionViewTextItem* syncServicesHeader = [ |
| 297 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | 299 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; |
| 298 syncServicesHeader.text = | 300 syncServicesHeader.text = |
| 299 l10n_util::GetNSString(IDS_IOS_SYNC_DATA_TYPES_TITLE); | 301 l10n_util::GetNSString(IDS_IOS_SYNC_DATA_TYPES_TITLE); |
| 300 syncServicesHeader.textColor = [[MDCPalette greyPalette] tint500]; | |
| 301 [model setHeader:syncServicesHeader | 302 [model setHeader:syncServicesHeader |
| 302 forSectionWithIdentifier:SectionIdentifierSyncServices]; | 303 forSectionWithIdentifier:SectionIdentifierSyncServices]; |
| 303 BOOL syncEverythingEnabled = _syncSetupService->IsSyncingAllDataTypes(); | 304 BOOL syncEverythingEnabled = _syncSetupService->IsSyncingAllDataTypes(); |
| 304 [model addItem:[self syncEverythingSwitchItem:syncEverythingEnabled] | 305 [model addItem:[self syncEverythingSwitchItem:syncEverythingEnabled] |
| 305 toSectionWithIdentifier:SectionIdentifierSyncServices]; | 306 toSectionWithIdentifier:SectionIdentifierSyncServices]; |
| 306 // Specific Data Types to sync. Enabled if Sync Everything is off. | 307 // Specific Data Types to sync. Enabled if Sync Everything is off. |
| 307 for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; ++i) { | 308 for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; ++i) { |
| 308 SyncSetupService::SyncableDatatype dataType = | 309 SyncSetupService::SyncableDatatype dataType = |
| 309 static_cast<SyncSetupService::SyncableDatatype>(i); | 310 static_cast<SyncSetupService::SyncableDatatype>(i); |
| 310 [model addItem:[self switchItemForDataType:dataType] | 311 [model addItem:[self switchItemForDataType:dataType] |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 455 } |
| 455 case ItemTypeSyncableDataType: { | 456 case ItemTypeSyncableDataType: { |
| 456 SyncSwitchCell* switchCell = | 457 SyncSwitchCell* switchCell = |
| 457 base::mac::ObjCCastStrict<SyncSwitchCell>(cell); | 458 base::mac::ObjCCastStrict<SyncSwitchCell>(cell); |
| 458 [switchCell.switchView addTarget:self | 459 [switchCell.switchView addTarget:self |
| 459 action:@selector(changeDataTypeSyncStatusToOn:) | 460 action:@selector(changeDataTypeSyncStatusToOn:) |
| 460 forControlEvents:UIControlEventValueChanged]; | 461 forControlEvents:UIControlEventValueChanged]; |
| 461 switchCell.switchView.tag = [self tagForIndexPath:indexPath]; | 462 switchCell.switchView.tag = [self tagForIndexPath:indexPath]; |
| 462 break; | 463 break; |
| 463 } | 464 } |
| 465 case ItemTypeHeader: |
| 466 case ItemTypeManageSyncedData: { |
| 467 CollectionViewTextCell* textCell = |
| 468 base::mac::ObjCCastStrict<CollectionViewTextCell>(cell); |
| 469 textCell.textLabel.font = [MDCTypography body2Font]; |
| 470 if (itemType == ItemTypeHeader) |
| 471 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 472 else |
| 473 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint900]; |
| 474 textCell.detailTextLabel.font = [MDCTypography body1Font]; |
| 475 textCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 476 break; |
| 477 } |
| 464 default: | 478 default: |
| 465 break; | 479 break; |
| 466 } | 480 } |
| 467 return cell; | 481 return cell; |
| 468 } | 482 } |
| 469 | 483 |
| 470 #pragma mark UICollectionViewDelegate | 484 #pragma mark UICollectionViewDelegate |
| 471 | 485 |
| 472 - (void)collectionView:(UICollectionView*)collectionView | 486 - (void)collectionView:(UICollectionView*)collectionView |
| 473 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 487 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 [self updateAccountItem:item withIdentity:identity]; | 981 [self updateAccountItem:item withIdentity:identity]; |
| 968 [self reconfigureCellsForItems:@[ item ] | 982 [self reconfigureCellsForItems:@[ item ] |
| 969 inSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 983 inSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
| 970 } | 984 } |
| 971 | 985 |
| 972 - (void)onChromeIdentityServiceWillBeDestroyed { | 986 - (void)onChromeIdentityServiceWillBeDestroyed { |
| 973 _identityServiceObserver.reset(); | 987 _identityServiceObserver.reset(); |
| 974 } | 988 } |
| 975 | 989 |
| 976 @end | 990 @end |
| OLD | NEW |