Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m

Issue 2462623002: Add setting to AppRTCMobile for iOS, that can change capture resolution. (Closed)
Patch Set: Add check to make sure only available constraint is being stored. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #import "ARDSettingsViewController.h"
12 #import "ARDMediaConstraintsModel.h"
13
14 NS_ASSUME_NONNULL_BEGIN
15 @interface ARDSettingsViewController () {
16 ARDMediaConstraintsModel *_mediaConstraintsModel;
17 }
18
19 @end
20
21 @implementation ARDSettingsViewController
22
23 - (instancetype)initWithStyle:(UITableViewStyle)style
24 mediaConstraintsModel:(ARDMediaConstraintsModel *)mediaConstraintsModel {
25 self = [super initWithStyle:style];
26 if (self) {
27 _mediaConstraintsModel = mediaConstraintsModel;
28 }
29 return self;
30 }
31
32 #pragma mark - View lifecycle
33
34 - (void)viewDidLoad {
35 [super viewDidLoad];
36 self.title = @"Settings";
37 [self addDoneBarButton];
38 }
39
40 - (void)viewDidAppear:(BOOL)animated {
41 [super viewDidAppear:animated];
42 [self selectCurrentlyStoredOrDefaultMediaConstraints];
43 }
44
45 #pragma mark - Data source
46
47 - (NSArray<NSString *> *)mediaConstraintsArray {
48 return _mediaConstraintsModel.availableVideoResoultionsMediaConstraints;
49 }
50
51 #pragma mark -
52
53 - (void)addDoneBarButton {
54 UIBarButtonItem *barItem =
55 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem Done
56 target:self
57 action:@selector(dismissModa lly:)];
58 self.navigationItem.leftBarButtonItem = barItem;
59 }
60
61 - (void)selectCurrentlyStoredOrDefaultMediaConstraints {
62 NSString *currentSelection = [_mediaConstraintsModel currentVideoResoultionCon straintFromStore];
63
64 NSUInteger indexOfSelection = [[self mediaConstraintsArray] indexOfObject:curr entSelection];
65 NSIndexPath *pathToBeSelected = [NSIndexPath indexPathForRow:indexOfSelection inSection:0];
66 [self.tableView selectRowAtIndexPath:pathToBeSelected
67 animated:NO
68 scrollPosition:UITableViewScrollPositionNone];
69 // Manully invoke the delegate method because the previous invocation will not .
70 [self tableView:self.tableView didSelectRowAtIndexPath:pathToBeSelected];
71 }
72
73 #pragma mark - Dismissal of view controller
74
75 - (void)dismissModally:(id)sender {
76 [self dismissViewControllerAnimated:YES completion:nil];
77 }
78
79 #pragma mark - Table view data source
80
81 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
82 return 1;
83 }
84
85 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section {
86 return self.mediaConstraintsArray.count;
87 }
88
89 #pragma mark - Table view delegate
90
91 - (BOOL)sectionIsMediaConstraints:(int)section {
92 return section == 0;
93 }
94
95 - (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath {
96 return [self sectionIsMediaConstraints:indexPath.section];
97 }
98
99 - (nullable NSString *)tableView:(UITableView *)tableView
100 titleForHeaderInSection:(NSInteger)section {
101 if ([self sectionIsMediaConstraints:section]) {
102 return @"Media constraints";
103 }
104 return @"";
105 }
106
107 - (UITableViewCell *)tableView:(UITableView *)tableView
108 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
109 if ([self indexPathIsMediaConstraints:indexPath]) {
110 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath :indexPath];
111 }
112 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
113 reuseIdentifier:@"identifier"];
114 }
115
116 - (nullable NSIndexPath *)tableView:(UITableView *)tableView
117 willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
118 if ([self indexPathIsMediaConstraints:indexPath]) {
119 return [self tableView:tableView willDeselectMediaConstraintsRowAtIndexPath: indexPath];
120 }
121 return indexPath;
122 }
123
124 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
125 if ([self indexPathIsMediaConstraints:indexPath]) {
126 [self tableView:tableView didSelectMediaConstraintsCellAtIndexPath:indexPath ];
127 }
128 }
129
130 #pragma mark - Table view delegate(Media Constraints)
131
132 - (UITableViewCell *)mediaConstraintsTableViewCellForTableView:(UITableView *)ta bleView
133 atIndexPath:(NSIndexPath *)in dexPath {
134 NSString *dequeueIdentifier = @"ARDSettingsMediaConstraintsViewCellIdentifier" ;
135 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier];
136 if (!cell) {
137 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
138 reuseIdentifier:dequeueIdentifier];
139 }
140 cell.textLabel.text = self.mediaConstraintsArray[indexPath.row];
141 return cell;
142 }
143
144 - (void)tableView:(UITableView *)tableView
145 didSelectMediaConstraintsCellAtIndexPath:(NSIndexPath *)indexPath {
146 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
147 cell.accessoryType = UITableViewCellAccessoryCheckmark;
148
149 NSString *mediaConstraintsString = self.mediaConstraintsArray[indexPath.row];
150 [_mediaConstraintsModel storeVideoResoultionConstraint:mediaConstraintsString] ;
151 }
152
153 - (NSIndexPath *)tableView:(UITableView *)tableView
154 willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath {
155 NSIndexPath *oldSelection = [tableView indexPathForSelectedRow];
156 UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection];
157 cell.accessoryType = UITableViewCellAccessoryNone;
158 return indexPath;
159 }
160
161 @end
162 NS_ASSUME_NONNULL_END
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698