Chromium Code Reviews| 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/ios/app/remoting_view_controller.h" | 9 #import "remoting/ios/app/remoting_view_controller.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 #include "base/strings/sys_string_conversions.h" | 26 #include "base/strings/sys_string_conversions.h" |
| 27 #include "remoting/base/oauth_token_getter.h" | 27 #include "remoting/base/oauth_token_getter.h" |
| 28 #include "remoting/client/connect_to_host_info.h" | 28 #include "remoting/client/connect_to_host_info.h" |
| 29 | 29 |
| 30 static CGFloat kHostInset = 5.f; | 30 static CGFloat kHostInset = 5.f; |
| 31 | 31 |
| 32 @interface RemotingViewController ()<HostCollectionViewControllerDelegate, | 32 @interface RemotingViewController ()<HostCollectionViewControllerDelegate, |
| 33 UIViewControllerAnimatedTransitioning, | 33 UIViewControllerAnimatedTransitioning, |
| 34 UIViewControllerTransitioningDelegate> { | 34 UIViewControllerTransitioningDelegate> { |
| 35 bool _isAuthenticated; | 35 BOOL _isAuthenticated; |
| 36 BOOL _showAccountSignIn; | |
|
Yuwei
2017/07/06 22:29:45
Maybe change this to _showSignedInAccount? _showAc
nicholss
2017/07/06 22:40:01
sounds fine. Done.
| |
| 36 MDCDialogTransitionController* _dialogTransitionController; | 37 MDCDialogTransitionController* _dialogTransitionController; |
| 37 MDCAppBar* _appBar; | 38 MDCAppBar* _appBar; |
| 38 HostCollectionViewController* _collectionViewController; | 39 HostCollectionViewController* _collectionViewController; |
| 39 RemotingService* _remotingService; | 40 RemotingService* _remotingService; |
| 40 } | 41 } |
| 41 @end | 42 @end |
| 42 | 43 |
| 43 // TODO(nicholss): Localize this file. | 44 // TODO(nicholss): Localize this file. |
| 44 // TODO(nicholss): This file is not finished with integration, the app flow is | 45 // TODO(nicholss): This file is not finished with integration, the app flow is |
| 45 // still pending development. | 46 // still pending development. |
| 46 | 47 |
| 47 @implementation RemotingViewController | 48 @implementation RemotingViewController |
| 48 | 49 |
| 49 - (instancetype)init { | 50 - (instancetype)init { |
| 50 _isAuthenticated = NO; | 51 _isAuthenticated = NO; |
| 52 _showAccountSignIn = YES; | |
| 51 UICollectionViewFlowLayout* layout = | 53 UICollectionViewFlowLayout* layout = |
| 52 [[MDCCollectionViewFlowLayout alloc] init]; | 54 [[MDCCollectionViewFlowLayout alloc] init]; |
| 53 layout.minimumInteritemSpacing = 0; | 55 layout.minimumInteritemSpacing = 0; |
| 54 CGFloat sectionInset = kHostInset * 2.f; | 56 CGFloat sectionInset = kHostInset * 2.f; |
| 55 [layout setSectionInset:UIEdgeInsetsMake(sectionInset, sectionInset, | 57 [layout setSectionInset:UIEdgeInsetsMake(sectionInset, sectionInset, |
| 56 sectionInset, sectionInset)]; | 58 sectionInset, sectionInset)]; |
| 57 HostCollectionViewController* collectionVC = [ | 59 HostCollectionViewController* collectionVC = [ |
| 58 [HostCollectionViewController alloc] initWithCollectionViewLayout:layout]; | 60 [HostCollectionViewController alloc] initWithCollectionViewLayout:layout]; |
| 59 self = [super initWithContentViewController:collectionVC]; | 61 self = [super initWithContentViewController:collectionVC]; |
| 60 if (self) { | 62 if (self) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 selector:@selector(hostsDidUpdateNotification:) | 121 selector:@selector(hostsDidUpdateNotification:) |
| 120 name:kHostsDidUpdate | 122 name:kHostsDidUpdate |
| 121 object:nil]; | 123 object:nil]; |
| 122 [[NSNotificationCenter defaultCenter] | 124 [[NSNotificationCenter defaultCenter] |
| 123 addObserver:self | 125 addObserver:self |
| 124 selector:@selector(userDidUpdateNotification:) | 126 selector:@selector(userDidUpdateNotification:) |
| 125 name:kUserDidUpdate | 127 name:kUserDidUpdate |
| 126 object:nil]; | 128 object:nil]; |
| 127 } | 129 } |
| 128 | 130 |
| 129 - (void)viewWillAppear:(BOOL)animated { | |
| 130 [super viewWillAppear:animated]; | |
| 131 | |
| 132 [self nowAuthenticated:_remotingService.authentication.user.isAuthenticated]; | |
| 133 [self presentStatus]; | |
| 134 } | |
| 135 | |
| 136 - (void)viewDidAppear:(BOOL)animated { | 131 - (void)viewDidAppear:(BOOL)animated { |
| 137 [super viewDidAppear:animated]; | 132 [super viewDidAppear:animated]; |
| 138 if (!_isAuthenticated) { | 133 if (!_remotingService.authentication.user.isAuthenticated) { |
| 139 [AppDelegate.instance presentSignInFlow]; | 134 [AppDelegate.instance presentSignInFlow]; |
| 140 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 135 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
| 141 message.text = @"Please login."; | 136 message.text = @"Please login."; |
| 142 [MDCSnackbarManager showMessage:message]; | 137 [MDCSnackbarManager showMessage:message]; |
| 143 } else { | 138 } else { |
| 144 [_remotingService requestHostListFetch]; | 139 [_remotingService requestHostListFetch]; |
| 145 } | 140 } |
| 146 } | 141 } |
| 147 | 142 |
| 148 - (UIStatusBarStyle)preferredStatusBarStyle { | 143 - (UIStatusBarStyle)preferredStatusBarStyle { |
| 149 return UIStatusBarStyleLightContent; | 144 return UIStatusBarStyleLightContent; |
| 150 } | 145 } |
| 151 | 146 |
| 152 #pragma mark - Remoting Service Notifications | 147 #pragma mark - Remoting Service Notifications |
| 153 | 148 |
| 154 - (void)hostsDidUpdateNotification:(NSNotification*)notification { | 149 - (void)hostsDidUpdateNotification:(NSNotification*)notification { |
| 155 [_collectionViewController.collectionView reloadData]; | 150 [_collectionViewController.collectionView reloadData]; |
| 156 } | 151 } |
| 157 | 152 |
| 158 - (void)userDidUpdateNotification:(NSNotification*)notification { | 153 - (void)userDidUpdateNotification:(NSNotification*)notification { |
| 159 [self nowAuthenticated:_remotingService.authentication.user.isAuthenticated]; | 154 [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 155 [self | |
| 156 nowAuthenticated:_remotingService.authentication.user.isAuthenticated]; | |
| 157 }]; | |
| 160 } | 158 } |
| 161 | 159 |
| 162 #pragma mark - RemotingAuthenticationDelegate | 160 #pragma mark - RemotingAuthenticationDelegate |
| 163 | 161 |
| 164 - (void)nowAuthenticated:(BOOL)authenticated { | 162 - (void)nowAuthenticated:(BOOL)authenticated { |
| 163 _isAuthenticated = authenticated; | |
| 165 if (authenticated) { | 164 if (authenticated) { |
| 166 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 165 _showAccountSignIn = YES; |
| 167 message.text = @"Logged In!"; | 166 [self presentStatus]; |
| 168 [MDCSnackbarManager showMessage:message]; | |
| 169 } else { | 167 } else { |
| 170 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 168 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
|
Yuwei
2017/07/06 22:29:45
If we already presentSignInFlow if the user hasn't
nicholss
2017/07/06 22:40:01
Acknowledged.
| |
| 171 message.text = @"Not logged in."; | 169 message.text = @"Please sign-in."; |
| 172 [MDCSnackbarManager showMessage:message]; | 170 [MDCSnackbarManager showMessage:message]; |
| 173 } | 171 } |
| 174 _isAuthenticated = authenticated; | |
| 175 [_collectionViewController.collectionView reloadData]; | 172 [_collectionViewController.collectionView reloadData]; |
| 176 } | 173 } |
| 177 | 174 |
| 178 #pragma mark - RemotingHostListDelegate | 175 #pragma mark - RemotingHostListDelegate |
| 179 | 176 |
| 180 // TODO(nicholss): these need to be a stats change like "none, loading, | 177 // TODO(nicholss): these need to be a stats change like "none, loading, |
| 181 // updated"... | 178 // updated"... |
| 182 - (void)hostListUpdated { | 179 - (void)hostListUpdated { |
| 183 [_collectionViewController.collectionView reloadData]; | 180 [_collectionViewController.collectionView reloadData]; |
| 184 } | 181 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 // controls that. | 244 // controls that. |
| 248 [_remotingService requestHostListFetch]; | 245 [_remotingService requestHostListFetch]; |
| 249 } | 246 } |
| 250 | 247 |
| 251 - (void)didSelectMenu { | 248 - (void)didSelectMenu { |
| 252 [AppDelegate.instance showMenuAnimated:YES]; | 249 [AppDelegate.instance showMenuAnimated:YES]; |
| 253 } | 250 } |
| 254 | 251 |
| 255 - (void)presentStatus { | 252 - (void)presentStatus { |
| 256 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 253 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
| 257 if (_isAuthenticated) { | 254 if (_isAuthenticated && _showAccountSignIn) { |
|
Yuwei
2017/07/06 22:29:45
I think we still want to show the message if the u
nicholss
2017/07/06 22:40:01
I think that sounds like a good refactor, pull all
| |
| 255 _showAccountSignIn = NO; | |
| 258 message.text = [NSString | 256 message.text = [NSString |
| 259 stringWithFormat:@"Currently signed in as %@.", | 257 stringWithFormat:@"Currently signed in as %@.", |
| 260 _remotingService.authentication.user.userEmail]; | 258 _remotingService.authentication.user.userEmail]; |
| 261 [MDCSnackbarManager showMessage:message]; | 259 [MDCSnackbarManager showMessage:message]; |
| 262 } | 260 } |
| 263 } | 261 } |
| 264 | 262 |
| 265 @end | 263 @end |
| OLD | NEW |