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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "base/strings/sys_string_conversions.h" | 30 #include "base/strings/sys_string_conversions.h" |
31 #include "remoting/base/oauth_token_getter.h" | 31 #include "remoting/base/oauth_token_getter.h" |
32 #include "remoting/client/connect_to_host_info.h" | 32 #include "remoting/client/connect_to_host_info.h" |
33 | 33 |
34 static CGFloat kHostInset = 5.f; | 34 static CGFloat kHostInset = 5.f; |
35 | 35 |
36 @interface RemotingViewController ()<HostCollectionViewControllerDelegate, | 36 @interface RemotingViewController ()<HostCollectionViewControllerDelegate, |
37 UIViewControllerAnimatedTransitioning, | 37 UIViewControllerAnimatedTransitioning, |
38 UIViewControllerTransitioningDelegate> { | 38 UIViewControllerTransitioningDelegate> { |
39 bool _isAuthenticated; | 39 BOOL _isAuthenticated; |
| 40 BOOL _showSignedInAccount; |
40 MDCDialogTransitionController* _dialogTransitionController; | 41 MDCDialogTransitionController* _dialogTransitionController; |
41 MDCAppBar* _appBar; | 42 MDCAppBar* _appBar; |
42 HostCollectionViewController* _collectionViewController; | 43 HostCollectionViewController* _collectionViewController; |
43 HostFetchingViewController* _fetchingViewController; | 44 HostFetchingViewController* _fetchingViewController; |
44 HostSetupViewController* _setupViewController; | 45 HostSetupViewController* _setupViewController; |
45 RemotingService* _remotingService; | 46 RemotingService* _remotingService; |
46 } | 47 } |
47 @end | 48 @end |
48 | 49 |
49 // TODO(nicholss): Localize this file. | 50 // TODO(nicholss): Localize this file. |
50 // TODO(nicholss): This file is not finished with integration, the app flow is | 51 // TODO(nicholss): This file is not finished with integration, the app flow is |
51 // still pending development. | 52 // still pending development. |
52 | 53 |
53 @implementation RemotingViewController | 54 @implementation RemotingViewController |
54 | 55 |
55 - (instancetype)init { | 56 - (instancetype)init { |
56 _isAuthenticated = NO; | 57 _isAuthenticated = NO; |
| 58 _showSignedInAccount = YES; |
57 UICollectionViewFlowLayout* layout = | 59 UICollectionViewFlowLayout* layout = |
58 [[MDCCollectionViewFlowLayout alloc] init]; | 60 [[MDCCollectionViewFlowLayout alloc] init]; |
59 layout.minimumInteritemSpacing = 0; | 61 layout.minimumInteritemSpacing = 0; |
60 CGFloat sectionInset = kHostInset * 2.f; | 62 CGFloat sectionInset = kHostInset * 2.f; |
61 [layout setSectionInset:UIEdgeInsetsMake(sectionInset, sectionInset, | 63 [layout setSectionInset:UIEdgeInsetsMake(sectionInset, sectionInset, |
62 sectionInset, sectionInset)]; | 64 sectionInset, sectionInset)]; |
63 self = [super init]; | 65 self = [super init]; |
64 if (self) { | 66 if (self) { |
65 _remotingService = RemotingService.instance; | 67 _remotingService = RemotingService.instance; |
66 | 68 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 selector:@selector(hostListStateDidChangeNotification:) | 142 selector:@selector(hostListStateDidChangeNotification:) |
141 name:kHostListStateDidChange | 143 name:kHostListStateDidChange |
142 object:nil]; | 144 object:nil]; |
143 [[NSNotificationCenter defaultCenter] | 145 [[NSNotificationCenter defaultCenter] |
144 addObserver:self | 146 addObserver:self |
145 selector:@selector(userDidUpdateNotification:) | 147 selector:@selector(userDidUpdateNotification:) |
146 name:kUserDidUpdate | 148 name:kUserDidUpdate |
147 object:nil]; | 149 object:nil]; |
148 } | 150 } |
149 | 151 |
150 - (void)viewWillAppear:(BOOL)animated { | |
151 [super viewWillAppear:animated]; | |
152 | |
153 [self nowAuthenticated:_remotingService.authentication.user.isAuthenticated]; | |
154 if (_isAuthenticated) { | |
155 [_remotingService requestHostListFetch]; | |
156 } | |
157 [self presentStatus]; | |
158 } | |
159 | |
160 - (void)viewDidAppear:(BOOL)animated { | 152 - (void)viewDidAppear:(BOOL)animated { |
161 [super viewDidAppear:animated]; | 153 [super viewDidAppear:animated]; |
162 if (!_isAuthenticated) { | 154 if (!_remotingService.authentication.user.isAuthenticated) { |
163 [AppDelegate.instance presentSignInFlow]; | 155 [AppDelegate.instance presentSignInFlow]; |
164 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 156 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
165 message.text = @"Please login."; | 157 message.text = @"Please login."; |
166 [MDCSnackbarManager showMessage:message]; | 158 [MDCSnackbarManager showMessage:message]; |
167 } | 159 } |
168 } | 160 } |
169 | 161 |
170 - (UIStatusBarStyle)preferredStatusBarStyle { | 162 - (UIStatusBarStyle)preferredStatusBarStyle { |
171 return UIStatusBarStyleLightContent; | 163 return UIStatusBarStyleLightContent; |
172 } | 164 } |
173 | 165 |
174 #pragma mark - Remoting Service Notifications | 166 #pragma mark - Remoting Service Notifications |
175 | 167 |
176 - (void)hostListStateDidChangeNotification:(NSNotification*)notification { | 168 - (void)hostListStateDidChangeNotification:(NSNotification*)notification { |
177 [self refreshContent]; | 169 [self refreshContent]; |
178 } | 170 } |
179 | 171 |
180 - (void)userDidUpdateNotification:(NSNotification*)notification { | 172 - (void)userDidUpdateNotification:(NSNotification*)notification { |
181 [self nowAuthenticated:_remotingService.authentication.user.isAuthenticated]; | 173 [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 174 [self |
| 175 nowAuthenticated:_remotingService.authentication.user.isAuthenticated]; |
| 176 }]; |
182 } | 177 } |
183 | 178 |
184 #pragma mark - RemotingAuthenticationDelegate | 179 #pragma mark - RemotingAuthenticationDelegate |
185 | 180 |
186 - (void)nowAuthenticated:(BOOL)authenticated { | 181 - (void)nowAuthenticated:(BOOL)authenticated { |
| 182 _isAuthenticated = authenticated; |
187 if (authenticated) { | 183 if (authenticated) { |
188 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 184 _showSignedInAccount = YES; |
189 message.text = @"Logged In!"; | 185 [self presentStatus]; |
190 [MDCSnackbarManager showMessage:message]; | |
191 } else { | 186 } else { |
192 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 187 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
193 message.text = @"Not logged in."; | 188 message.text = @"Please sign-in."; |
194 [MDCSnackbarManager showMessage:message]; | 189 [MDCSnackbarManager showMessage:message]; |
195 } | 190 } |
196 _isAuthenticated = authenticated; | |
197 [self refreshContent]; | 191 [self refreshContent]; |
198 } | 192 } |
199 | 193 |
200 #pragma mark - HostCollectionViewControllerDelegate | 194 #pragma mark - HostCollectionViewControllerDelegate |
201 | 195 |
202 - (void)didSelectCell:(HostCollectionViewCell*)cell | 196 - (void)didSelectCell:(HostCollectionViewCell*)cell |
203 completion:(void (^)())completionBlock { | 197 completion:(void (^)())completionBlock { |
204 if (![cell.hostInfo isOnline]) { | 198 if (![cell.hostInfo isOnline]) { |
205 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 199 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
206 message.text = @"Host is offline."; | 200 message.text = @"Host is offline."; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // controls that. | 255 // controls that. |
262 [_remotingService requestHostListFetch]; | 256 [_remotingService requestHostListFetch]; |
263 } | 257 } |
264 | 258 |
265 - (void)didSelectMenu { | 259 - (void)didSelectMenu { |
266 [AppDelegate.instance showMenuAnimated:YES]; | 260 [AppDelegate.instance showMenuAnimated:YES]; |
267 } | 261 } |
268 | 262 |
269 - (void)presentStatus { | 263 - (void)presentStatus { |
270 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; | 264 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; |
271 if (_isAuthenticated) { | 265 if (_isAuthenticated && _showSignedInAccount) { |
| 266 _showSignedInAccount = NO; |
272 message.text = [NSString | 267 message.text = [NSString |
273 stringWithFormat:@"Currently signed in as %@.", | 268 stringWithFormat:@"Currently signed in as %@.", |
274 _remotingService.authentication.user.userEmail]; | 269 _remotingService.authentication.user.userEmail]; |
275 [MDCSnackbarManager showMessage:message]; | 270 [MDCSnackbarManager showMessage:message]; |
276 } | 271 } |
277 } | 272 } |
278 | 273 |
279 - (void)refreshContent { | 274 - (void)refreshContent { |
280 if (_remotingService.hostListState == HostListStateNotFetched) { | 275 if (_remotingService.hostListState == HostListStateNotFetched) { |
281 self.contentViewController = nil; | 276 self.contentViewController = nil; |
(...skipping 15 matching lines...) Expand all Loading... |
297 self.contentViewController = _collectionViewController; | 292 self.contentViewController = _collectionViewController; |
298 } else { | 293 } else { |
299 self.contentViewController = _setupViewController; | 294 self.contentViewController = _setupViewController; |
300 self.headerViewController.headerView.trackingScrollView = | 295 self.headerViewController.headerView.trackingScrollView = |
301 _setupViewController.collectionView; | 296 _setupViewController.collectionView; |
302 } | 297 } |
303 self.contentViewController.view.frame = self.view.bounds; | 298 self.contentViewController.view.frame = self.view.bounds; |
304 } | 299 } |
305 | 300 |
306 @end | 301 @end |
OLD | NEW |