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

Side by Side Diff: remoting/client/ios/app/remoting_settings_view_controller.mm

Issue 2854273002: [CRD iOS] Implementing save to keychain and user defaults for login info. Refactor remoting service. (Closed)
Patch Set: Cleanup on self review. Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #if !defined(__has_feature) || !__has_feature(objc_arc) 5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support." 6 #error "This file requires ARC support."
7 #endif 7 #endif
8 8
9 #import "remoting/client/ios/app/remoting_settings_view_controller.h" 9 #import "remoting/client/ios/app/remoting_settings_view_controller.h"
10 10
11 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater ialAppBar.h" 11 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater ialAppBar.h"
12 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 12 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
13 #import "remoting/client/ios/facade/remoting_service.h"
13 14
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "google_apis/google_api_keys.h" 16 #include "google_apis/google_api_keys.h"
16 #include "net/base/escape.h" 17 #include "net/base/escape.h"
17 18
18 // TODO(nicholss): This should be generated from a remoting/base class: 19 // TODO(nicholss): This should be generated from a remoting/base class:
19 20
20 static NSString* const kReusableIdentifierItem = 21 static NSString* const kReusableIdentifierItem =
21 @"remotingSettingsViewControllerItem"; 22 @"remotingSettingsViewControllerItem";
22 static UIColor* kBackgroundColor = 23 static UIColor* kBackgroundColor =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 [self.collectionView registerClass:[MDCCollectionViewTextCell class] 107 [self.collectionView registerClass:[MDCCollectionViewTextCell class]
107 forCellWithReuseIdentifier:kReusableIdentifierItem]; 108 forCellWithReuseIdentifier:kReusableIdentifierItem];
108 109
109 [self.collectionView registerClass:[MDCCollectionViewTextCell class] 110 [self.collectionView registerClass:[MDCCollectionViewTextCell class]
110 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader 111 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
111 withReuseIdentifier:UICollectionElementKindSectionHeader]; 112 withReuseIdentifier:UICollectionElementKindSectionHeader];
112 113
113 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 114 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
114 115
115 _content = [NSMutableArray array]; 116 _content = [NSMutableArray array];
116 [_content addObject:@[ @"Login" ]]; 117 [_content addObject:@[ @"Login", @"Logout" ]];
117 } 118 }
118 119
119 #pragma mark - UICollectionViewDataSource 120 #pragma mark - UICollectionViewDataSource
120 121
121 - (NSInteger)numberOfSectionsInCollectionView: 122 - (NSInteger)numberOfSectionsInCollectionView:
122 (UICollectionView*)collectionView { 123 (UICollectionView*)collectionView {
123 return (NSInteger)[_content count]; 124 return (NSInteger)[_content count];
124 } 125 }
125 126
126 - (NSInteger)collectionView:(UICollectionView*)collectionView 127 - (NSInteger)collectionView:(UICollectionView*)collectionView
(...skipping 12 matching lines...) Expand all
139 if (indexPath.section == 0 && indexPath.item == 0) { 140 if (indexPath.section == 0 && indexPath.item == 0) {
140 MDCRaisedButton* accessCodeButton = [[MDCRaisedButton alloc] init]; 141 MDCRaisedButton* accessCodeButton = [[MDCRaisedButton alloc] init];
141 [accessCodeButton setTitle:@"Get Access Code" 142 [accessCodeButton setTitle:@"Get Access Code"
142 forState:UIControlStateNormal]; 143 forState:UIControlStateNormal];
143 [accessCodeButton sizeToFit]; 144 [accessCodeButton sizeToFit];
144 [accessCodeButton addTarget:self 145 [accessCodeButton addTarget:self
145 action:@selector(didTapGetAccessCode:) 146 action:@selector(didTapGetAccessCode:)
146 forControlEvents:UIControlEventTouchUpInside]; 147 forControlEvents:UIControlEventTouchUpInside];
147 accessCodeButton.translatesAutoresizingMaskIntoConstraints = NO; 148 accessCodeButton.translatesAutoresizingMaskIntoConstraints = NO;
148 cell.accessoryView = accessCodeButton; 149 cell.accessoryView = accessCodeButton;
149 } else { 150 } else if (indexPath.section == 0 && indexPath.item == 1) {
150 UISwitch* editingSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; 151 MDCRaisedButton* logoutButton = [[MDCRaisedButton alloc] init];
151 cell.accessoryView = editingSwitch; 152 [logoutButton setTitle:@"Logout" forState:UIControlStateNormal];
153 [logoutButton sizeToFit];
154 [logoutButton addTarget:self
155 action:@selector(didTapLogout:)
156 forControlEvents:UIControlEventTouchUpInside];
157 logoutButton.translatesAutoresizingMaskIntoConstraints = NO;
158 cell.accessoryView = logoutButton;
152 } 159 }
160
153 return cell; 161 return cell;
154 } 162 }
155 163
156 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView 164 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView
157 viewForSupplementaryElementOfKind:(NSString*)kind 165 viewForSupplementaryElementOfKind:(NSString*)kind
158 atIndexPath:(NSIndexPath*)indexPath { 166 atIndexPath:(NSIndexPath*)indexPath {
159 MDCCollectionViewTextCell* supplementaryView = 167 MDCCollectionViewTextCell* supplementaryView =
160 [collectionView dequeueReusableSupplementaryViewOfKind:kind 168 [collectionView dequeueReusableSupplementaryViewOfKind:kind
161 withReuseIdentifier:kind 169 withReuseIdentifier:kind
162 forIndexPath:indexPath]; 170 forIndexPath:indexPath];
(...skipping 22 matching lines...) Expand all
185 [self dismissViewControllerAnimated:YES completion:nil]; 193 [self dismissViewControllerAnimated:YES completion:nil];
186 } 194 }
187 195
188 - (void)didTapGetAccessCode:(id)sender { 196 - (void)didTapGetAccessCode:(id)sender {
189 NSString* authUri = 197 NSString* authUri =
190 [NSString stringWithCString:GetAuthorizationCodeUri().c_str() 198 [NSString stringWithCString:GetAuthorizationCodeUri().c_str()
191 encoding:[NSString defaultCStringEncoding]]; 199 encoding:[NSString defaultCStringEncoding]];
192 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:authUri]]; 200 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:authUri]];
193 } 201 }
194 202
203 - (void)didTapLogout:(id)sender {
204 [[RemotingService SharedInstance] logout];
205 }
206
195 @end 207 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698