| 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_view_controller.h" | 9 #import "remoting/client/ios/app/remoting_view_controller.h" |
| 10 | 10 |
| 11 #import "base/mac/bind_objc_block.h" | 11 #import "base/mac/bind_objc_block.h" |
| 12 #import "ios/third_party/material_components_ios/src/components/AnimationTiming/
src/MaterialAnimationTiming.h" | 12 #import "ios/third_party/material_components_ios/src/components/AnimationTiming/
src/MaterialAnimationTiming.h" |
| 13 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater
ialAppBar.h" | 13 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater
ialAppBar.h" |
| 14 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate
rialDialogs.h" | 14 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate
rialDialogs.h" |
| 15 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" | 15 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" |
| 16 #import "remoting/client/ios/app/client_connection_view_controller.h" | 16 #import "remoting/client/ios/app/client_connection_view_controller.h" |
| 17 #import "remoting/client/ios/app/host_collection_view_controller.h" | 17 #import "remoting/client/ios/app/host_collection_view_controller.h" |
| 18 #import "remoting/client/ios/app/host_view_controller.h" | 18 #import "remoting/client/ios/app/host_view_controller.h" |
| 19 #import "remoting/client/ios/app/remoting_settings_view_controller.h" | 19 #import "remoting/client/ios/app/remoting_settings_view_controller.h" |
| 20 #import "remoting/client/ios/domain/client_session_details.h" | 20 #import "remoting/client/ios/domain/client_session_details.h" |
| 21 #import "remoting/client/ios/facade/remoting_authentication.h" |
| 21 #import "remoting/client/ios/facade/remoting_service.h" | 22 #import "remoting/client/ios/facade/remoting_service.h" |
| 22 #import "remoting/client/ios/session/remoting_client.h" | 23 #import "remoting/client/ios/session/remoting_client.h" |
| 23 | 24 |
| 24 #include "base/strings/sys_string_conversions.h" | 25 #include "base/strings/sys_string_conversions.h" |
| 25 #include "remoting/base/oauth_token_getter.h" | 26 #include "remoting/base/oauth_token_getter.h" |
| 26 #include "remoting/client/connect_to_host_info.h" | 27 #include "remoting/client/connect_to_host_info.h" |
| 27 | 28 |
| 28 static CGFloat kHostInset = 5.f; | 29 static CGFloat kHostInset = 5.f; |
| 29 | 30 |
| 30 @interface RemotingViewController ()<HostCollectionViewControllerDelegate, | 31 @interface RemotingViewController ()<HostCollectionViewControllerDelegate, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 52 [[UICollectionViewFlowLayout alloc] init]; | 53 [[UICollectionViewFlowLayout alloc] init]; |
| 53 layout.minimumInteritemSpacing = 0; | 54 layout.minimumInteritemSpacing = 0; |
| 54 CGFloat sectionInset = kHostInset * 2.f; | 55 CGFloat sectionInset = kHostInset * 2.f; |
| 55 [layout setSectionInset:UIEdgeInsetsMake(sectionInset, sectionInset, | 56 [layout setSectionInset:UIEdgeInsetsMake(sectionInset, sectionInset, |
| 56 sectionInset, sectionInset)]; | 57 sectionInset, sectionInset)]; |
| 57 HostCollectionViewController* collectionVC = [ | 58 HostCollectionViewController* collectionVC = [ |
| 58 [HostCollectionViewController alloc] initWithCollectionViewLayout:layout]; | 59 [HostCollectionViewController alloc] initWithCollectionViewLayout:layout]; |
| 59 self = [super initWithContentViewController:collectionVC]; | 60 self = [super initWithContentViewController:collectionVC]; |
| 60 if (self) { | 61 if (self) { |
| 61 _remotingService = [RemotingService SharedInstance]; | 62 _remotingService = [RemotingService SharedInstance]; |
| 62 [_remotingService setAuthenticationDelegate:self]; | |
| 63 | 63 |
| 64 _collectionViewController = collectionVC; | 64 _collectionViewController = collectionVC; |
| 65 _collectionViewController.flexHeaderContainerViewController = self; | 65 _collectionViewController.flexHeaderContainerViewController = self; |
| 66 _collectionViewController.delegate = self; | 66 _collectionViewController.delegate = self; |
| 67 | 67 |
| 68 _appBar = [[MDCAppBar alloc] init]; | 68 _appBar = [[MDCAppBar alloc] init]; |
| 69 [self addChildViewController:_appBar.headerViewController]; | 69 [self addChildViewController:_appBar.headerViewController]; |
| 70 | 70 |
| 71 _appBar.headerViewController.headerView.backgroundColor = | 71 _appBar.headerViewController.headerView.backgroundColor = |
| 72 [UIColor clearColor]; | 72 [UIColor clearColor]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 93 object:nil]; | 93 object:nil]; |
| 94 } | 94 } |
| 95 return self; | 95 return self; |
| 96 } | 96 } |
| 97 | 97 |
| 98 #pragma mark - UIViewController | 98 #pragma mark - UIViewController |
| 99 | 99 |
| 100 - (void)viewDidLoad { | 100 - (void)viewDidLoad { |
| 101 [super viewDidLoad]; | 101 [super viewDidLoad]; |
| 102 [_appBar addSubviewsToParent]; | 102 [_appBar addSubviewsToParent]; |
| 103 |
| 104 [[NSNotificationCenter defaultCenter] |
| 105 addObserver:self |
| 106 selector:@selector(hostsDidUpdateNotification:) |
| 107 name:kHostsDidUpdate |
| 108 object:nil]; |
| 109 [[NSNotificationCenter defaultCenter] |
| 110 addObserver:self |
| 111 selector:@selector(userDidUpdateNotification:) |
| 112 name:kUserDidUpdate |
| 113 object:nil]; |
| 114 } |
| 115 |
| 116 - (void)viewWillAppear:(BOOL)animated { |
| 117 [super viewWillAppear:animated]; |
| 118 |
| 119 [self nowAuthenticated:_remotingService.authentication.user.isAuthenticated]; |
| 103 [self presentStatus]; | 120 [self presentStatus]; |
| 104 } | 121 } |
| 105 | 122 |
| 106 - (void)viewDidAppear:(BOOL)animated { | 123 - (void)viewDidAppear:(BOOL)animated { |
| 124 [super viewDidAppear:animated]; |
| 107 if (!_isAuthenticated) { | 125 if (!_isAuthenticated) { |
| 108 // TODO(nicholss): This is used as a demo of the app functionality for the | 126 // TODO(nicholss): This is used as a demo of the app functionality for the |
| 109 // moment but the real app will force the login flow if unauthenticated. | 127 // moment but the real app will force the login flow if unauthenticated. |
| 110 [self didSelectSettings]; | 128 [self didSelectSettings]; |
| 111 // [self didSelectRefresh]; | 129 // [self didSelectRefresh]; |
| 112 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 130 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
| 113 message.text = @"Please login."; | 131 message.text = @"Please login."; |
| 114 [MDCSnackbarManager showMessage:message]; | 132 [MDCSnackbarManager showMessage:message]; |
| 133 } else { |
| 134 [_remotingService requestHostListFetch]; |
| 115 } | 135 } |
| 116 } | 136 } |
| 117 | 137 |
| 118 - (void)viewDidLayoutSubviews { | 138 - (void)viewDidLayoutSubviews { |
| 119 [super viewDidLayoutSubviews]; | 139 [super viewDidLayoutSubviews]; |
| 120 | 140 |
| 121 // Adjust the collection view's position and size so that it doesn't get | 141 // Adjust the collection view's position and size so that it doesn't get |
| 122 // overlayed by the navigation bar. | 142 // overlayed by the navigation bar. |
| 123 CGFloat collectionOffsetY = | 143 CGFloat collectionOffsetY = |
| 124 _appBar.headerViewController.headerView.frame.size.height; | 144 _appBar.headerViewController.headerView.frame.size.height; |
| 125 CGFloat collectionHeight = self.view.bounds.size.height - collectionOffsetY; | 145 CGFloat collectionHeight = self.view.bounds.size.height - collectionOffsetY; |
| 126 CGRect oldFrame = _collectionViewController.collectionView.frame; | 146 CGRect oldFrame = _collectionViewController.collectionView.frame; |
| 127 _collectionViewController.collectionView.frame = | 147 _collectionViewController.collectionView.frame = |
| 128 CGRectMake(oldFrame.origin.x, collectionOffsetY, oldFrame.size.width, | 148 CGRectMake(oldFrame.origin.x, collectionOffsetY, oldFrame.size.width, |
| 129 collectionHeight); | 149 collectionHeight); |
| 130 } | 150 } |
| 131 | 151 |
| 152 #pragma mark - Remoting Service Notifications |
| 153 |
| 154 - (void)hostsDidUpdateNotification:(NSNotification*)notification { |
| 155 [_collectionViewController.collectionView reloadData]; |
| 156 } |
| 157 |
| 158 - (void)userDidUpdateNotification:(NSNotification*)notification { |
| 159 [self nowAuthenticated:_remotingService.authentication.user.isAuthenticated]; |
| 160 } |
| 161 |
| 132 #pragma mark - RemotingAuthenticationDelegate | 162 #pragma mark - RemotingAuthenticationDelegate |
| 133 | 163 |
| 134 - (void)nowAuthenticated:(BOOL)authenticated { | 164 - (void)nowAuthenticated:(BOOL)authenticated { |
| 135 if (authenticated) { | 165 if (authenticated) { |
| 136 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 166 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
| 137 message.text = @"Logged In!"; | 167 message.text = @"Logged In!"; |
| 138 [MDCSnackbarManager showMessage:message]; | 168 [MDCSnackbarManager showMessage:message]; |
| 139 [_remotingService setHostListDelegate:self]; | |
| 140 } else { | 169 } else { |
| 141 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 170 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
| 142 message.text = @"Not logged in."; | 171 message.text = @"Not logged in."; |
| 143 [MDCSnackbarManager showMessage:message]; | 172 [MDCSnackbarManager showMessage:message]; |
| 144 [_remotingService setHostListDelegate:nil]; | |
| 145 } | 173 } |
| 146 _isAuthenticated = authenticated; | 174 _isAuthenticated = authenticated; |
| 147 [_collectionViewController.collectionView reloadData]; | 175 [_collectionViewController.collectionView reloadData]; |
| 148 } | 176 } |
| 149 | 177 |
| 150 #pragma mark - RemotingHostListDelegate | 178 #pragma mark - RemotingHostListDelegate |
| 151 | 179 |
| 152 // TODO(nicholss): these need to be a stats change like "none, loading, | 180 // TODO(nicholss): these need to be a stats change like "none, loading, |
| 153 // updated"... | 181 // updated"... |
| 154 - (void)hostListUpdated { | 182 - (void)hostListUpdated { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 169 } | 197 } |
| 170 return nil; | 198 return nil; |
| 171 } | 199 } |
| 172 | 200 |
| 173 #pragma mark - HostCollectionViewControllerDelegate | 201 #pragma mark - HostCollectionViewControllerDelegate |
| 174 | 202 |
| 175 - (void)didSelectCell:(HostCollectionViewCell*)cell | 203 - (void)didSelectCell:(HostCollectionViewCell*)cell |
| 176 completion:(void (^)())completionBlock { | 204 completion:(void (^)())completionBlock { |
| 177 _client = [[RemotingClient alloc] init]; | 205 _client = [[RemotingClient alloc] init]; |
| 178 | 206 |
| 179 [_remotingService | 207 [_remotingService.authentication |
| 180 callbackWithAccessToken:base::BindBlockArc(^( | 208 callbackWithAccessToken:base::BindBlockArc(^( |
| 181 remoting::OAuthTokenGetter::Status status, | 209 remoting::OAuthTokenGetter::Status status, |
| 182 const std::string& user_email, | 210 const std::string& user_email, |
| 183 const std::string& access_token) { | 211 const std::string& access_token) { |
| 184 // TODO(nicholss): Check status. | 212 // TODO(nicholss): Check status. |
| 185 HostInfo* hostInfo = cell.hostInfo; | 213 HostInfo* hostInfo = cell.hostInfo; |
| 186 [_client connectToHost:hostInfo | 214 [_client connectToHost:hostInfo |
| 187 username:base::SysUTF8ToNSString(user_email) | 215 username:base::SysUTF8ToNSString(user_email) |
| 188 accessToken:base::SysUTF8ToNSString(access_token)]; | 216 accessToken:base::SysUTF8ToNSString(access_token)]; |
| 189 })]; | 217 })]; |
| 190 | 218 |
| 191 ClientConnectionViewController* clientConnectionViewController = | 219 ClientConnectionViewController* clientConnectionViewController = |
| 192 [[ClientConnectionViewController alloc] init]; | 220 [[ClientConnectionViewController alloc] init]; |
| 193 clientConnectionViewController.delegate = self; | 221 clientConnectionViewController.delegate = self; |
| 194 [self presentViewController:clientConnectionViewController | 222 [self presentViewController:clientConnectionViewController |
| 195 animated:YES | 223 animated:YES |
| 196 completion:nil]; | 224 completion:nil]; |
| 197 completionBlock(); | 225 completionBlock(); |
| 198 } | 226 } |
| 199 | 227 |
| 200 - (NSInteger)getHostCount { | 228 - (NSInteger)getHostCount { |
| 201 NSArray<HostInfo*>* hosts = [_remotingService getHosts]; | 229 return _remotingService.hosts.count; |
| 202 return [hosts count]; | |
| 203 } | 230 } |
| 204 | 231 |
| 205 - (HostInfo*)getHostAtIndexPath:(NSIndexPath*)path { | 232 - (HostInfo*)getHostAtIndexPath:(NSIndexPath*)path { |
| 206 NSArray<HostInfo*>* hosts = [_remotingService getHosts]; | 233 return _remotingService.hosts[path.row]; |
| 207 return hosts[path.row]; | |
| 208 } | 234 } |
| 209 | 235 |
| 210 #pragma mark - UIViewControllerTransitioningDelegate | 236 #pragma mark - UIViewControllerTransitioningDelegate |
| 211 | 237 |
| 212 - (nullable id<UIViewControllerAnimatedTransitioning>) | 238 - (nullable id<UIViewControllerAnimatedTransitioning>) |
| 213 animationControllerForPresentedController:(UIViewController*)presented | 239 animationControllerForPresentedController:(UIViewController*)presented |
| 214 presentingController:(UIViewController*)presenting | 240 presentingController:(UIViewController*)presenting |
| 215 sourceController:(UIViewController*)source { | 241 sourceController:(UIViewController*)source { |
| 216 // TODO(nicholss): Not implemented yet. | 242 // TODO(nicholss): Not implemented yet. |
| 217 return nil; | 243 return nil; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 237 | 263 |
| 238 - (void)hostSessionStatusChanged:(NSNotification*)notification { | 264 - (void)hostSessionStatusChanged:(NSNotification*)notification { |
| 239 NSLog(@"hostSessionStatusChanged: %@", [notification userInfo]); | 265 NSLog(@"hostSessionStatusChanged: %@", [notification userInfo]); |
| 240 } | 266 } |
| 241 | 267 |
| 242 - (void)closeViewController { | 268 - (void)closeViewController { |
| 243 [self dismissViewControllerAnimated:true completion:nil]; | 269 [self dismissViewControllerAnimated:true completion:nil]; |
| 244 } | 270 } |
| 245 | 271 |
| 246 - (void)didSelectRefresh { | 272 - (void)didSelectRefresh { |
| 247 // TODO(nicholss) implement this. | 273 // TODO(nicholss): Might want to rate limit this. Maybe remoting service |
| 248 NSLog(@"Should refresh..."); | 274 // controls that. |
| 249 _dialogTransitionController = [[MDCDialogTransitionController alloc] init]; | 275 [_remotingService requestHostListFetch]; |
| 250 } | 276 } |
| 251 | 277 |
| 252 - (void)didSelectSettings { | 278 - (void)didSelectSettings { |
| 253 RemotingSettingsViewController* settingsViewController = | 279 RemotingSettingsViewController* settingsViewController = |
| 254 [[RemotingSettingsViewController alloc] init]; | 280 [[RemotingSettingsViewController alloc] init]; |
| 255 [self presentViewController:settingsViewController | 281 [self presentViewController:settingsViewController |
| 256 animated:YES | 282 animated:YES |
| 257 completion:nil]; | 283 completion:nil]; |
| 258 } | 284 } |
| 259 | 285 |
| 260 - (void)presentStatus { | 286 - (void)presentStatus { |
| 261 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 287 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
| 262 if (_isAuthenticated) { | 288 if (_isAuthenticated) { |
| 263 UserInfo* user = [_remotingService getUser]; | 289 message.text = [NSString stringWithFormat:@"Currently signed in as %@.", |
| 264 message.text = [NSString | 290 _remotingService.user.userEmail]; |
| 265 stringWithFormat:@"Currently signed in as %@.", [user userEmail]]; | |
| 266 [MDCSnackbarManager showMessage:message]; | 291 [MDCSnackbarManager showMessage:message]; |
| 267 } | 292 } |
| 268 } | 293 } |
| 269 | 294 |
| 270 @end | 295 @end |
| OLD | NEW |