Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: ios/chrome/browser/ui/settings/contextual_search_collection_view_controller.mm

Issue 2814813003: [ObjC ARC] Converts ios/chrome/browser/ui/settings:settings_arc_transition to ARC. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/contextual_search_collection_view_contro ller.h" 5 #import "ios/chrome/browser/ui/settings/contextual_search_collection_view_contro ller.h"
6 6
7 #import "base/mac/foundation_util.h" 7 #import "base/mac/foundation_util.h"
8 #import "base/mac/scoped_nsobject.h"
9 #include "components/google/core/browser/google_util.h" 8 #include "components/google/core/browser/google_util.h"
10 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
11 #include "ios/chrome/browser/application_context.h" 10 #include "ios/chrome/browser/application_context.h"
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
13 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 12 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h"
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h" 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h"
16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
17 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med iator.h" 16 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med iator.h"
18 #import "ios/chrome/browser/ui/settings/settings_utils.h" 17 #import "ios/chrome/browser/ui/settings/settings_utils.h"
19 #include "ios/chrome/grit/ios_strings.h" 18 #include "ios/chrome/grit/ios_strings.h"
20 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
21 #include "url/gurl.h" 20 #include "url/gurl.h"
22 21
22 #if !defined(__has_feature) || !__has_feature(objc_arc)
23 #error "This file requires ARC support."
24 #endif
25
23 namespace { 26 namespace {
24 27
25 typedef NS_ENUM(NSInteger, SectionIdentifier) { 28 typedef NS_ENUM(NSInteger, SectionIdentifier) {
26 SectionIdentifierTouchToSearch = kSectionIdentifierEnumZero, 29 SectionIdentifierTouchToSearch = kSectionIdentifierEnumZero,
27 SectionIdentifierFooter, 30 SectionIdentifierFooter,
28 }; 31 };
29 32
30 typedef NS_ENUM(NSUInteger, ItemType) { 33 typedef NS_ENUM(NSUInteger, ItemType) {
31 ItemTypeTouchToSearchSwitch = kItemTypeEnumZero, 34 ItemTypeTouchToSearchSwitch = kItemTypeEnumZero,
32 ItemTypeFooter, 35 ItemTypeFooter,
33 }; 36 };
34 37
35 } // namespace 38 } // namespace
36 39
37 @interface ContextualSearchCollectionViewController () { 40 @interface ContextualSearchCollectionViewController () {
38 // Permissions interface for Touch-to-Search. 41 // Permissions interface for Touch-to-Search.
39 base::scoped_nsobject<TouchToSearchPermissionsMediator> 42 TouchToSearchPermissionsMediator* _touchToSearchPermissions;
40 _touchToSearchPermissions;
41 } 43 }
42 44
43 // Returns the switch item to use for the touch to search setting. 45 // Returns the switch item to use for the touch to search setting.
44 - (CollectionViewSwitchItem*)touchToSearchSwitchItem; 46 - (CollectionViewSwitchItem*)touchToSearchSwitchItem;
45 47
46 // Returns the item to use for the footer. 48 // Returns the item to use for the footer.
47 - (CollectionViewFooterItem*)footerItem; 49 - (CollectionViewFooterItem*)footerItem;
48 50
49 // Called when the touch to search switch is toggled. 51 // Called when the touch to search switch is toggled.
50 - (void)switchToggled:(id)sender; 52 - (void)switchToggled:(id)sender;
51 53
52 @end 54 @end
53 55
54 @implementation ContextualSearchCollectionViewController 56 @implementation ContextualSearchCollectionViewController
55 57
56 #pragma mark - Initialization 58 #pragma mark - Initialization
57 59
58 - (instancetype)initWithPermissions: 60 - (instancetype)initWithPermissions:
59 (TouchToSearchPermissionsMediator*)touchToSearchPermissions { 61 (TouchToSearchPermissionsMediator*)touchToSearchPermissions {
60 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; 62 self = [super initWithStyle:CollectionViewControllerStyleAppBar];
61 if (self) { 63 if (self) {
62 self.title = l10n_util::GetNSString(IDS_IOS_CONTEXTUAL_SEARCH_TITLE); 64 self.title = l10n_util::GetNSString(IDS_IOS_CONTEXTUAL_SEARCH_TITLE);
63 _touchToSearchPermissions.reset([touchToSearchPermissions retain]); 65 _touchToSearchPermissions = touchToSearchPermissions;
64 self.collectionViewAccessibilityIdentifier = @"Contextual Search"; 66 self.collectionViewAccessibilityIdentifier = @"Contextual Search";
65 [self loadModel]; 67 [self loadModel];
66 } 68 }
67 return self; 69 return self;
68 } 70 }
69 71
70 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { 72 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
71 return [self 73 return [self initWithPermissions:[[TouchToSearchPermissionsMediator alloc]
72 initWithPermissions:[[[TouchToSearchPermissionsMediator alloc] 74 initWithBrowserState:browserState]];
73 initWithBrowserState:browserState] autorelease]];
74 } 75 }
75 76
76 #pragma mark - SettingsRootCollectionViewController 77 #pragma mark - SettingsRootCollectionViewController
77 78
78 - (void)loadModel { 79 - (void)loadModel {
79 [super loadModel]; 80 [super loadModel];
80 CollectionViewModel* model = self.collectionViewModel; 81 CollectionViewModel* model = self.collectionViewModel;
81 82
82 [model addSectionWithIdentifier:SectionIdentifierTouchToSearch]; 83 [model addSectionWithIdentifier:SectionIdentifierTouchToSearch];
83 [model addItem:[self touchToSearchSwitchItem] 84 [model addItem:[self touchToSearchSwitchItem]
84 toSectionWithIdentifier:SectionIdentifierTouchToSearch]; 85 toSectionWithIdentifier:SectionIdentifierTouchToSearch];
85 86
86 [model addSectionWithIdentifier:SectionIdentifierFooter]; 87 [model addSectionWithIdentifier:SectionIdentifierFooter];
87 [model addItem:[self footerItem] 88 [model addItem:[self footerItem]
88 toSectionWithIdentifier:SectionIdentifierFooter]; 89 toSectionWithIdentifier:SectionIdentifierFooter];
89 } 90 }
90 91
91 - (CollectionViewSwitchItem*)touchToSearchSwitchItem { 92 - (CollectionViewSwitchItem*)touchToSearchSwitchItem {
92 CollectionViewSwitchItem* item = [[[CollectionViewSwitchItem alloc] 93 CollectionViewSwitchItem* item = [[CollectionViewSwitchItem alloc]
93 initWithType:ItemTypeTouchToSearchSwitch] autorelease]; 94 initWithType:ItemTypeTouchToSearchSwitch];
94 item.text = l10n_util::GetNSString(IDS_IOS_CONTEXTUAL_SEARCH_TITLE); 95 item.text = l10n_util::GetNSString(IDS_IOS_CONTEXTUAL_SEARCH_TITLE);
95 item.on = 96 item.on =
96 ([_touchToSearchPermissions preferenceState] != TouchToSearch::DISABLED); 97 ([_touchToSearchPermissions preferenceState] != TouchToSearch::DISABLED);
97 return item; 98 return item;
98 } 99 }
99 100
100 - (CollectionViewFooterItem*)footerItem { 101 - (CollectionViewFooterItem*)footerItem {
101 NSString* footerText = 102 NSString* footerText =
102 [NSString stringWithFormat:@"%@ BEGIN_LINK%@END_LINK", 103 [NSString stringWithFormat:@"%@ BEGIN_LINK%@END_LINK",
103 l10n_util::GetNSString( 104 l10n_util::GetNSString(
104 IDS_IOS_CONTEXTUAL_SEARCH_DESCRIPTION), 105 IDS_IOS_CONTEXTUAL_SEARCH_DESCRIPTION),
105 l10n_util::GetNSString(IDS_LEARN_MORE)]; 106 l10n_util::GetNSString(IDS_LEARN_MORE)];
106 GURL learnMoreURL = google_util::AppendGoogleLocaleParam( 107 GURL learnMoreURL = google_util::AppendGoogleLocaleParam(
107 GURL(l10n_util::GetStringUTF8(IDS_IOS_CONTEXTUAL_SEARCH_LEARN_MORE_URL)), 108 GURL(l10n_util::GetStringUTF8(IDS_IOS_CONTEXTUAL_SEARCH_LEARN_MORE_URL)),
108 GetApplicationContext()->GetApplicationLocale()); 109 GetApplicationContext()->GetApplicationLocale());
109 110
110 CollectionViewFooterItem* item = [[[CollectionViewFooterItem alloc] 111 CollectionViewFooterItem* item =
111 initWithType:ItemTypeFooter] autorelease]; 112 [[CollectionViewFooterItem alloc] initWithType:ItemTypeFooter];
112 item.text = footerText; 113 item.text = footerText;
113 item.linkURL = learnMoreURL; 114 item.linkURL = learnMoreURL;
114 item.linkDelegate = self; 115 item.linkDelegate = self;
115 return item; 116 return item;
116 } 117 }
117 118
118 - (void)switchToggled:(id)sender { 119 - (void)switchToggled:(id)sender {
119 NSIndexPath* switchPath = [self.collectionViewModel 120 NSIndexPath* switchPath = [self.collectionViewModel
120 indexPathForItemType:ItemTypeTouchToSearchSwitch 121 indexPathForItemType:ItemTypeTouchToSearchSwitch
121 sectionIdentifier:SectionIdentifierTouchToSearch]; 122 sectionIdentifier:SectionIdentifierTouchToSearch];
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 switch (type) { 208 switch (type) {
208 case ItemTypeFooter: 209 case ItemTypeFooter:
209 case ItemTypeTouchToSearchSwitch: 210 case ItemTypeTouchToSearchSwitch:
210 return YES; 211 return YES;
211 default: 212 default:
212 return NO; 213 return NO;
213 } 214 }
214 } 215 }
215 216
216 @end 217 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698