Chromium Code Reviews| Index: webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m |
| diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m b/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..12d14db8c6c58ed62cad573ee69539541094ff47 |
| --- /dev/null |
| +++ b/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m |
| @@ -0,0 +1,160 @@ |
| +/* |
| + * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#import "ARDSettingsViewController.h" |
| +#import "ARDMediaConstraintsModel.h" |
| + |
| +NS_ASSUME_NONNULL_BEGIN |
| +@interface ARDSettingsViewController () { |
| + ARDMediaConstraintsModel *_mediaConstraintsModel; |
| +} |
| + |
| +@end |
| + |
| +@implementation ARDSettingsViewController |
| + |
| +- (instancetype)initWithStyle:(UITableViewStyle)style |
| + mediaConstraintsModel:(ARDMediaConstraintsModel *)mediaConstraintsModel { |
| + self = [super initWithStyle:style]; |
| + if (self) { |
| + _mediaConstraintsModel = mediaConstraintsModel; |
| + } |
| + return self; |
| +} |
| + |
| +#pragma mark - View lifecycle |
| + |
| +- (void)viewDidLoad { |
| + [super viewDidLoad]; |
| + self.title = @"Settings"; |
| + [self addDoneBarButton]; |
| +} |
| + |
| +- (void)viewDidAppear:(BOOL)animated { |
| + [super viewDidAppear:animated]; |
| + [self selectCurrentlyStoredOrDefaultMediaConstraints]; |
| +} |
| + |
| +- (NSArray<NSString *> *)mediaConstraintsArray { |
|
magjed_webrtc
2016/10/31 19:26:39
should this function be under 'View lifecycle'?
daniela-webrtc
2016/11/01 09:51:12
Done.
|
| + return _mediaConstraintsModel.availableVideoResoultionsMediaConstraints; |
| +} |
| + |
| +#pragma mark - |
|
magjed_webrtc
2016/10/31 19:26:39
nit: Shouldn't this section have a name?
daniela-webrtc
2016/11/01 09:51:13
Not necessarily. The pragma marks are useful for l
|
| + |
| +- (void)addDoneBarButton { |
| + UIBarButtonItem *barItem = |
| + [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
| + target:self |
| + action:@selector(dismissModally:)]; |
| + self.navigationItem.leftBarButtonItem = barItem; |
| +} |
| + |
| +- (void)selectCurrentlyStoredOrDefaultMediaConstraints { |
| + NSString *currentSelection = [_mediaConstraintsModel currentVideoResoultionConstraintFromStore]; |
| + |
| + NSUInteger indexOfSelection = [[self mediaConstraintsArray] indexOfObject:currentSelection]; |
| + NSIndexPath *pathToBeSelected = [NSIndexPath indexPathForRow:indexOfSelection inSection:0]; |
| + [self.tableView selectRowAtIndexPath:pathToBeSelected |
| + animated:NO |
| + scrollPosition:UITableViewScrollPositionNone]; |
| + // Manully invoke the delegate method because the previous invocation will not |
|
magjed_webrtc
2016/10/31 19:26:39
nit: dot at end of sentence.
daniela-webrtc
2016/11/01 09:51:12
Done.
|
| + [self tableView:self.tableView didSelectRowAtIndexPath:pathToBeSelected]; |
| +} |
| + |
| +#pragma mark - Dismissall of view controller |
|
magjed_webrtc
2016/10/31 19:26:39
nit: dismissal
daniela-webrtc
2016/11/01 09:51:13
Done.
|
| + |
| +- (void)dismissModally:(id)sender { |
| + [self dismissViewControllerAnimated:YES completion:nil]; |
| +} |
| + |
| +#pragma mark - Table view data source |
| + |
| +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
| + return 1; |
| +} |
| + |
| +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
| + return self.mediaConstraintsArray.count; |
| +} |
| + |
| +#pragma mark - Tablev view delegate |
|
magjed_webrtc
2016/10/31 19:26:39
nit: Table
daniela-webrtc
2016/11/01 09:51:12
Done.
|
| + |
| +- (BOOL)sectionIsMediaConstraints:(int)section { |
| + return section == 0; |
| +} |
| + |
| +- (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath { |
| + return [self sectionIsMediaConstraints:indexPath.section]; |
| +} |
| + |
| +- (nullable NSString *)tableView:(UITableView *)tableView |
| + titleForHeaderInSection:(NSInteger)section { |
| + if ([self sectionIsMediaConstraints:section]) { |
| + return @"Media constraints"; |
| + } |
| + return @""; |
| +} |
| + |
| +- (UITableViewCell *)tableView:(UITableView *)tableView |
|
magjed_webrtc
2016/10/31 19:26:39
The following functions - are they standard boiler
daniela-webrtc
2016/11/01 09:51:12
Standard boiler plate :( And this is the bare mini
|
| + cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
| + if ([self indexPathIsMediaConstraints:indexPath]) { |
| + return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath:indexPath]; |
| + } |
| + return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
| + reuseIdentifier:@"identifier"]; |
| +} |
| + |
| +- (nullable NSIndexPath *)tableView:(UITableView *)tableView |
| + willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { |
| + if ([self indexPathIsMediaConstraints:indexPath]) { |
| + return [self tableView:tableView willDeselectMediaConstraintsRowAtIndexPath:indexPath]; |
| + } |
| + return indexPath; |
| +} |
| + |
| +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
| + if ([self indexPathIsMediaConstraints:indexPath]) { |
| + [self tableView:tableView didSelectMediaConstraintsCellAtIndexPath:indexPath]; |
| + } |
| +} |
| + |
| +#pragma mark - Table view delegate(Media Constraints) |
| + |
| +- (UITableViewCell *)mediaConstraintsTableViewCellForTableView:(UITableView *)tableView |
| + atIndexPath:(NSIndexPath *)indexPath { |
| + NSString *dequeueIdentifier = @"ARDSettingsMediaConstraintsViewCellIdentifier"; |
| + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueIdentifier]; |
| + if (!cell) { |
| + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
| + reuseIdentifier:dequeueIdentifier]; |
| + } |
| + cell.textLabel.text = self.mediaConstraintsArray[indexPath.row]; |
| + return cell; |
| +} |
| + |
| +- (void)tableView:(UITableView *)tableView |
| + didSelectMediaConstraintsCellAtIndexPath:(NSIndexPath *)indexPath { |
| + UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; |
| + cell.accessoryType = UITableViewCellAccessoryCheckmark; |
| + |
| + NSString *mediaConstraintsString = self.mediaConstraintsArray[indexPath.row]; |
| + [_mediaConstraintsModel storeVideoResoultionConstraint:mediaConstraintsString]; |
| +} |
| + |
| +- (NSIndexPath *)tableView:(UITableView *)tableView |
| + willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath { |
| + NSIndexPath *oldSelection = [tableView indexPathForSelectedRow]; |
| + UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection]; |
| + cell.accessoryType = UITableViewCellAccessoryNone; |
| + return indexPath; |
| +} |
| + |
| +@end |
| +NS_ASSUME_NONNULL_END |