AnalyzerViewController.mm 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // AnalyzerViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/12/22.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "AnalyzerViewController.h"
  9. #import "ItemViewController.h"
  10. #import "ItemTableviewCell.h"
  11. #import "AnalyzeConfig.h"
  12. #import "Header.h"
  13. @interface AnalyzerViewController () <UITableViewDelegate,UITableViewDataSource,AnalyzeConfigDelegate>
  14. {
  15. AnalyzeConfig *config; //智能分析
  16. UITableView *analyzerTableView;
  17. NSMutableArray *analyzerTitleArray;
  18. }
  19. @end
  20. @implementation AnalyzerViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. //初始化tableview数据
  24. [self initDataSource];
  25. [self configSubView];
  26. // 获取智能分析配置
  27. [self getVideoRotainConfig];
  28. }
  29. - (void)viewWillDisappear:(BOOL)animated{
  30. //有加载状态、则取消加载
  31. if ([SVProgressHUD isVisible]){
  32. [SVProgressHUD dismiss];
  33. }
  34. }
  35. #pragma mark - 获取智能分析配置
  36. - (void)getVideoRotainConfig {
  37. [SVProgressHUD showWithStatus:TS("")];
  38. if (config == nil) {
  39. config = [[AnalyzeConfig alloc] init];
  40. config.delegate = self;
  41. }
  42. //调用获取智能分析等参数的接口
  43. [config getAnalyzeConfig];
  44. }
  45. #pragma mark 获取智能分析代理回调
  46. - (void)getAnalyzeConfigResult:(NSInteger)result {
  47. if (result >0) {
  48. //成功,刷新界面数据
  49. [self.analyzerTableView reloadData];
  50. [SVProgressHUD dismiss];
  51. }else{
  52. [MessageUI ShowErrorInt:(int)result];
  53. }
  54. }
  55. #pragma mark - 保存智能分析配置 (
  56. -(void)saveConfig{
  57. [SVProgressHUD show];
  58. [config setAnalyzeConfig];
  59. }
  60. #pragma mark 保存智能分析代理回调
  61. - (void)setAnalyzeConfigResult:(NSInteger)result {
  62. if (result >0) {
  63. //成功
  64. [SVProgressHUD dismissWithSuccess:TS("Success")];
  65. }else{
  66. [MessageUI ShowErrorInt:(int)result];
  67. }
  68. }
  69. #pragma mark - tableView代理方法
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  71. return analyzerTitleArray.count;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  74. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  75. if (!cell) {
  76. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  77. }
  78. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  79. NSString *title = [analyzerTitleArray objectAtIndex:indexPath.row];
  80. cell.textLabel.text = title;
  81. if ([config checkParam] == NO) {
  82. //当前配置参数无效,不能刷新
  83. return cell;
  84. }
  85. AnalyzeDataSource *dataSource = [config getAnalyzeDataSource];
  86. if ([title isEqualToString:TS("Analyzer_Enable")]) {
  87. cell.Labeltext.text = [dataSource getEnableString:dataSource.AnalyzeEnable];
  88. }
  89. if ([title isEqualToString:TS("Analyzer_Type")]) {
  90. cell.Labeltext.text = [dataSource getAnalyzeTypeString:dataSource.ModuleType];
  91. }
  92. if ([title isEqualToString:TS("Analyzer_Level")]) {
  93. cell.Labeltext.text = [NSString stringWithFormat:@"%d",dataSource.PeaLevel];
  94. }
  95. if ([title isEqualToString:TS("Analyzer_Rule")]) {
  96. cell.Labeltext.text = [dataSource getEnableString:dataSource.PeaShowRule];
  97. }
  98. if ([title isEqualToString:TS("Analyzer_Trace")]) {
  99. cell.Labeltext.text = [dataSource getEnableString:dataSource.PeaShowTrace];
  100. }
  101. return cell;
  102. }
  103. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  104. if ([config checkParam] == NO) {
  105. return; //
  106. }
  107. NSString *titleStr = analyzerTitleArray[indexPath.row];
  108. //初始化各个配置的item单元格
  109. ItemViewController *itemVC = [[ItemViewController alloc] init];
  110. [itemVC setTitle:titleStr];
  111. __weak typeof(self) weakSelf = self;
  112. itemVC.itemSelectStringBlock = ^(NSString *encodeString) {
  113. //itemVC的单元格点击回调,设置各种属性
  114. ItemTableviewCell *cell = [weakSelf.analyzerTableView cellForRowAtIndexPath:indexPath];
  115. cell.Labeltext.text = encodeString;
  116. AnalyzeDataSource *dataSource = [config getAnalyzeDataSource];
  117. if ([cell.textLabel.text isEqualToString:TS("Analyzer_Enable")]) {
  118. dataSource.AnalyzeEnable = [dataSource getEnableBool:encodeString];
  119. }
  120. if ([cell.textLabel.text isEqualToString:TS("Analyzer_Type")]) {
  121. dataSource.ModuleType = (int)[dataSource getAnalyzeTypeInt:encodeString];
  122. }
  123. if ([cell.textLabel.text isEqualToString:TS("Analyzer_Level")]) {
  124. dataSource.PeaLevel = [encodeString intValue];
  125. }
  126. if ([cell.textLabel.text isEqualToString:TS("Analyzer_Rule")]) {
  127. dataSource.PeaShowRule = [dataSource getEnableBool:encodeString];
  128. }
  129. if ([cell.textLabel.text isEqualToString:TS("Analyzer_Trace")]) {
  130. dataSource.PeaShowTrace = [dataSource getEnableBool:encodeString];
  131. }
  132. };
  133. //点击单元格之后进行分别赋值
  134. AnalyzeDataSource *dataSource = [config getAnalyzeDataSource];
  135. if ([titleStr isEqualToString:TS("Analyzer_Enable")]) {
  136. [itemVC setValueArray:[config getEnableArray]];
  137. }else if ([titleStr isEqualToString:TS("Analyzer_Type")]) {
  138. [itemVC setValueArray:(NSMutableArray*)[dataSource analyzeTypeArray]]; //警戒算法,分3种
  139. }else if ([titleStr isEqualToString:TS("Analyzer_Level")]) {
  140. [itemVC setValueArray:(NSMutableArray*)[dataSource analyzeLevelArray]]; //警戒级别,1-5(可能不同)
  141. }else if ([titleStr isEqualToString:TS("Analyzer_Rule")]) {
  142. [itemVC setValueArray:[config getEnableArray]];
  143. }else if ([titleStr isEqualToString:TS("Analyzer_Trace")]) {
  144. [itemVC setValueArray:[config getEnableArray]];
  145. }else{
  146. return;
  147. }
  148. //如果赋值成功,跳转到下一级界面
  149. [self.navigationController pushViewController:itemVC animated:YES];
  150. }
  151. #pragma mark - 界面和数据初始化
  152. - (void)configSubView {
  153. self.navigationItem.title = TS("AnalyzeConfig");
  154. UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveConfig)];
  155. self.navigationItem.rightBarButtonItem = rightButton;
  156. [self.view addSubview:self.analyzerTableView];
  157. }
  158. - (UITableView *)analyzerTableView {
  159. if (!analyzerTableView) {
  160. analyzerTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  161. analyzerTableView.delegate = self;
  162. analyzerTableView.dataSource = self;
  163. [analyzerTableView registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  164. }
  165. return analyzerTableView;
  166. }
  167. #pragma mark - 界面和数据初始化
  168. - (void)initDataSource {
  169. analyzerTitleArray = (NSMutableArray*)@[TS("Analyzer_Enable"),TS("Analyzer_Type"),TS("Analyzer_Level"),TS("Analyzer_Rule"),TS("Analyzer_Trace")];
  170. }
  171. - (void)didReceiveMemoryWarning {
  172. [super didReceiveMemoryWarning];
  173. // Dispose of any resources that can be recreated.
  174. }
  175. @end