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/physical_web_collection_view_controller.
h" | 5 #import "ios/chrome/browser/ui/settings/physical_web_collection_view_controller.
h" |
6 | 6 |
7 #import <CoreLocation/CoreLocation.h> | 7 #import <CoreLocation/CoreLocation.h> |
8 | 8 |
9 #import "base/ios/weak_nsobject.h" | |
10 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
11 #import "base/mac/scoped_nsobject.h" | |
12 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
13 #include "components/google/core/browser/google_util.h" | 11 #include "components/google/core/browser/google_util.h" |
14 #include "components/physical_web/data_source/physical_web_data_source.h" | 12 #include "components/physical_web/data_source/physical_web_data_source.h" |
15 #include "components/prefs/pref_member.h" | 13 #include "components/prefs/pref_member.h" |
16 #include "ios/chrome/browser/application_context.h" | 14 #include "ios/chrome/browser/application_context.h" |
17 #include "ios/chrome/browser/chrome_url_constants.h" | 15 #include "ios/chrome/browser/chrome_url_constants.h" |
18 #include "ios/chrome/browser/physical_web/physical_web_constants.h" | 16 #include "ios/chrome/browser/physical_web/physical_web_constants.h" |
19 #include "ios/chrome/browser/pref_names.h" | 17 #include "ios/chrome/browser/pref_names.h" |
20 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 18 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" | 21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
25 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 23 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
26 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 24 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
27 #import "ios/chrome/browser/ui/settings/settings_utils.h" | 25 #import "ios/chrome/browser/ui/settings/settings_utils.h" |
28 #import "ios/chrome/common/string_util.h" | 26 #import "ios/chrome/common/string_util.h" |
29 #include "ios/chrome/grit/ios_chromium_strings.h" | 27 #include "ios/chrome/grit/ios_chromium_strings.h" |
30 #include "ios/chrome/grit/ios_strings.h" | 28 #include "ios/chrome/grit/ios_strings.h" |
31 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 29 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
32 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
33 #include "url/gurl.h" | 31 #include "url/gurl.h" |
34 | 32 |
| 33 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 34 #error "This file requires ARC support." |
| 35 #endif |
| 36 |
35 namespace { | 37 namespace { |
36 | 38 |
37 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 39 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
38 SectionIdentifierPhysicalWeb = kSectionIdentifierEnumZero, | 40 SectionIdentifierPhysicalWeb = kSectionIdentifierEnumZero, |
39 SectionIdentifierLearnMore, | 41 SectionIdentifierLearnMore, |
40 }; | 42 }; |
41 | 43 |
42 typedef NS_ENUM(NSInteger, ItemType) { | 44 typedef NS_ENUM(NSInteger, ItemType) { |
43 ItemTypePhysicalWebSwitch = kItemTypeEnumZero, | 45 ItemTypePhysicalWebSwitch = kItemTypeEnumZero, |
44 ItemTypeLearnMore, | 46 ItemTypeLearnMore, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 158 |
157 - (void)loadModel { | 159 - (void)loadModel { |
158 [super loadModel]; | 160 [super loadModel]; |
159 CollectionViewModel* model = self.collectionViewModel; | 161 CollectionViewModel* model = self.collectionViewModel; |
160 | 162 |
161 [model addSectionWithIdentifier:SectionIdentifierPhysicalWeb]; | 163 [model addSectionWithIdentifier:SectionIdentifierPhysicalWeb]; |
162 | 164 |
163 NSString* switchLabelText = | 165 NSString* switchLabelText = |
164 l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB); | 166 l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB); |
165 | 167 |
166 CollectionViewSwitchItem* switchItem = [[[CollectionViewSwitchItem alloc] | 168 CollectionViewSwitchItem* switchItem = |
167 initWithType:ItemTypePhysicalWebSwitch] autorelease]; | 169 [[CollectionViewSwitchItem alloc] initWithType:ItemTypePhysicalWebSwitch]; |
168 switchItem.text = switchLabelText; | 170 switchItem.text = switchLabelText; |
169 switchItem.on = [PhysicalWebCollectionViewController | 171 switchItem.on = [PhysicalWebCollectionViewController |
170 shouldEnableForPreferenceState:_physicalWebEnabled.GetValue()]; | 172 shouldEnableForPreferenceState:_physicalWebEnabled.GetValue()]; |
171 [model addItem:switchItem | 173 [model addItem:switchItem |
172 toSectionWithIdentifier:SectionIdentifierPhysicalWeb]; | 174 toSectionWithIdentifier:SectionIdentifierPhysicalWeb]; |
173 | 175 |
174 [model addSectionWithIdentifier:SectionIdentifierLearnMore]; | 176 [model addSectionWithIdentifier:SectionIdentifierLearnMore]; |
175 | 177 |
176 NSString* learnMoreText = | 178 NSString* learnMoreText = |
177 l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB_DETAILS); | 179 l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB_DETAILS); |
178 | 180 |
179 CollectionViewFooterItem* learnMore = [[[CollectionViewFooterItem alloc] | 181 CollectionViewFooterItem* learnMore = |
180 initWithType:ItemTypeLearnMore] autorelease]; | 182 [[CollectionViewFooterItem alloc] initWithType:ItemTypeLearnMore]; |
181 learnMore.text = learnMoreText; | 183 learnMore.text = learnMoreText; |
182 learnMore.linkURL = GURL(kPhysicalWebLearnMoreURL); | 184 learnMore.linkURL = GURL(kPhysicalWebLearnMoreURL); |
183 learnMore.linkDelegate = self; | 185 learnMore.linkDelegate = self; |
184 learnMore.accessibilityTraits = UIAccessibilityTraitButton; | 186 learnMore.accessibilityTraits = UIAccessibilityTraitButton; |
185 [model addItem:learnMore toSectionWithIdentifier:SectionIdentifierLearnMore]; | 187 [model addItem:learnMore toSectionWithIdentifier:SectionIdentifierLearnMore]; |
186 } | 188 } |
187 | 189 |
188 #pragma mark - MDCCollectionViewStylingDelegate | 190 #pragma mark - MDCCollectionViewStylingDelegate |
189 | 191 |
190 - (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView | 192 - (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 235 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
234 switch (type) { | 236 switch (type) { |
235 case ItemTypePhysicalWebSwitch: | 237 case ItemTypePhysicalWebSwitch: |
236 return YES; | 238 return YES; |
237 default: | 239 default: |
238 return NO; | 240 return NO; |
239 } | 241 } |
240 } | 242 } |
241 | 243 |
242 @end | 244 @end |
OLD | NEW |