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 |
index 815b14799f7cf388c2a4813620954ce6f676fec9..6c33d63aaf0cb57a68de93dbaf943d7502cfe016 100644 |
--- a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m |
+++ b/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m |
@@ -15,7 +15,8 @@ NS_ASSUME_NONNULL_BEGIN |
typedef NS_ENUM(int, ARDSettingsSections) { |
ARDSettingsSectionMediaConstraints = 0, |
- ARDSettingsSectionBitRate |
+ ARDSettingsSectionVideoCodec, |
+ ARDSettingsSectionBitRate, |
}; |
@interface ARDSettingsViewController () <UITextFieldDelegate> { |
@@ -43,9 +44,14 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
[self addDoneBarButton]; |
} |
+- (void)viewWillAppear:(BOOL)animated { |
+ [super viewWillAppear:animated]; |
+ [self decorateCurrentlyStoredOrDefaultMediaConstraints]; |
+ [self decorateCurrentlyStoredOrDefaultVideoCodec]; |
kthelgason
2017/03/09 13:39:43
Is this safe to do here? Why not in viewDidAppear?
sakal
2017/03/10 10:25:28
I didn't notice any problems in my testing. If we
|
+} |
+ |
- (void)viewDidAppear:(BOOL)animated { |
[super viewDidAppear:animated]; |
- [self selectCurrentlyStoredOrDefaultMediaConstraints]; |
} |
#pragma mark - Data source |
@@ -54,6 +60,10 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
return _settingsModel.availableVideoResoultionsMediaConstraints; |
} |
+- (NSArray<NSString *> *)videoCodecArray { |
+ return _settingsModel.availableVideoCodecs; |
+} |
+ |
#pragma mark - |
- (void)addDoneBarButton { |
@@ -64,16 +74,24 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
self.navigationItem.leftBarButtonItem = barItem; |
} |
-- (void)selectCurrentlyStoredOrDefaultMediaConstraints { |
+- (void)decorateCurrentlyStoredOrDefaultMediaConstraints { |
NSString *currentSelection = [_settingsModel 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. |
- [self tableView:self.tableView didSelectRowAtIndexPath:pathToBeSelected]; |
+ NSIndexPath *pathToBeDecorated = [NSIndexPath indexPathForRow:indexOfSelection |
+ inSection:ARDSettingsSectionMediaConstraints]; |
+ UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:pathToBeDecorated]; |
+ cell.accessoryType = UITableViewCellAccessoryCheckmark; |
+} |
+ |
+- (void)decorateCurrentlyStoredOrDefaultVideoCodec { |
+ NSString *currentSelection = [_settingsModel currentVideoCodecSettingFromStore]; |
+ |
+ NSUInteger indexOfSelection = [[self videoCodecArray] indexOfObject:currentSelection]; |
+ NSIndexPath *pathToBeDecorated = [NSIndexPath indexPathForRow:indexOfSelection |
+ inSection:ARDSettingsSectionVideoCodec]; |
+ UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:pathToBeDecorated]; |
+ cell.accessoryType = UITableViewCellAccessoryCheckmark; |
} |
#pragma mark - Dismissal of view controller |
@@ -85,13 +103,16 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
#pragma mark - Table view data source |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
- return 2; |
+ return 3; |
} |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
if ([self sectionIsMediaConstraints:section]) { |
return self.mediaConstraintsArray.count; |
} |
+ if ([self sectionIsVideoCodec:section]) { |
+ return self.videoCodecArray.count; |
+ } |
kthelgason
2017/03/09 13:39:43
I'd prefer a switch-case on section here.
sakal
2017/03/10 10:25:28
Done.
|
return 1; |
} |
@@ -102,6 +123,10 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
return section == ARDSettingsSectionMediaConstraints; |
} |
+- (BOOL)sectionIsVideoCodec:(int)section { |
+ return section == ARDSettingsSectionVideoCodec; |
+} |
+ |
- (BOOL)sectionIsBitrate:(int)section { |
return section == ARDSettingsSectionBitRate; |
} |
@@ -110,10 +135,26 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
return [self sectionIsMediaConstraints:indexPath.section]; |
} |
+- (BOOL)indexPathIsVideoCodec:(NSIndexPath *)indexPath { |
+ return [self sectionIsVideoCodec:indexPath.section]; |
+} |
+ |
- (BOOL)indexPathIsBitrate:(NSIndexPath *)indexPath { |
return [self sectionIsBitrate:indexPath.section]; |
} |
+#pragma mark - Table view delegate helpers |
+ |
+- (void)removeAllAccessories:(UITableView *)tableView |
+ inSection:(int)section |
+{ |
+ for (int i = 0; i < [tableView numberOfRowsInSection:section]; i++) { |
+ NSIndexPath *rowPath = [NSIndexPath indexPathForRow:i inSection:section]; |
+ UITableViewCell *cell = [tableView cellForRowAtIndexPath:rowPath]; |
+ cell.accessoryType = UITableViewCellAccessoryNone; |
+ } |
+} |
+ |
#pragma mark - Table view delegate |
- (nullable NSString *)tableView:(UITableView *)tableView |
@@ -126,6 +167,10 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
return @"Maximum bitrate"; |
} |
+ if ([self sectionIsVideoCodec:section]) { |
+ return @"Video codec"; |
+ } |
+ |
return @""; |
} |
@@ -135,6 +180,10 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath:indexPath]; |
} |
+ if ([self indexPathIsVideoCodec:indexPath]) { |
+ return [self videoCodecTableViewCellForTableView:tableView atIndexPath:indexPath]; |
+ } |
+ |
if ([self indexPathIsBitrate:indexPath]) { |
return [self bitrateTableViewCellForTableView:tableView atIndexPath:indexPath]; |
} |
@@ -143,18 +192,13 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
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]; |
} |
+ if ([self indexPathIsVideoCodec:indexPath]) { |
+ [self tableView:tableView didSelectVideoCodecCellAtIndexPath:indexPath]; |
+ } |
} |
#pragma mark - Table view delegate(Media Constraints) |
@@ -173,19 +217,41 @@ typedef NS_ENUM(int, ARDSettingsSections) { |
- (void)tableView:(UITableView *)tableView |
didSelectMediaConstraintsCellAtIndexPath:(NSIndexPath *)indexPath { |
+ [self removeAllAccessories:tableView inSection:ARDSettingsSectionMediaConstraints]; |
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
NSString *mediaConstraintsString = self.mediaConstraintsArray[indexPath.row]; |
[_settingsModel storeVideoResoultionConstraint:mediaConstraintsString]; |
+ |
+ [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
} |
-- (NSIndexPath *)tableView:(UITableView *)tableView |
- willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath { |
- NSIndexPath *oldSelection = [tableView indexPathForSelectedRow]; |
- UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection]; |
- cell.accessoryType = UITableViewCellAccessoryNone; |
- return indexPath; |
+#pragma mark - Table view delegate(Video Codec) |
+ |
+- (UITableViewCell *)videoCodecTableViewCellForTableView:(UITableView *)tableView |
+ atIndexPath:(NSIndexPath *)indexPath { |
+ NSString *dequeueIdentifier = @"ARDSettingsVideoCodecCellIdentifier"; |
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueIdentifier]; |
+ if (!cell) { |
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
+ reuseIdentifier:dequeueIdentifier]; |
+ } |
+ cell.textLabel.text = self.videoCodecArray[indexPath.row]; |
+ |
+ return cell; |
+} |
kthelgason
2017/03/09 13:39:43
It seems to me that there is a lot of shared code
sakal
2017/03/10 10:25:28
Done.
|
+ |
+- (void)tableView:(UITableView *)tableView |
+ didSelectVideoCodecCellAtIndexPath:(NSIndexPath *)indexPath { |
+ [self removeAllAccessories:tableView inSection:ARDSettingsSectionVideoCodec]; |
+ UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; |
+ cell.accessoryType = UITableViewCellAccessoryCheckmark; |
+ |
+ NSString *videoCodec = self.videoCodecArray[indexPath.row]; |
+ [_settingsModel storeVideoCodecSetting:videoCodec]; |
+ |
+ [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
} |
#pragma mark - Table view delegate(Bitrate) |