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 |
15 @interface ARDSettingsViewController () { | 21 @interface ARDSettingsViewController () { |
16 ARDMediaConstraintsModel *_mediaConstraintsModel; | 22 ARDMediaConstraintsModel *_mediaConstraintsModel; |
17 } | 23 } |
18 | 24 |
19 @end | 25 @end |
20 | 26 |
21 @implementation ARDSettingsViewController | 27 @implementation ARDSettingsViewController |
22 | 28 |
23 - (instancetype)initWithStyle:(UITableViewStyle)style | 29 - (instancetype)initWithStyle:(UITableViewStyle)style |
24 mediaConstraintsModel:(ARDMediaConstraintsModel *)mediaConstraintsModel
{ | 30 mediaConstraintsModel:(ARDMediaConstraintsModel *)mediaConstraintsModel
{ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 78 |
73 #pragma mark - Dismissal of view controller | 79 #pragma mark - Dismissal of view controller |
74 | 80 |
75 - (void)dismissModally:(id)sender { | 81 - (void)dismissModally:(id)sender { |
76 [self dismissViewControllerAnimated:YES completion:nil]; | 82 [self dismissViewControllerAnimated:YES completion:nil]; |
77 } | 83 } |
78 | 84 |
79 #pragma mark - Table view data source | 85 #pragma mark - Table view data source |
80 | 86 |
81 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | 87 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
| 88 return 2; |
| 89 } |
| 90 |
| 91 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
)section { |
| 92 if ([self sectionIsMediaConstraints:section]) { |
| 93 return self.mediaConstraintsArray.count; |
| 94 } |
| 95 |
82 return 1; | 96 return 1; |
83 } | 97 } |
84 | 98 |
85 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
)section { | 99 #pragma mark - Index path helpers |
86 return self.mediaConstraintsArray.count; | 100 |
| 101 - (BOOL)sectionIsMediaConstraints:(int)section { |
| 102 return section == ARDSettingsSectionMediaConstraints; |
87 } | 103 } |
88 | 104 |
89 #pragma mark - Table view delegate | 105 - (BOOL)sectionIsBitrate:(int)section { |
90 | 106 return section == ARDSettingsSectionBitRate; |
91 - (BOOL)sectionIsMediaConstraints:(int)section { | |
92 return section == 0; | |
93 } | 107 } |
94 | 108 |
95 - (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath { | 109 - (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath { |
96 return [self sectionIsMediaConstraints:indexPath.section]; | 110 return [self sectionIsMediaConstraints:indexPath.section]; |
97 } | 111 } |
98 | 112 |
| 113 - (BOOL)indexPathIsBitrate:(NSIndexPath *)indexPath { |
| 114 return [self sectionIsBitrate:indexPath.section]; |
| 115 } |
| 116 |
| 117 #pragma mark - Table view delegate |
| 118 |
99 - (nullable NSString *)tableView:(UITableView *)tableView | 119 - (nullable NSString *)tableView:(UITableView *)tableView |
100 titleForHeaderInSection:(NSInteger)section { | 120 titleForHeaderInSection:(NSInteger)section { |
101 if ([self sectionIsMediaConstraints:section]) { | 121 if ([self sectionIsMediaConstraints:section]) { |
102 return @"Media constraints"; | 122 return @"Media constraints"; |
103 } | 123 } |
| 124 |
| 125 if ([self sectionIsBitrate:section]) { |
| 126 return @"Maximum bitrate"; |
| 127 } |
| 128 |
104 return @""; | 129 return @""; |
105 } | 130 } |
106 | 131 |
107 - (UITableViewCell *)tableView:(UITableView *)tableView | 132 - (UITableViewCell *)tableView:(UITableView *)tableView |
108 cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 133 cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
109 if ([self indexPathIsMediaConstraints:indexPath]) { | 134 if ([self indexPathIsMediaConstraints:indexPath]) { |
110 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath
:indexPath]; | 135 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath
:indexPath]; |
111 } | 136 } |
| 137 |
| 138 if ([self indexPathIsBitrate:indexPath]) { |
| 139 return [self bitrateTableViewCellForTableView:tableView atIndexPath:indexPat
h]; |
| 140 } |
| 141 |
112 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault | 142 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
113 reuseIdentifier:@"identifier"]; | 143 reuseIdentifier:@"identifier"]; |
114 } | 144 } |
115 | 145 |
116 - (nullable NSIndexPath *)tableView:(UITableView *)tableView | 146 - (nullable NSIndexPath *)tableView:(UITableView *)tableView |
117 willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { | 147 willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { |
118 if ([self indexPathIsMediaConstraints:indexPath]) { | 148 if ([self indexPathIsMediaConstraints:indexPath]) { |
119 return [self tableView:tableView willDeselectMediaConstraintsRowAtIndexPath:
indexPath]; | 149 return [self tableView:tableView willDeselectMediaConstraintsRowAtIndexPath:
indexPath]; |
120 } | 150 } |
121 return indexPath; | 151 return indexPath; |
(...skipping 29 matching lines...) Expand all Loading... |
151 } | 181 } |
152 | 182 |
153 - (NSIndexPath *)tableView:(UITableView *)tableView | 183 - (NSIndexPath *)tableView:(UITableView *)tableView |
154 willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath { | 184 willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath { |
155 NSIndexPath *oldSelection = [tableView indexPathForSelectedRow]; | 185 NSIndexPath *oldSelection = [tableView indexPathForSelectedRow]; |
156 UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection]; | 186 UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection]; |
157 cell.accessoryType = UITableViewCellAccessoryNone; | 187 cell.accessoryType = UITableViewCellAccessoryNone; |
158 return indexPath; | 188 return indexPath; |
159 } | 189 } |
160 | 190 |
| 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 = UIKeyboardTypeNumberPad; |
| 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 |
161 @end | 230 @end |
162 NS_ASSUME_NONNULL_END | 231 NS_ASSUME_NONNULL_END |
OLD | NEW |