OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "ARDSettingsViewController.h" | 11 #import "ARDSettingsViewController.h" |
12 #import "ARDSettingsModel.h" | 12 #import "ARDSettingsModel.h" |
13 | 13 |
14 NS_ASSUME_NONNULL_BEGIN | 14 NS_ASSUME_NONNULL_BEGIN |
15 | 15 |
16 typedef NS_ENUM(int, ARDSettingsSections) { | 16 typedef NS_ENUM(int, ARDSettingsSections) { |
17 ARDSettingsSectionMediaConstraints = 0, | 17 ARDSettingsSectionMediaConstraints = 0, |
18 ARDSettingsSectionBitRate | 18 ARDSettingsSectionVideoCodec, |
19 ARDSettingsSectionBitRate, | |
19 }; | 20 }; |
20 | 21 |
21 @interface ARDSettingsViewController () <UITextFieldDelegate> { | 22 @interface ARDSettingsViewController () <UITextFieldDelegate> { |
22 ARDSettingsModel *_settingsModel; | 23 ARDSettingsModel *_settingsModel; |
23 } | 24 } |
24 | 25 |
25 @end | 26 @end |
26 | 27 |
27 @implementation ARDSettingsViewController | 28 @implementation ARDSettingsViewController |
28 | 29 |
29 - (instancetype)initWithStyle:(UITableViewStyle)style | 30 - (instancetype)initWithStyle:(UITableViewStyle)style |
30 settingsModel:(ARDSettingsModel *)settingsModel { | 31 settingsModel:(ARDSettingsModel *)settingsModel { |
31 self = [super initWithStyle:style]; | 32 self = [super initWithStyle:style]; |
32 if (self) { | 33 if (self) { |
33 _settingsModel = settingsModel; | 34 _settingsModel = settingsModel; |
34 } | 35 } |
35 return self; | 36 return self; |
36 } | 37 } |
37 | 38 |
38 #pragma mark - View lifecycle | 39 #pragma mark - View lifecycle |
39 | 40 |
40 - (void)viewDidLoad { | 41 - (void)viewDidLoad { |
41 [super viewDidLoad]; | 42 [super viewDidLoad]; |
42 self.title = @"Settings"; | 43 self.title = @"Settings"; |
43 [self addDoneBarButton]; | 44 [self addDoneBarButton]; |
44 } | 45 } |
45 | 46 |
47 - (void)viewWillAppear:(BOOL)animated { | |
48 [super viewWillAppear:animated]; | |
49 [self decorateCurrentlyStoredOrDefaultMediaConstraints]; | |
50 [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
| |
51 } | |
52 | |
46 - (void)viewDidAppear:(BOOL)animated { | 53 - (void)viewDidAppear:(BOOL)animated { |
47 [super viewDidAppear:animated]; | 54 [super viewDidAppear:animated]; |
48 [self selectCurrentlyStoredOrDefaultMediaConstraints]; | |
49 } | 55 } |
50 | 56 |
51 #pragma mark - Data source | 57 #pragma mark - Data source |
52 | 58 |
53 - (NSArray<NSString *> *)mediaConstraintsArray { | 59 - (NSArray<NSString *> *)mediaConstraintsArray { |
54 return _settingsModel.availableVideoResoultionsMediaConstraints; | 60 return _settingsModel.availableVideoResoultionsMediaConstraints; |
55 } | 61 } |
56 | 62 |
63 - (NSArray<NSString *> *)videoCodecArray { | |
64 return _settingsModel.availableVideoCodecs; | |
65 } | |
66 | |
57 #pragma mark - | 67 #pragma mark - |
58 | 68 |
59 - (void)addDoneBarButton { | 69 - (void)addDoneBarButton { |
60 UIBarButtonItem *barItem = | 70 UIBarButtonItem *barItem = |
61 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem Done | 71 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem Done |
62 target:self | 72 target:self |
63 action:@selector(dismissModa lly:)]; | 73 action:@selector(dismissModa lly:)]; |
64 self.navigationItem.leftBarButtonItem = barItem; | 74 self.navigationItem.leftBarButtonItem = barItem; |
65 } | 75 } |
66 | 76 |
67 - (void)selectCurrentlyStoredOrDefaultMediaConstraints { | 77 - (void)decorateCurrentlyStoredOrDefaultMediaConstraints { |
68 NSString *currentSelection = [_settingsModel currentVideoResoultionConstraintF romStore]; | 78 NSString *currentSelection = [_settingsModel currentVideoResoultionConstraintF romStore]; |
69 | 79 |
70 NSUInteger indexOfSelection = [[self mediaConstraintsArray] indexOfObject:curr entSelection]; | 80 NSUInteger indexOfSelection = [[self mediaConstraintsArray] indexOfObject:curr entSelection]; |
71 NSIndexPath *pathToBeSelected = [NSIndexPath indexPathForRow:indexOfSelection inSection:0]; | 81 NSIndexPath *pathToBeDecorated = [NSIndexPath indexPathForRow:indexOfSelection |
72 [self.tableView selectRowAtIndexPath:pathToBeSelected | 82 inSection:ARDSettingsSecti onMediaConstraints]; |
73 animated:NO | 83 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:pathToBeDecorate d]; |
74 scrollPosition:UITableViewScrollPositionNone]; | 84 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
75 // Manully invoke the delegate method because the previous invocation will not . | 85 } |
76 [self tableView:self.tableView didSelectRowAtIndexPath:pathToBeSelected]; | 86 |
87 - (void)decorateCurrentlyStoredOrDefaultVideoCodec { | |
88 NSString *currentSelection = [_settingsModel currentVideoCodecSettingFromStore ]; | |
89 | |
90 NSUInteger indexOfSelection = [[self videoCodecArray] indexOfObject:currentSel ection]; | |
91 NSIndexPath *pathToBeDecorated = [NSIndexPath indexPathForRow:indexOfSelection | |
92 inSection:ARDSettingsSecti onVideoCodec]; | |
93 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:pathToBeDecorate d]; | |
94 cell.accessoryType = UITableViewCellAccessoryCheckmark; | |
77 } | 95 } |
78 | 96 |
79 #pragma mark - Dismissal of view controller | 97 #pragma mark - Dismissal of view controller |
80 | 98 |
81 - (void)dismissModally:(id)sender { | 99 - (void)dismissModally:(id)sender { |
82 [self dismissViewControllerAnimated:YES completion:nil]; | 100 [self dismissViewControllerAnimated:YES completion:nil]; |
83 } | 101 } |
84 | 102 |
85 #pragma mark - Table view data source | 103 #pragma mark - Table view data source |
86 | 104 |
87 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | 105 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
88 return 2; | 106 return 3; |
89 } | 107 } |
90 | 108 |
91 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section { | 109 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section { |
92 if ([self sectionIsMediaConstraints:section]) { | 110 if ([self sectionIsMediaConstraints:section]) { |
93 return self.mediaConstraintsArray.count; | 111 return self.mediaConstraintsArray.count; |
94 } | 112 } |
113 if ([self sectionIsVideoCodec:section]) { | |
114 return self.videoCodecArray.count; | |
115 } | |
kthelgason
2017/03/09 13:39:43
I'd prefer a switch-case on section here.
sakal
2017/03/10 10:25:28
Done.
| |
95 | 116 |
96 return 1; | 117 return 1; |
97 } | 118 } |
98 | 119 |
99 #pragma mark - Index path helpers | 120 #pragma mark - Index path helpers |
100 | 121 |
101 - (BOOL)sectionIsMediaConstraints:(int)section { | 122 - (BOOL)sectionIsMediaConstraints:(int)section { |
102 return section == ARDSettingsSectionMediaConstraints; | 123 return section == ARDSettingsSectionMediaConstraints; |
103 } | 124 } |
104 | 125 |
126 - (BOOL)sectionIsVideoCodec:(int)section { | |
127 return section == ARDSettingsSectionVideoCodec; | |
128 } | |
129 | |
105 - (BOOL)sectionIsBitrate:(int)section { | 130 - (BOOL)sectionIsBitrate:(int)section { |
106 return section == ARDSettingsSectionBitRate; | 131 return section == ARDSettingsSectionBitRate; |
107 } | 132 } |
108 | 133 |
109 - (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath { | 134 - (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath { |
110 return [self sectionIsMediaConstraints:indexPath.section]; | 135 return [self sectionIsMediaConstraints:indexPath.section]; |
111 } | 136 } |
112 | 137 |
138 - (BOOL)indexPathIsVideoCodec:(NSIndexPath *)indexPath { | |
139 return [self sectionIsVideoCodec:indexPath.section]; | |
140 } | |
141 | |
113 - (BOOL)indexPathIsBitrate:(NSIndexPath *)indexPath { | 142 - (BOOL)indexPathIsBitrate:(NSIndexPath *)indexPath { |
114 return [self sectionIsBitrate:indexPath.section]; | 143 return [self sectionIsBitrate:indexPath.section]; |
115 } | 144 } |
116 | 145 |
146 #pragma mark - Table view delegate helpers | |
147 | |
148 - (void)removeAllAccessories:(UITableView *)tableView | |
149 inSection:(int)section | |
150 { | |
151 for (int i = 0; i < [tableView numberOfRowsInSection:section]; i++) { | |
152 NSIndexPath *rowPath = [NSIndexPath indexPathForRow:i inSection:section]; | |
153 UITableViewCell *cell = [tableView cellForRowAtIndexPath:rowPath]; | |
154 cell.accessoryType = UITableViewCellAccessoryNone; | |
155 } | |
156 } | |
157 | |
117 #pragma mark - Table view delegate | 158 #pragma mark - Table view delegate |
118 | 159 |
119 - (nullable NSString *)tableView:(UITableView *)tableView | 160 - (nullable NSString *)tableView:(UITableView *)tableView |
120 titleForHeaderInSection:(NSInteger)section { | 161 titleForHeaderInSection:(NSInteger)section { |
121 if ([self sectionIsMediaConstraints:section]) { | 162 if ([self sectionIsMediaConstraints:section]) { |
122 return @"Media constraints"; | 163 return @"Media constraints"; |
123 } | 164 } |
124 | 165 |
125 if ([self sectionIsBitrate:section]) { | 166 if ([self sectionIsBitrate:section]) { |
126 return @"Maximum bitrate"; | 167 return @"Maximum bitrate"; |
127 } | 168 } |
128 | 169 |
170 if ([self sectionIsVideoCodec:section]) { | |
171 return @"Video codec"; | |
172 } | |
173 | |
129 return @""; | 174 return @""; |
130 } | 175 } |
131 | 176 |
132 - (UITableViewCell *)tableView:(UITableView *)tableView | 177 - (UITableViewCell *)tableView:(UITableView *)tableView |
133 cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 178 cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
134 if ([self indexPathIsMediaConstraints:indexPath]) { | 179 if ([self indexPathIsMediaConstraints:indexPath]) { |
kthelgason
2017/03/09 13:39:43
I'd also prefer a switch-case here, but up to you.
sakal
2017/03/10 10:25:28
Done.
| |
135 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath :indexPath]; | 180 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath :indexPath]; |
136 } | 181 } |
137 | 182 |
183 if ([self indexPathIsVideoCodec:indexPath]) { | |
184 return [self videoCodecTableViewCellForTableView:tableView atIndexPath:index Path]; | |
185 } | |
186 | |
138 if ([self indexPathIsBitrate:indexPath]) { | 187 if ([self indexPathIsBitrate:indexPath]) { |
139 return [self bitrateTableViewCellForTableView:tableView atIndexPath:indexPat h]; | 188 return [self bitrateTableViewCellForTableView:tableView atIndexPath:indexPat h]; |
140 } | 189 } |
141 | 190 |
142 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault | 191 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
143 reuseIdentifier:@"identifier"]; | 192 reuseIdentifier:@"identifier"]; |
144 } | 193 } |
145 | 194 |
146 - (nullable NSIndexPath *)tableView:(UITableView *)tableView | |
147 willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { | |
148 if ([self indexPathIsMediaConstraints:indexPath]) { | |
149 return [self tableView:tableView willDeselectMediaConstraintsRowAtIndexPath: indexPath]; | |
150 } | |
151 return indexPath; | |
152 } | |
153 | |
154 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | 195 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
155 if ([self indexPathIsMediaConstraints:indexPath]) { | 196 if ([self indexPathIsMediaConstraints:indexPath]) { |
156 [self tableView:tableView didSelectMediaConstraintsCellAtIndexPath:indexPath ]; | 197 [self tableView:tableView didSelectMediaConstraintsCellAtIndexPath:indexPath ]; |
157 } | 198 } |
199 if ([self indexPathIsVideoCodec:indexPath]) { | |
200 [self tableView:tableView didSelectVideoCodecCellAtIndexPath:indexPath]; | |
201 } | |
158 } | 202 } |
159 | 203 |
160 #pragma mark - Table view delegate(Media Constraints) | 204 #pragma mark - Table view delegate(Media Constraints) |
161 | 205 |
162 - (UITableViewCell *)mediaConstraintsTableViewCellForTableView:(UITableView *)ta bleView | 206 - (UITableViewCell *)mediaConstraintsTableViewCellForTableView:(UITableView *)ta bleView |
163 atIndexPath:(NSIndexPath *)in dexPath { | 207 atIndexPath:(NSIndexPath *)in dexPath { |
164 NSString *dequeueIdentifier = @"ARDSettingsMediaConstraintsViewCellIdentifier" ; | 208 NSString *dequeueIdentifier = @"ARDSettingsMediaConstraintsViewCellIdentifier" ; |
165 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier]; | 209 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier]; |
166 if (!cell) { | 210 if (!cell) { |
167 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault | 211 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
168 reuseIdentifier:dequeueIdentifier]; | 212 reuseIdentifier:dequeueIdentifier]; |
169 } | 213 } |
170 cell.textLabel.text = self.mediaConstraintsArray[indexPath.row]; | 214 cell.textLabel.text = self.mediaConstraintsArray[indexPath.row]; |
171 return cell; | 215 return cell; |
172 } | 216 } |
173 | 217 |
174 - (void)tableView:(UITableView *)tableView | 218 - (void)tableView:(UITableView *)tableView |
175 didSelectMediaConstraintsCellAtIndexPath:(NSIndexPath *)indexPath { | 219 didSelectMediaConstraintsCellAtIndexPath:(NSIndexPath *)indexPath { |
220 [self removeAllAccessories:tableView inSection:ARDSettingsSectionMediaConstrai nts]; | |
176 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; | 221 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; |
177 cell.accessoryType = UITableViewCellAccessoryCheckmark; | 222 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
178 | 223 |
179 NSString *mediaConstraintsString = self.mediaConstraintsArray[indexPath.row]; | 224 NSString *mediaConstraintsString = self.mediaConstraintsArray[indexPath.row]; |
180 [_settingsModel storeVideoResoultionConstraint:mediaConstraintsString]; | 225 [_settingsModel storeVideoResoultionConstraint:mediaConstraintsString]; |
226 | |
227 [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
181 } | 228 } |
182 | 229 |
183 - (NSIndexPath *)tableView:(UITableView *)tableView | 230 #pragma mark - Table view delegate(Video Codec) |
184 willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath { | 231 |
185 NSIndexPath *oldSelection = [tableView indexPathForSelectedRow]; | 232 - (UITableViewCell *)videoCodecTableViewCellForTableView:(UITableView *)tableVie w |
186 UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection]; | 233 atIndexPath:(NSIndexPath *)indexPat h { |
187 cell.accessoryType = UITableViewCellAccessoryNone; | 234 NSString *dequeueIdentifier = @"ARDSettingsVideoCodecCellIdentifier"; |
188 return indexPath; | 235 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier]; |
236 if (!cell) { | |
237 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault | |
238 reuseIdentifier:dequeueIdentifier]; | |
239 } | |
240 cell.textLabel.text = self.videoCodecArray[indexPath.row]; | |
241 | |
242 return cell; | |
243 } | |
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.
| |
244 | |
245 - (void)tableView:(UITableView *)tableView | |
246 didSelectVideoCodecCellAtIndexPath:(NSIndexPath *)indexPath { | |
247 [self removeAllAccessories:tableView inSection:ARDSettingsSectionVideoCodec]; | |
248 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; | |
249 cell.accessoryType = UITableViewCellAccessoryCheckmark; | |
250 | |
251 NSString *videoCodec = self.videoCodecArray[indexPath.row]; | |
252 [_settingsModel storeVideoCodecSetting:videoCodec]; | |
253 | |
254 [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
189 } | 255 } |
190 | 256 |
191 #pragma mark - Table view delegate(Bitrate) | 257 #pragma mark - Table view delegate(Bitrate) |
192 | 258 |
193 - (UITableViewCell *)bitrateTableViewCellForTableView:(UITableView *)tableView | 259 - (UITableViewCell *)bitrateTableViewCellForTableView:(UITableView *)tableView |
194 atIndexPath:(NSIndexPath *)indexPath { | 260 atIndexPath:(NSIndexPath *)indexPath { |
195 NSString *dequeueIdentifier = @"ARDSettingsBitrateCellIdentifier"; | 261 NSString *dequeueIdentifier = @"ARDSettingsBitrateCellIdentifier"; |
196 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier]; | 262 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier]; |
197 if (!cell) { | 263 if (!cell) { |
198 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault | 264 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 | 301 |
236 if (textField.text.length != 0) { | 302 if (textField.text.length != 0) { |
237 bitrateNumber = [NSNumber numberWithInteger:textField.text.intValue]; | 303 bitrateNumber = [NSNumber numberWithInteger:textField.text.intValue]; |
238 } | 304 } |
239 | 305 |
240 [_settingsModel storeMaxBitrateSetting:bitrateNumber]; | 306 [_settingsModel storeMaxBitrateSetting:bitrateNumber]; |
241 } | 307 } |
242 | 308 |
243 @end | 309 @end |
244 NS_ASSUME_NONNULL_END | 310 NS_ASSUME_NONNULL_END |
OLD | NEW |