| OLD | NEW |
| 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_authentication.h" |
| 14 #import "remoting/client/ios/facade/remoting_service.h" |
| 13 | 15 |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "google_apis/google_api_keys.h" | 17 #include "google_apis/google_api_keys.h" |
| 16 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
| 17 | 19 |
| 18 // TODO(nicholss): This should be generated from a remoting/base class: | 20 // TODO(nicholss): This should be generated from a remoting/base class: |
| 19 | 21 |
| 20 static NSString* const kReusableIdentifierItem = | 22 static NSString* const kReusableIdentifierItem = |
| 21 @"remotingSettingsViewControllerItem"; | 23 @"remotingSettingsViewControllerItem"; |
| 22 static UIColor* kBackgroundColor = | 24 static UIColor* kBackgroundColor = |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 [self.collectionView registerClass:[MDCCollectionViewTextCell class] | 108 [self.collectionView registerClass:[MDCCollectionViewTextCell class] |
| 107 forCellWithReuseIdentifier:kReusableIdentifierItem]; | 109 forCellWithReuseIdentifier:kReusableIdentifierItem]; |
| 108 | 110 |
| 109 [self.collectionView registerClass:[MDCCollectionViewTextCell class] | 111 [self.collectionView registerClass:[MDCCollectionViewTextCell class] |
| 110 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader | 112 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| 111 withReuseIdentifier:UICollectionElementKindSectionHeader]; | 113 withReuseIdentifier:UICollectionElementKindSectionHeader]; |
| 112 | 114 |
| 113 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 115 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 114 | 116 |
| 115 _content = [NSMutableArray array]; | 117 _content = [NSMutableArray array]; |
| 116 [_content addObject:@[ @"Login" ]]; | 118 [_content addObject:@[ @"Login", @"Logout" ]]; |
| 117 } | 119 } |
| 118 | 120 |
| 119 #pragma mark - UICollectionViewDataSource | 121 #pragma mark - UICollectionViewDataSource |
| 120 | 122 |
| 121 - (NSInteger)numberOfSectionsInCollectionView: | 123 - (NSInteger)numberOfSectionsInCollectionView: |
| 122 (UICollectionView*)collectionView { | 124 (UICollectionView*)collectionView { |
| 123 return (NSInteger)[_content count]; | 125 return (NSInteger)[_content count]; |
| 124 } | 126 } |
| 125 | 127 |
| 126 - (NSInteger)collectionView:(UICollectionView*)collectionView | 128 - (NSInteger)collectionView:(UICollectionView*)collectionView |
| (...skipping 12 matching lines...) Expand all Loading... |
| 139 if (indexPath.section == 0 && indexPath.item == 0) { | 141 if (indexPath.section == 0 && indexPath.item == 0) { |
| 140 MDCRaisedButton* accessCodeButton = [[MDCRaisedButton alloc] init]; | 142 MDCRaisedButton* accessCodeButton = [[MDCRaisedButton alloc] init]; |
| 141 [accessCodeButton setTitle:@"Get Access Code" | 143 [accessCodeButton setTitle:@"Get Access Code" |
| 142 forState:UIControlStateNormal]; | 144 forState:UIControlStateNormal]; |
| 143 [accessCodeButton sizeToFit]; | 145 [accessCodeButton sizeToFit]; |
| 144 [accessCodeButton addTarget:self | 146 [accessCodeButton addTarget:self |
| 145 action:@selector(didTapGetAccessCode:) | 147 action:@selector(didTapGetAccessCode:) |
| 146 forControlEvents:UIControlEventTouchUpInside]; | 148 forControlEvents:UIControlEventTouchUpInside]; |
| 147 accessCodeButton.translatesAutoresizingMaskIntoConstraints = NO; | 149 accessCodeButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 148 cell.accessoryView = accessCodeButton; | 150 cell.accessoryView = accessCodeButton; |
| 149 } else { | 151 } else if (indexPath.section == 0 && indexPath.item == 1) { |
| 150 UISwitch* editingSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; | 152 MDCRaisedButton* logoutButton = [[MDCRaisedButton alloc] init]; |
| 151 cell.accessoryView = editingSwitch; | 153 [logoutButton setTitle:@"Logout" forState:UIControlStateNormal]; |
| 154 [logoutButton sizeToFit]; |
| 155 [logoutButton addTarget:self |
| 156 action:@selector(didTapLogout:) |
| 157 forControlEvents:UIControlEventTouchUpInside]; |
| 158 logoutButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 159 cell.accessoryView = logoutButton; |
| 152 } | 160 } |
| 161 |
| 153 return cell; | 162 return cell; |
| 154 } | 163 } |
| 155 | 164 |
| 156 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView | 165 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView |
| 157 viewForSupplementaryElementOfKind:(NSString*)kind | 166 viewForSupplementaryElementOfKind:(NSString*)kind |
| 158 atIndexPath:(NSIndexPath*)indexPath { | 167 atIndexPath:(NSIndexPath*)indexPath { |
| 159 MDCCollectionViewTextCell* supplementaryView = | 168 MDCCollectionViewTextCell* supplementaryView = |
| 160 [collectionView dequeueReusableSupplementaryViewOfKind:kind | 169 [collectionView dequeueReusableSupplementaryViewOfKind:kind |
| 161 withReuseIdentifier:kind | 170 withReuseIdentifier:kind |
| 162 forIndexPath:indexPath]; | 171 forIndexPath:indexPath]; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 185 [self dismissViewControllerAnimated:YES completion:nil]; | 194 [self dismissViewControllerAnimated:YES completion:nil]; |
| 186 } | 195 } |
| 187 | 196 |
| 188 - (void)didTapGetAccessCode:(id)sender { | 197 - (void)didTapGetAccessCode:(id)sender { |
| 189 NSString* authUri = | 198 NSString* authUri = |
| 190 [NSString stringWithCString:GetAuthorizationCodeUri().c_str() | 199 [NSString stringWithCString:GetAuthorizationCodeUri().c_str() |
| 191 encoding:[NSString defaultCStringEncoding]]; | 200 encoding:[NSString defaultCStringEncoding]]; |
| 192 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:authUri]]; | 201 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:authUri]]; |
| 193 } | 202 } |
| 194 | 203 |
| 204 - (void)didTapLogout:(id)sender { |
| 205 [[RemotingService SharedInstance].authentication logout]; |
| 206 } |
| 207 |
| 195 @end | 208 @end |
| OLD | NEW |