RecordViewController.mm 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // RecordViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/7.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "RecordViewController.h"
  9. #import "ItemTableviewCell.h"
  10. #import "ItemViewController.h"
  11. #import "RecordConfig.h"
  12. #import "Header.h"
  13. @interface RecordViewController () <UITableViewDelegate,UITableViewDataSource,RecordConfigDelegate>
  14. {
  15. RecordConfig *config;
  16. UITableView *recordTableView;
  17. NSMutableArray *recordTitleArray;
  18. }
  19. @end
  20. @implementation RecordViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. //初始化界面
  24. [self initDataSource];
  25. [self configSubView];
  26. //请求配置
  27. [self getRecordConfig];
  28. }
  29. - (void)viewWillDisappear:(BOOL)animated{
  30. //有加载状态、则取消加载
  31. if ([SVProgressHUD isVisible]){
  32. [SVProgressHUD dismiss];
  33. }
  34. }
  35. #pragma mark - 获取录像配置
  36. - (void)getRecordConfig {
  37. [SVProgressHUD showWithStatus:TS("")];
  38. if (config == nil) {
  39. config = [[RecordConfig alloc] init];
  40. config.delegate = self;
  41. }
  42. //调用获取设备录像配置的接口
  43. [config getRecordConfig];
  44. }
  45. #pragma mark 获取录像配置代理回调
  46. - (void)recordSuportStatu:(NSInteger)statu {
  47. //statu = 0:只支持主码流。statu=1:只支持辅码流。statu=2:主辅码流都支持
  48. if (statu == 0) {//删掉辅码流
  49. [recordTitleArray removeObjectsInArray:self.extraArray];
  50. }else if (statu == 1){
  51. [recordTitleArray removeObjectsInArray:self.mainArray];
  52. }
  53. }
  54. - (void)getRecordConfigResult:(NSInteger)result {
  55. if (result >0) {
  56. //成功,刷新界面数据
  57. [self.recordTableView reloadData];
  58. [SVProgressHUD dismiss];
  59. }else{
  60. [MessageUI ShowErrorInt:(int)result];
  61. }
  62. }
  63. #pragma mark - 保存录像配置
  64. -(void)saveConfig{
  65. [SVProgressHUD show];
  66. [config setRecordConfig];
  67. }
  68. #pragma mark 保存录像配置代理回调
  69. - (void)setRecordConfigResult:(NSInteger)result {
  70. if (result >0) {
  71. //成功
  72. [SVProgressHUD dismissWithSuccess:TS("Success")];
  73. }else{
  74. [MessageUI ShowErrorInt:(int)result];
  75. }
  76. }
  77. #pragma mark - tableView代理方法
  78. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  79. return recordTitleArray.count;
  80. }
  81. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  82. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  83. if (!cell) {
  84. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  85. }
  86. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  87. NSString *title = [recordTitleArray objectAtIndex:indexPath.row];
  88. cell.textLabel.text = title;
  89. if ([config checkRecord] == NO) {
  90. //当前配置参数无效,不能刷新
  91. return cell;
  92. }
  93. if ([title isEqualToString:TS("main_record")]) {
  94. cell.Labeltext.text = [config getMainRecordMode];
  95. }else if ([title isEqualToString:TS("main_pre_record")]) {
  96. cell.Labeltext.text =[config getMainPreRecord];
  97. }else if ([title isEqualToString:TS("main_record_length")]) {
  98. cell.Labeltext.text = [config getMainPacketLength];
  99. }else if ([title isEqualToString:TS("extra_record")]) {
  100. cell.Labeltext.text = [config getExtraRecordMode];
  101. }else if ([title isEqualToString:TS("extra_pre_record")]) {
  102. cell.Labeltext.text = [config getExtraPreRecord];
  103. }else if ([title isEqualToString:TS("extra_record_length")]) {
  104. cell.Labeltext.text = [config getExtraPacketLength];
  105. }
  106. return cell;
  107. }
  108. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  109. if ([config checkRecord] == NO) {
  110. return; //录像配置能力级数据异常,无法进行配置
  111. }
  112. NSString *titleStr = recordTitleArray[indexPath.row];
  113. //初始化各个配置的item单元格
  114. ItemViewController *itemVC = [[ItemViewController alloc] init];
  115. [itemVC setTitle:titleStr];
  116. __weak typeof(self) weakSelf = self;
  117. itemVC.itemSelectStringBlock = ^(NSString *encodeString) {
  118. //itemVC的单元格点击回调,设置各种属性
  119. ItemTableviewCell *cell = [weakSelf.recordTableView cellForRowAtIndexPath:indexPath];
  120. cell.Labeltext.text = encodeString;
  121. if ([cell.textLabel.text isEqualToString:TS("main_record")]) {
  122. [config setMainRecordMode:encodeString];
  123. }else if ([cell.textLabel.text isEqualToString:TS("main_pre_record")]){
  124. [config setMainPreRecord:encodeString];
  125. }else if ([cell.textLabel.text isEqualToString:TS("main_record_length")]){
  126. [config setMainPacketLength:encodeString];
  127. }else if ([cell.textLabel.text isEqualToString:TS("extra_record")]){
  128. [config setExtraRecordMode: encodeString];
  129. }else if ([cell.textLabel.text isEqualToString:TS("extra_pre_record")]){
  130. [config setExtraPreRecord:encodeString];
  131. }else if ([cell.textLabel.text isEqualToString:TS("extra_record_length")]){
  132. [config setExtraPacketLength:encodeString];
  133. }else{
  134. return;
  135. }
  136. };
  137. //点击单元格之后进行分别赋值
  138. if ([titleStr isEqualToString:TS("main_record")]) {
  139. NSMutableArray *array = [[config getMainRecordModeArray] mutableCopy];
  140. [itemVC setValueArray:array];
  141. }else if ([titleStr isEqualToString:TS("main_pre_record")]){
  142. NSMutableArray *array = [[config getMainPrerecordArray] mutableCopy];
  143. [itemVC setValueArray:array];
  144. }else if ([titleStr isEqualToString:TS("main_record_length")]){
  145. NSMutableArray *array = [[config getMainPacketLengthArray] mutableCopy];
  146. [itemVC setValueArray:array];
  147. }else if ([titleStr isEqualToString:TS("extra_record")]){
  148. NSMutableArray *array = [[config getExtraRecordModeArray] mutableCopy];
  149. [itemVC setValueArray:array];
  150. }else if ([titleStr isEqualToString:TS("extra_pre_record")]){
  151. NSMutableArray *array = [[config getMainPrerecordArray] mutableCopy];
  152. [itemVC setValueArray:array];
  153. }else if ([titleStr isEqualToString:TS("extra_record_length")]){
  154. NSMutableArray *array = [[config getExtraPacketLengthArray] mutableCopy];
  155. [itemVC setValueArray:array];
  156. }else if ([titleStr isEqualToString:TS("Custom_example")]){
  157. [config setTuesdayNightAlarmRecord];//设置周二晚上报警录像打开,保存后生效
  158. return;
  159. }else{
  160. return;
  161. }
  162. //如果赋值成功,跳转到下一级界面
  163. [self.navigationController pushViewController:itemVC animated:YES];
  164. }
  165. #pragma mark - 界面和数据初始化
  166. - (void)configSubView {
  167. UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveConfig)];
  168. self.navigationItem.rightBarButtonItem = rightButton;
  169. [self.view addSubview:self.recordTableView];
  170. }
  171. - (UITableView *)recordTableView {
  172. if (!recordTableView) {
  173. recordTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  174. recordTableView.delegate = self;
  175. recordTableView.dataSource = self;
  176. [recordTableView registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  177. }
  178. return recordTableView;
  179. }
  180. - (void)initDataSource {
  181. recordTitleArray= [[NSMutableArray alloc] initWithArray:self.mainArray];
  182. [recordTitleArray addObjectsFromArray:self.extraArray];
  183. [recordTitleArray addObjectsFromArray:self.expendArray];
  184. }
  185. -(NSArray*)mainArray {
  186. return @[TS("main_record"),TS("main_pre_record"),TS("main_record_length")];
  187. }
  188. -(NSArray*)extraArray {
  189. return @[TS("extra_record"),TS("extra_pre_record"),TS("extra_record_length")];
  190. }
  191. -(NSArray*)expendArray {
  192. return @[TS("Custom_example")];
  193. }
  194. - (void)didReceiveMemoryWarning {
  195. [super didReceiveMemoryWarning];
  196. }
  197. @end