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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 263 |
264 // Sync to Section. | 264 // Sync to Section. |
265 if ([self hasAccountsSection]) { | 265 if ([self hasAccountsSection]) { |
266 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = | 266 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = |
267 [[[NSMutableDictionary alloc] init] autorelease]; | 267 [[[NSMutableDictionary alloc] init] autorelease]; |
268 // Accounts section. Cells enabled if sync is on. | 268 // Accounts section. Cells enabled if sync is on. |
269 [model addSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 269 [model addSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
270 CollectionViewTextItem* syncToHeader = [[[CollectionViewTextItem alloc] | 270 CollectionViewTextItem* syncToHeader = [[[CollectionViewTextItem alloc] |
271 initWithType:ItemTypeHeader] autorelease]; | 271 initWithType:ItemTypeHeader] autorelease]; |
272 syncToHeader.text = l10n_util::GetNSString(IDS_IOS_SYNC_TO_TITLE); | 272 syncToHeader.text = l10n_util::GetNSString(IDS_IOS_SYNC_TO_TITLE); |
| 273 syncToHeader.textColor = [[MDCPalette greyPalette] tint500]; |
273 [model setHeader:syncToHeader | 274 [model setHeader:syncToHeader |
274 forSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 275 forSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
275 ProfileOAuth2TokenService* oauth2_service = | 276 ProfileOAuth2TokenService* oauth2_service = |
276 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); | 277 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); |
277 AccountTrackerService* accountTracker = | 278 AccountTrackerService* accountTracker = |
278 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); | 279 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); |
279 | 280 |
280 for (const std::string& account_id : oauth2_service->GetAccounts()) { | 281 for (const std::string& account_id : oauth2_service->GetAccounts()) { |
281 AccountInfo account = accountTracker->GetAccountInfo(account_id); | 282 AccountInfo account = accountTracker->GetAccountInfo(account_id); |
282 ChromeIdentity* identity = ios::GetChromeBrowserProvider() | 283 ChromeIdentity* identity = ios::GetChromeBrowserProvider() |
283 ->GetChromeIdentityService() | 284 ->GetChromeIdentityService() |
284 ->GetIdentityWithGaiaID(account.gaia); | 285 ->GetIdentityWithGaiaID(account.gaia); |
285 CollectionViewItem* accountItem = [self accountItem:identity]; | 286 CollectionViewItem* accountItem = [self accountItem:identity]; |
286 [model addItem:accountItem | 287 [model addItem:accountItem |
287 toSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 288 toSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
288 [mutableIdentityMap setObject:accountItem forKey:identity.gaiaID]; | 289 [mutableIdentityMap setObject:accountItem forKey:identity.gaiaID]; |
289 } | 290 } |
290 _identityMap.reset([mutableIdentityMap retain]); | 291 _identityMap.reset([mutableIdentityMap retain]); |
291 } | 292 } |
292 | 293 |
293 // Data Types to sync. Enabled if sync is on. | 294 // Data Types to sync. Enabled if sync is on. |
294 [model addSectionWithIdentifier:SectionIdentifierSyncServices]; | 295 [model addSectionWithIdentifier:SectionIdentifierSyncServices]; |
295 CollectionViewTextItem* syncServicesHeader = [ | 296 CollectionViewTextItem* syncServicesHeader = [ |
296 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | 297 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; |
297 syncServicesHeader.text = | 298 syncServicesHeader.text = |
298 l10n_util::GetNSString(IDS_IOS_SYNC_DATA_TYPES_TITLE); | 299 l10n_util::GetNSString(IDS_IOS_SYNC_DATA_TYPES_TITLE); |
| 300 syncServicesHeader.textColor = [[MDCPalette greyPalette] tint500]; |
299 [model setHeader:syncServicesHeader | 301 [model setHeader:syncServicesHeader |
300 forSectionWithIdentifier:SectionIdentifierSyncServices]; | 302 forSectionWithIdentifier:SectionIdentifierSyncServices]; |
301 BOOL syncEverythingEnabled = _syncSetupService->IsSyncingAllDataTypes(); | 303 BOOL syncEverythingEnabled = _syncSetupService->IsSyncingAllDataTypes(); |
302 [model addItem:[self syncEverythingSwitchItem:syncEverythingEnabled] | 304 [model addItem:[self syncEverythingSwitchItem:syncEverythingEnabled] |
303 toSectionWithIdentifier:SectionIdentifierSyncServices]; | 305 toSectionWithIdentifier:SectionIdentifierSyncServices]; |
304 // Specific Data Types to sync. Enabled if Sync Everything is off. | 306 // Specific Data Types to sync. Enabled if Sync Everything is off. |
305 for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; ++i) { | 307 for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; ++i) { |
306 SyncSetupService::SyncableDatatype dataType = | 308 SyncSetupService::SyncableDatatype dataType = |
307 static_cast<SyncSetupService::SyncableDatatype>(i); | 309 static_cast<SyncSetupService::SyncableDatatype>(i); |
308 [model addItem:[self switchItemForDataType:dataType] | 310 [model addItem:[self switchItemForDataType:dataType] |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 forControlEvents:UIControlEventValueChanged]; | 460 forControlEvents:UIControlEventValueChanged]; |
459 switchCell.switchView.tag = [self tagForIndexPath:indexPath]; | 461 switchCell.switchView.tag = [self tagForIndexPath:indexPath]; |
460 break; | 462 break; |
461 } | 463 } |
462 default: | 464 default: |
463 break; | 465 break; |
464 } | 466 } |
465 return cell; | 467 return cell; |
466 } | 468 } |
467 | 469 |
468 // Method for overriding the header view of a section. Used to set the header | |
469 // text color to gray. | |
470 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView | |
471 viewForSupplementaryElementOfKind:(NSString*)kind | |
472 atIndexPath:(NSIndexPath*)indexPath { | |
473 UICollectionReusableView* view = [super collectionView:collectionView | |
474 viewForSupplementaryElementOfKind:kind | |
475 atIndexPath:indexPath]; | |
476 | |
477 MDCCollectionViewTextCell* textCell = | |
478 base::mac::ObjCCast<MDCCollectionViewTextCell>(view); | |
479 if (textCell) { | |
480 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; | |
481 } | |
482 return view; | |
483 } | |
484 | |
485 #pragma mark UICollectionViewDelegate | 470 #pragma mark UICollectionViewDelegate |
486 | 471 |
487 - (void)collectionView:(UICollectionView*)collectionView | 472 - (void)collectionView:(UICollectionView*)collectionView |
488 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 473 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
489 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 474 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
490 | 475 |
491 NSInteger itemType = | 476 NSInteger itemType = |
492 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 477 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
493 switch (itemType) { | 478 switch (itemType) { |
494 case ItemTypeSyncError: | 479 case ItemTypeSyncError: |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 [self updateAccountItem:item withIdentity:identity]; | 967 [self updateAccountItem:item withIdentity:identity]; |
983 [self reconfigureCellsForItems:@[ item ] | 968 [self reconfigureCellsForItems:@[ item ] |
984 inSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 969 inSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
985 } | 970 } |
986 | 971 |
987 - (void)onChromeIdentityServiceWillBeDestroyed { | 972 - (void)onChromeIdentityServiceWillBeDestroyed { |
988 _identityServiceObserver.reset(); | 973 _identityServiceObserver.reset(); |
989 } | 974 } |
990 | 975 |
991 @end | 976 @end |
OLD | NEW |