| 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/autofill_collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/settings/autofill_collection_view_controller.h" |
| 6 | 6 |
| 7 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #import "base/mac/objc_property_releaser.h" | 9 #import "base/mac/objc_property_releaser.h" |
| 10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 - (CollectionViewItem*)walletSwitchItem { | 164 - (CollectionViewItem*)walletSwitchItem { |
| 165 CollectionViewSwitchItem* switchItem = [[[CollectionViewSwitchItem alloc] | 165 CollectionViewSwitchItem* switchItem = [[[CollectionViewSwitchItem alloc] |
| 166 initWithType:ItemTypeWalletSwitch] autorelease]; | 166 initWithType:ItemTypeWalletSwitch] autorelease]; |
| 167 switchItem.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_USE_WALLET_DATA); | 167 switchItem.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_USE_WALLET_DATA); |
| 168 switchItem.on = [self isWalletEnabled]; | 168 switchItem.on = [self isWalletEnabled]; |
| 169 return switchItem; | 169 return switchItem; |
| 170 } | 170 } |
| 171 | 171 |
| 172 - (CollectionViewItem*)profileSectionHeader { | 172 - (CollectionViewItem*)profileSectionHeader { |
| 173 CollectionViewTextItem* header = [ | 173 CollectionViewTextItem* header = [self genericHeader]; |
| 174 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | |
| 175 header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_ADDRESSES_GROUP_NAME); | 174 header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_ADDRESSES_GROUP_NAME); |
| 176 return header; | 175 return header; |
| 177 } | 176 } |
| 178 | 177 |
| 179 - (CollectionViewItem*)cardSectionHeader { | 178 - (CollectionViewItem*)cardSectionHeader { |
| 180 CollectionViewTextItem* header = [ | 179 CollectionViewTextItem* header = [self genericHeader]; |
| 181 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | |
| 182 header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_CREDITCARDS_GROUP_NAME); | 180 header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_CREDITCARDS_GROUP_NAME); |
| 183 return header; | 181 return header; |
| 184 } | 182 } |
| 185 | 183 |
| 184 - (CollectionViewTextItem*)genericHeader { |
| 185 CollectionViewTextItem* header = [ |
| 186 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; |
| 187 header.textColor = [[MDCPalette greyPalette] tint500]; |
| 188 return header; |
| 189 } |
| 190 |
| 186 - (CollectionViewItem*)itemForProfile: | 191 - (CollectionViewItem*)itemForProfile: |
| 187 (const autofill::AutofillProfile&)autofillProfile { | 192 (const autofill::AutofillProfile&)autofillProfile { |
| 188 std::string guid(autofillProfile.guid()); | 193 std::string guid(autofillProfile.guid()); |
| 189 NSString* title = base::SysUTF16ToNSString(autofillProfile.GetInfo( | 194 NSString* title = base::SysUTF16ToNSString(autofillProfile.GetInfo( |
| 190 autofill::AutofillType(autofill::NAME_FULL), _locale)); | 195 autofill::AutofillType(autofill::NAME_FULL), _locale)); |
| 191 NSString* subTitle = base::SysUTF16ToNSString(autofillProfile.GetInfo( | 196 NSString* subTitle = base::SysUTF16ToNSString(autofillProfile.GetInfo( |
| 192 autofill::AutofillType(autofill::ADDRESS_HOME_LINE1), _locale)); | 197 autofill::AutofillType(autofill::ADDRESS_HOME_LINE1), _locale)); |
| 193 bool isServerProfile = autofillProfile.record_type() == | 198 bool isServerProfile = autofillProfile.record_type() == |
| 194 autofill::AutofillProfile::SERVER_PROFILE; | 199 autofill::AutofillProfile::SERVER_PROFILE; |
| 195 | 200 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } else if (itemType == ItemTypeWalletSwitch) { | 267 } else if (itemType == ItemTypeWalletSwitch) { |
| 263 CollectionViewSwitchCell* switchCell = | 268 CollectionViewSwitchCell* switchCell = |
| 264 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell); | 269 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell); |
| 265 [switchCell.switchView addTarget:self | 270 [switchCell.switchView addTarget:self |
| 266 action:@selector(walletSwitchChanged:) | 271 action:@selector(walletSwitchChanged:) |
| 267 forControlEvents:UIControlEventValueChanged]; | 272 forControlEvents:UIControlEventValueChanged]; |
| 268 } | 273 } |
| 269 return cell; | 274 return cell; |
| 270 } | 275 } |
| 271 | 276 |
| 272 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView | |
| 273 viewForSupplementaryElementOfKind:(NSString*)kind | |
| 274 atIndexPath:(NSIndexPath*)indexPath { | |
| 275 UICollectionReusableView* view = [super collectionView:collectionView | |
| 276 viewForSupplementaryElementOfKind:kind | |
| 277 atIndexPath:indexPath]; | |
| 278 MDCCollectionViewTextCell* textCell = | |
| 279 base::mac::ObjCCast<MDCCollectionViewTextCell>(view); | |
| 280 if (textCell) { | |
| 281 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; | |
| 282 } | |
| 283 return view; | |
| 284 } | |
| 285 | |
| 286 #pragma mark - Switch Callbacks | 277 #pragma mark - Switch Callbacks |
| 287 | 278 |
| 288 - (void)autofillSwitchChanged:(UISwitch*)switchView { | 279 - (void)autofillSwitchChanged:(UISwitch*)switchView { |
| 289 [self setSwitchItemOn:[switchView isOn] itemType:ItemTypeAutofillSwitch]; | 280 [self setSwitchItemOn:[switchView isOn] itemType:ItemTypeAutofillSwitch]; |
| 290 _userInteractionInProgress = YES; | 281 _userInteractionInProgress = YES; |
| 291 [self setAutofillEnabled:[switchView isOn]]; | 282 [self setAutofillEnabled:[switchView isOn]]; |
| 292 _userInteractionInProgress = NO; | 283 _userInteractionInProgress = NO; |
| 293 [self updateEditButton]; | 284 [self updateEditButton]; |
| 294 | 285 |
| 295 // Avoid reference cycle in block. | 286 // Avoid reference cycle in block. |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 return _browserState->GetPrefs()->GetBoolean( | 611 return _browserState->GetPrefs()->GetBoolean( |
| 621 autofill::prefs::kAutofillWalletImportEnabled); | 612 autofill::prefs::kAutofillWalletImportEnabled); |
| 622 } | 613 } |
| 623 | 614 |
| 624 - (void)setWalletEnabled:(BOOL)isEnabled { | 615 - (void)setWalletEnabled:(BOOL)isEnabled { |
| 625 _browserState->GetPrefs()->SetBoolean( | 616 _browserState->GetPrefs()->SetBoolean( |
| 626 autofill::prefs::kAutofillWalletImportEnabled, isEnabled); | 617 autofill::prefs::kAutofillWalletImportEnabled, isEnabled); |
| 627 } | 618 } |
| 628 | 619 |
| 629 @end | 620 @end |
| OLD | NEW |