| 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/settings_collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
| 10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 572 |
| 573 #pragma mark Item Updaters | 573 #pragma mark Item Updaters |
| 574 | 574 |
| 575 - (void)updateSearchCell { | 575 - (void)updateSearchCell { |
| 576 NSString* defaultSearchEngineName = | 576 NSString* defaultSearchEngineName = |
| 577 base::SysUTF16ToNSString(GetDefaultSearchEngineName( | 577 base::SysUTF16ToNSString(GetDefaultSearchEngineName( |
| 578 ios::TemplateURLServiceFactory::GetForBrowserState( | 578 ios::TemplateURLServiceFactory::GetForBrowserState( |
| 579 _mainBrowserState))); | 579 _mainBrowserState))); |
| 580 | 580 |
| 581 _defaultSearchEngineItem.get().detailText = defaultSearchEngineName; | 581 _defaultSearchEngineItem.get().detailText = defaultSearchEngineName; |
| 582 [self reconfigureCellsForItems:@[ _defaultSearchEngineItem ] | 582 [self reconfigureCellsForItems:@[ _defaultSearchEngineItem ]]; |
| 583 inSectionWithIdentifier:SectionIdentifierBasics]; | |
| 584 } | 583 } |
| 585 | 584 |
| 586 #pragma mark Item Constructors | 585 #pragma mark Item Constructors |
| 587 | 586 |
| 588 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type | 587 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type |
| 589 text:(NSString*)text | 588 text:(NSString*)text |
| 590 detailText:(NSString*)detailText { | 589 detailText:(NSString*)detailText { |
| 591 CollectionViewDetailItem* detailItem = | 590 CollectionViewDetailItem* detailItem = |
| 592 [[[CollectionViewDetailItem alloc] initWithType:type] autorelease]; | 591 [[[CollectionViewDetailItem alloc] initWithType:type] autorelease]; |
| 593 detailItem.text = text; | 592 detailItem.text = text; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 return; | 957 return; |
| 959 } | 958 } |
| 960 NSIndexPath* accountCellIndexPath = | 959 NSIndexPath* accountCellIndexPath = |
| 961 [self.collectionViewModel indexPathForItemType:ItemTypeAccount | 960 [self.collectionViewModel indexPathForItemType:ItemTypeAccount |
| 962 sectionIdentifier:SectionIdentifierSignIn]; | 961 sectionIdentifier:SectionIdentifierSignIn]; |
| 963 CollectionViewAccountItem* identityAccountItem = | 962 CollectionViewAccountItem* identityAccountItem = |
| 964 base::mac::ObjCCast<CollectionViewAccountItem>( | 963 base::mac::ObjCCast<CollectionViewAccountItem>( |
| 965 [self.collectionViewModel itemAtIndexPath:accountCellIndexPath]); | 964 [self.collectionViewModel itemAtIndexPath:accountCellIndexPath]); |
| 966 if (identityAccountItem) { | 965 if (identityAccountItem) { |
| 967 [self updateIdentityAccountItem:identityAccountItem]; | 966 [self updateIdentityAccountItem:identityAccountItem]; |
| 968 [self reconfigureCellsForItems:@[ identityAccountItem ] | 967 [self reconfigureCellsForItems:@[ identityAccountItem ]]; |
| 969 inSectionWithIdentifier:SectionIdentifierSignIn]; | |
| 970 } | 968 } |
| 971 } | 969 } |
| 972 | 970 |
| 973 #pragma mark Sign in | 971 #pragma mark Sign in |
| 974 | 972 |
| 975 - (void)showSignInWithIdentity:(ChromeIdentity*)identity { | 973 - (void)showSignInWithIdentity:(ChromeIdentity*)identity { |
| 976 base::RecordAction(base::UserMetricsAction("Signin_Signin_FromSettings")); | 974 base::RecordAction(base::UserMetricsAction("Signin_Signin_FromSettings")); |
| 977 DCHECK(!_signinInteractionController); | 975 DCHECK(!_signinInteractionController); |
| 978 _signinInteractionController.reset([[SigninInteractionController alloc] | 976 _signinInteractionController.reset([[SigninInteractionController alloc] |
| 979 initWithBrowserState:_mainBrowserState | 977 initWithBrowserState:_mainBrowserState |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 } | 1071 } |
| 1074 | 1072 |
| 1075 #pragma mark - BooleanObserver | 1073 #pragma mark - BooleanObserver |
| 1076 | 1074 |
| 1077 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { | 1075 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { |
| 1078 DCHECK_EQ(observableBoolean, _showMemoryDebugToolsEnabled.get()); | 1076 DCHECK_EQ(observableBoolean, _showMemoryDebugToolsEnabled.get()); |
| 1079 // Update the Item. | 1077 // Update the Item. |
| 1080 _showMemoryDebugToolsItem.get().on = [_showMemoryDebugToolsEnabled value]; | 1078 _showMemoryDebugToolsItem.get().on = [_showMemoryDebugToolsEnabled value]; |
| 1081 | 1079 |
| 1082 // Update the Cell. | 1080 // Update the Cell. |
| 1083 [self reconfigureCellsForItems:@[ _showMemoryDebugToolsItem ] | 1081 [self reconfigureCellsForItems:@[ _showMemoryDebugToolsItem ]]; |
| 1084 inSectionWithIdentifier:SectionIdentifierDebug]; | |
| 1085 } | 1082 } |
| 1086 | 1083 |
| 1087 #pragma mark - PrefObserverDelegate | 1084 #pragma mark - PrefObserverDelegate |
| 1088 | 1085 |
| 1089 - (void)onPreferenceChanged:(const std::string&)preferenceName { | 1086 - (void)onPreferenceChanged:(const std::string&)preferenceName { |
| 1090 if (preferenceName == prefs::kVoiceSearchLocale) { | 1087 if (preferenceName == prefs::kVoiceSearchLocale) { |
| 1091 voice::SpeechInputLocaleConfig* localeConfig = | 1088 voice::SpeechInputLocaleConfig* localeConfig = |
| 1092 voice::SpeechInputLocaleConfig::GetInstance(); | 1089 voice::SpeechInputLocaleConfig::GetInstance(); |
| 1093 voice::SpeechInputLocale locale = | 1090 voice::SpeechInputLocale locale = |
| 1094 _voiceLocaleCode.GetValue().length() | 1091 _voiceLocaleCode.GetValue().length() |
| 1095 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) | 1092 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) |
| 1096 : localeConfig->GetDefaultLocale(); | 1093 : localeConfig->GetDefaultLocale(); |
| 1097 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); | 1094 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); |
| 1098 _voiceSearchDetailItem.get().detailText = languageName; | 1095 _voiceSearchDetailItem.get().detailText = languageName; |
| 1099 [self reconfigureCellsForItems:@[ _voiceSearchDetailItem ] | 1096 [self reconfigureCellsForItems:@[ _voiceSearchDetailItem ]]; |
| 1100 inSectionWithIdentifier:SectionIdentifierAdvanced]; | |
| 1101 } | 1097 } |
| 1102 | 1098 |
| 1103 if (preferenceName == | 1099 if (preferenceName == |
| 1104 password_manager::prefs::kPasswordManagerSavingEnabled) { | 1100 password_manager::prefs::kPasswordManagerSavingEnabled) { |
| 1105 BOOL savePasswordsEnabled = | 1101 BOOL savePasswordsEnabled = |
| 1106 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); | 1102 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); |
| 1107 NSString* passwordsDetail = | 1103 NSString* passwordsDetail = |
| 1108 savePasswordsEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 1104 savePasswordsEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 1109 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 1105 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 1110 | 1106 |
| 1111 _savePasswordsDetailItem.get().detailText = passwordsDetail; | 1107 _savePasswordsDetailItem.get().detailText = passwordsDetail; |
| 1112 [self reconfigureCellsForItems:@[ _savePasswordsDetailItem ] | 1108 [self reconfigureCellsForItems:@[ _savePasswordsDetailItem ]]; |
| 1113 inSectionWithIdentifier:SectionIdentifierBasics]; | |
| 1114 } | 1109 } |
| 1115 | 1110 |
| 1116 if (preferenceName == autofill::prefs::kAutofillEnabled) { | 1111 if (preferenceName == autofill::prefs::kAutofillEnabled) { |
| 1117 BOOL autofillEnabled = | 1112 BOOL autofillEnabled = |
| 1118 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); | 1113 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); |
| 1119 NSString* autofillDetail = | 1114 NSString* autofillDetail = |
| 1120 autofillEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 1115 autofillEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 1121 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 1116 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 1122 _autoFillDetailItem.get().detailText = autofillDetail; | 1117 _autoFillDetailItem.get().detailText = autofillDetail; |
| 1123 [self reconfigureCellsForItems:@[ _autoFillDetailItem ] | 1118 [self reconfigureCellsForItems:@[ _autoFillDetailItem ]]; |
| 1124 inSectionWithIdentifier:SectionIdentifierBasics]; | |
| 1125 } | 1119 } |
| 1126 } | 1120 } |
| 1127 | 1121 |
| 1128 #pragma mark - SigninPromoViewConsumer | 1122 #pragma mark - SigninPromoViewConsumer |
| 1129 | 1123 |
| 1130 - (void)configureSigninPromoViewWithNewIdentity:(BOOL)newIdentity | 1124 - (void)configureSigninPromoViewWithNewIdentity:(BOOL)newIdentity |
| 1131 configurator:(SigninPromoViewConfigurator*) | 1125 configurator:(SigninPromoViewConfigurator*) |
| 1132 configurator { | 1126 configurator { |
| 1133 if (![self.collectionViewModel hasItemForItemType:ItemTypeSigninPromo | 1127 if (![self.collectionViewModel hasItemForItemType:ItemTypeSigninPromo |
| 1134 sectionIdentifier:SectionIdentifierSignIn]) { | 1128 sectionIdentifier:SectionIdentifierSignIn]) { |
| 1135 return; | 1129 return; |
| 1136 } | 1130 } |
| 1137 NSIndexPath* signinPromoCellIndexPath = | 1131 NSIndexPath* signinPromoCellIndexPath = |
| 1138 [self.collectionViewModel indexPathForItemType:ItemTypeSigninPromo | 1132 [self.collectionViewModel indexPathForItemType:ItemTypeSigninPromo |
| 1139 sectionIdentifier:SectionIdentifierSignIn]; | 1133 sectionIdentifier:SectionIdentifierSignIn]; |
| 1140 DCHECK(signinPromoCellIndexPath.item != NSNotFound); | 1134 DCHECK(signinPromoCellIndexPath.item != NSNotFound); |
| 1141 SigninPromoItem* signinPromoItem = base::mac::ObjCCast<SigninPromoItem>( | 1135 SigninPromoItem* signinPromoItem = base::mac::ObjCCast<SigninPromoItem>( |
| 1142 [self.collectionViewModel itemAtIndexPath:signinPromoCellIndexPath]); | 1136 [self.collectionViewModel itemAtIndexPath:signinPromoCellIndexPath]); |
| 1143 if (signinPromoItem) { | 1137 if (signinPromoItem) { |
| 1144 signinPromoItem.configurator = configurator; | 1138 signinPromoItem.configurator = configurator; |
| 1145 [self reconfigureCellsForItems:@[ signinPromoItem ] | 1139 [self reconfigureCellsForItems:@[ signinPromoItem ]]; |
| 1146 inSectionWithIdentifier:SectionIdentifierSignIn]; | |
| 1147 if (newIdentity) | 1140 if (newIdentity) |
| 1148 [self.collectionViewLayout invalidateLayout]; | 1141 [self.collectionViewLayout invalidateLayout]; |
| 1149 } | 1142 } |
| 1150 } | 1143 } |
| 1151 | 1144 |
| 1152 @end | 1145 @end |
| OLD | NEW |