| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/handoff_collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/settings/handoff_collection_view_controller.h" |
| 6 | 6 |
| 7 #import "base/mac/foundation_util.h" | 7 #import "base/mac/foundation_util.h" |
| 8 #include "components/handoff/pref_names_ios.h" | 8 #include "components/handoff/pref_names_ios.h" |
| 9 #include "components/prefs/pref_member.h" | 9 #include "components/prefs/pref_member.h" |
| 10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 11 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 11 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
| 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" | 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
| 14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 15 #include "ios/chrome/grit/ios_strings.h" | 15 #include "ios/chrome/grit/ios_strings.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 | 17 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." |
| 20 #endif |
| 21 |
| 18 namespace { | 22 namespace { |
| 19 | 23 |
| 20 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 24 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 21 SectionIdentifierSwitch = kSectionIdentifierEnumZero, | 25 SectionIdentifierSwitch = kSectionIdentifierEnumZero, |
| 22 SectionIdentifierFooter, | 26 SectionIdentifierFooter, |
| 23 }; | 27 }; |
| 24 | 28 |
| 25 typedef NS_ENUM(NSInteger, ItemType) { | 29 typedef NS_ENUM(NSInteger, ItemType) { |
| 26 ItemTypeSwitch = kItemTypeEnumZero, | 30 ItemTypeSwitch = kItemTypeEnumZero, |
| 27 ItemTypeFooter, | 31 ItemTypeFooter, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 return self; | 58 return self; |
| 55 } | 59 } |
| 56 | 60 |
| 57 #pragma mark - CollectionViewController | 61 #pragma mark - CollectionViewController |
| 58 | 62 |
| 59 - (void)loadModel { | 63 - (void)loadModel { |
| 60 [super loadModel]; | 64 [super loadModel]; |
| 61 CollectionViewModel* model = self.collectionViewModel; | 65 CollectionViewModel* model = self.collectionViewModel; |
| 62 | 66 |
| 63 [model addSectionWithIdentifier:SectionIdentifierSwitch]; | 67 [model addSectionWithIdentifier:SectionIdentifierSwitch]; |
| 64 CollectionViewSwitchItem* switchItem = [[[CollectionViewSwitchItem alloc] | 68 CollectionViewSwitchItem* switchItem = |
| 65 initWithType:ItemTypeSwitch] autorelease]; | 69 [[CollectionViewSwitchItem alloc] initWithType:ItemTypeSwitch]; |
| 66 switchItem.text = | 70 switchItem.text = |
| 67 l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES); | 71 l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES); |
| 68 switchItem.on = _handoffEnabled.GetValue(); | 72 switchItem.on = _handoffEnabled.GetValue(); |
| 69 [model addItem:switchItem toSectionWithIdentifier:SectionIdentifierSwitch]; | 73 [model addItem:switchItem toSectionWithIdentifier:SectionIdentifierSwitch]; |
| 70 | 74 |
| 71 // The footer item must currently go into a separate section, to work around a | 75 // The footer item must currently go into a separate section, to work around a |
| 72 // drawing bug in MDC. | 76 // drawing bug in MDC. |
| 73 // TODO(crbug.com/650424) Use setFooter:forSectionWithIdentifier:. | 77 // TODO(crbug.com/650424) Use setFooter:forSectionWithIdentifier:. |
| 74 [model addSectionWithIdentifier:SectionIdentifierFooter]; | 78 [model addSectionWithIdentifier:SectionIdentifierFooter]; |
| 75 CollectionViewFooterItem* footer = [[[CollectionViewFooterItem alloc] | 79 CollectionViewFooterItem* footer = |
| 76 initWithType:ItemTypeFooter] autorelease]; | 80 [[CollectionViewFooterItem alloc] initWithType:ItemTypeFooter]; |
| 77 footer.text = l10n_util::GetNSString( | 81 footer.text = l10n_util::GetNSString( |
| 78 IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES_DETAILS); | 82 IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES_DETAILS); |
| 79 [model addItem:footer toSectionWithIdentifier:SectionIdentifierFooter]; | 83 [model addItem:footer toSectionWithIdentifier:SectionIdentifierFooter]; |
| 80 } | 84 } |
| 81 | 85 |
| 82 #pragma mark - UICollectionViewDataSource | 86 #pragma mark - UICollectionViewDataSource |
| 83 | 87 |
| 84 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 88 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 85 cellForItemAtIndexPath:(NSIndexPath*)indexPath { | 89 cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 86 UICollectionViewCell* cell = | 90 UICollectionViewCell* cell = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 155 } |
| 152 } | 156 } |
| 153 | 157 |
| 154 #pragma mark - Private | 158 #pragma mark - Private |
| 155 | 159 |
| 156 - (void)switchChanged:(UISwitch*)switchView { | 160 - (void)switchChanged:(UISwitch*)switchView { |
| 157 _handoffEnabled.SetValue(switchView.isOn); | 161 _handoffEnabled.SetValue(switchView.isOn); |
| 158 } | 162 } |
| 159 | 163 |
| 160 @end | 164 @end |
| OLD | NEW |