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 "ARDMediaConstraintsModel.h" | 12 #import "ARDMediaConstraintsModel.h" |
13 | 13 |
14 NS_ASSUME_NONNULL_BEGIN | 14 NS_ASSUME_NONNULL_BEGIN |
15 | |
16 typedef NS_ENUM(int, ARDSettingsSections) { | |
17 ARDSettingsSectionMediaConstraints = 0, | |
18 ARDSettingsSectionBitRate | |
19 }; | |
20 | |
21 @interface ARDSettingsViewController () { | 15 @interface ARDSettingsViewController () { |
22 ARDMediaConstraintsModel *_mediaConstraintsModel; | 16 ARDMediaConstraintsModel *_mediaConstraintsModel; |
23 } | 17 } |
24 | 18 |
25 @end | 19 @end |
26 | 20 |
27 @implementation ARDSettingsViewController | 21 @implementation ARDSettingsViewController |
28 | 22 |
29 - (instancetype)initWithStyle:(UITableViewStyle)style | 23 - (instancetype)initWithStyle:(UITableViewStyle)style |
30 mediaConstraintsModel:(ARDMediaConstraintsModel *)mediaConstraintsModel
{ | 24 mediaConstraintsModel:(ARDMediaConstraintsModel *)mediaConstraintsModel
{ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 72 |
79 #pragma mark - Dismissal of view controller | 73 #pragma mark - Dismissal of view controller |
80 | 74 |
81 - (void)dismissModally:(id)sender { | 75 - (void)dismissModally:(id)sender { |
82 [self dismissViewControllerAnimated:YES completion:nil]; | 76 [self dismissViewControllerAnimated:YES completion:nil]; |
83 } | 77 } |
84 | 78 |
85 #pragma mark - Table view data source | 79 #pragma mark - Table view data source |
86 | 80 |
87 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | 81 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
88 return 2; | 82 return 1; |
89 } | 83 } |
90 | 84 |
91 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
)section { | 85 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
)section { |
92 if ([self sectionIsMediaConstraints:section]) { | 86 return self.mediaConstraintsArray.count; |
93 return self.mediaConstraintsArray.count; | |
94 } | |
95 | |
96 return 1; | |
97 } | 87 } |
98 | 88 |
99 #pragma mark - Index path helpers | 89 #pragma mark - Table view delegate |
100 | 90 |
101 - (BOOL)sectionIsMediaConstraints:(int)section { | 91 - (BOOL)sectionIsMediaConstraints:(int)section { |
102 return section == ARDSettingsSectionMediaConstraints; | 92 return section == 0; |
103 } | |
104 | |
105 - (BOOL)sectionIsBitrate:(int)section { | |
106 return section == ARDSettingsSectionBitRate; | |
107 } | 93 } |
108 | 94 |
109 - (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath { | 95 - (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath { |
110 return [self sectionIsMediaConstraints:indexPath.section]; | 96 return [self sectionIsMediaConstraints:indexPath.section]; |
111 } | 97 } |
112 | 98 |
113 - (BOOL)indexPathIsBitrate:(NSIndexPath *)indexPath { | |
114 return [self sectionIsBitrate:indexPath.section]; | |
115 } | |
116 | |
117 #pragma mark - Table view delegate | |
118 | |
119 - (nullable NSString *)tableView:(UITableView *)tableView | 99 - (nullable NSString *)tableView:(UITableView *)tableView |
120 titleForHeaderInSection:(NSInteger)section { | 100 titleForHeaderInSection:(NSInteger)section { |
121 if ([self sectionIsMediaConstraints:section]) { | 101 if ([self sectionIsMediaConstraints:section]) { |
122 return @"Media constraints"; | 102 return @"Media constraints"; |
123 } | 103 } |
124 | |
125 if ([self sectionIsBitrate:section]) { | |
126 return @"Maximum bitrate"; | |
127 } | |
128 | |
129 return @""; | 104 return @""; |
130 } | 105 } |
131 | 106 |
132 - (UITableViewCell *)tableView:(UITableView *)tableView | 107 - (UITableViewCell *)tableView:(UITableView *)tableView |
133 cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 108 cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
134 if ([self indexPathIsMediaConstraints:indexPath]) { | 109 if ([self indexPathIsMediaConstraints:indexPath]) { |
135 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath
:indexPath]; | 110 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath
:indexPath]; |
136 } | 111 } |
137 | |
138 if ([self indexPathIsBitrate:indexPath]) { | |
139 return [self bitrateTableViewCellForTableView:tableView atIndexPath:indexPat
h]; | |
140 } | |
141 | |
142 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault | 112 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
143 reuseIdentifier:@"identifier"]; | 113 reuseIdentifier:@"identifier"]; |
144 } | 114 } |
145 | 115 |
146 - (nullable NSIndexPath *)tableView:(UITableView *)tableView | 116 - (nullable NSIndexPath *)tableView:(UITableView *)tableView |
147 willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { | 117 willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { |
148 if ([self indexPathIsMediaConstraints:indexPath]) { | 118 if ([self indexPathIsMediaConstraints:indexPath]) { |
149 return [self tableView:tableView willDeselectMediaConstraintsRowAtIndexPath:
indexPath]; | 119 return [self tableView:tableView willDeselectMediaConstraintsRowAtIndexPath:
indexPath]; |
150 } | 120 } |
151 return indexPath; | 121 return indexPath; |
(...skipping 29 matching lines...) Expand all Loading... |
181 } | 151 } |
182 | 152 |
183 - (NSIndexPath *)tableView:(UITableView *)tableView | 153 - (NSIndexPath *)tableView:(UITableView *)tableView |
184 willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath { | 154 willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath { |
185 NSIndexPath *oldSelection = [tableView indexPathForSelectedRow]; | 155 NSIndexPath *oldSelection = [tableView indexPathForSelectedRow]; |
186 UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection]; | 156 UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection]; |
187 cell.accessoryType = UITableViewCellAccessoryNone; | 157 cell.accessoryType = UITableViewCellAccessoryNone; |
188 return indexPath; | 158 return indexPath; |
189 } | 159 } |
190 | 160 |
191 #pragma mark - Table view delegate(Bitrate) | |
192 | |
193 - (UITableViewCell *)bitrateTableViewCellForTableView:(UITableView *)tableView | |
194 atIndexPath:(NSIndexPath *)indexPath { | |
195 NSString *dequeueIdentifier = @"ARDSettingsBitrateCellIdentifier"; | |
196 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId
entifier]; | |
197 if (!cell) { | |
198 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault | |
199 reuseIdentifier:dequeueIdentifier]; | |
200 | |
201 UITextField *textField = [[UITextField alloc] | |
202 initWithFrame:CGRectMake(10, 0, cell.bounds.size.width - 20, cell.bounds
.size.height)]; | |
203 textField.placeholder = @"Enter max bit rate (kbps)"; | |
204 textField.keyboardType = UIKeyboardTypeASCIICapableNumberPad; | |
205 | |
206 // Numerical keyboards have no return button, we need to add one manually. | |
207 UIToolbar *numberToolbar = | |
208 [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.
width, 50)]; | |
209 numberToolbar.items = @[ | |
210 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem
FlexibleSpace | |
211 target:nil | |
212 action:nil], | |
213 [[UIBarButtonItem alloc] initWithTitle:@"Apply" | |
214 style:UIBarButtonItemStyleDone | |
215 target:self | |
216 action:@selector(numberTextFieldDidEndEdit
ing:)] | |
217 ]; | |
218 [numberToolbar sizeToFit]; | |
219 | |
220 textField.inputAccessoryView = numberToolbar; | |
221 [cell addSubview:textField]; | |
222 } | |
223 return cell; | |
224 } | |
225 | |
226 - (void)numberTextFieldDidEndEditing:(id)sender { | |
227 [self.view endEditing:YES]; | |
228 } | |
229 | |
230 @end | 161 @end |
231 NS_ASSUME_NONNULL_END | 162 NS_ASSUME_NONNULL_END |
OLD | NEW |