HumanDetectionViewController.mm 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // HumanDetectionViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by wujiangbo on 2018/12/27.
  6. // Copyright © 2018 wujiangbo. All rights reserved.
  7. //
  8. #import "HumanDetectionViewController.h"
  9. #import "HumanDetectionConfig.h"
  10. #import "ItemTableviewCell.h"
  11. #import "EncodeItemViewController.h"
  12. #import "Header.h"
  13. @interface HumanDetectionViewController ()<UITableViewDataSource,UITableViewDelegate,HumanDetectionDelegate>
  14. {
  15. NSMutableArray *titleArray; //人形检测数组
  16. UITableView *tableView; //人形检测列表
  17. }
  18. @property (nonatomic, strong) HumanDetectionConfig *functionConfig;
  19. @end
  20. @implementation HumanDetectionViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. //初始化数据和界面
  24. [self initDataSource];
  25. [self configSubView];
  26. //设置导航栏
  27. [self setNaviStyle];
  28. //获取配置
  29. [self getConfig];
  30. }
  31. -(void)viewWillDisappear:(BOOL)animated{
  32. if ([SVProgressHUD isVisible]) {
  33. [SVProgressHUD dismiss];
  34. }
  35. }
  36. - (void)setNaviStyle {
  37. self.navigationItem.title = TS("appEventHumanDetectAlarm");
  38. }
  39. #pragma mark - tableView代理方法
  40. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  41. return titleArray.count;
  42. }
  43. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  44. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  45. if (!cell) {
  46. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  47. }
  48. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  49. NSString *title = [titleArray objectAtIndex:indexPath.row];
  50. cell.textLabel.text = title;
  51. int enable = 0;
  52. if ([title isEqualToString:TS("Alarm_function")]) {
  53. enable = [self.functionConfig getHumanDetectEnable];
  54. }
  55. else if ([title isEqualToString:TS("Alarm_video")]){
  56. enable = [self.functionConfig getHumanDetectRecordEnable];
  57. }
  58. else if ([title isEqualToString:TS("Alarm_picture")]){
  59. enable = [self.functionConfig getHumanDetectSnapEnable];
  60. }
  61. else{
  62. enable = [self.functionConfig getHumanDetectMessageEnable];
  63. }
  64. cell.Labeltext.text = enable == 0 ? TS("close"):TS("open");
  65. return cell;
  66. }
  67. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  68. NSString *titleStr = titleArray[indexPath.row];
  69. //初始化各个配置的item单元格
  70. EncodeItemViewController *itemVC = [[EncodeItemViewController alloc] init];
  71. [itemVC setTitle:titleStr];
  72. __weak typeof(self) weakSelf = self;
  73. itemVC.itemSelectStringBlock = ^(NSString *encodeString) {
  74. //itemVC的单元格点击回调,设置各种属性
  75. ItemTableviewCell *cell = [weakSelf.tableView cellForRowAtIndexPath:indexPath];
  76. cell.Labeltext.text = encodeString;
  77. };
  78. [itemVC setValueArray:[@[TS("close"),TS("open")] mutableCopy]];
  79. [self.navigationController pushViewController:itemVC animated:YES];
  80. }
  81. #pragma mark - 保存配置
  82. -(void)saveConfig{
  83. [SVProgressHUD show];
  84. for (int i = 0; i < titleArray.count; i++) {
  85. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
  86. ItemTableviewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  87. NSString *valueStr = cell.Labeltext.text;
  88. NSString *title = [titleArray objectAtIndex:i];
  89. int enable = 0;
  90. if ([valueStr isEqualToString:TS("open")]) {
  91. enable = 1;
  92. }
  93. if ([title isEqualToString:TS("Alarm_function")]) {
  94. [self.functionConfig setHumanDetectEnable:enable];
  95. }
  96. else if ([title isEqualToString:TS("Alarm_video")]){
  97. [self.functionConfig setHumanDetectRecordEnable:enable];
  98. }
  99. else if ([title isEqualToString:TS("Alarm_picture")]){
  100. [self.functionConfig setHumanDetectSnapEnable:enable];
  101. }
  102. else{
  103. [self.functionConfig setHumanDetectMessageEnable:enable];
  104. }
  105. }
  106. [self.functionConfig SetConfig];
  107. }
  108. #pragma mark - 获取人形检测配置
  109. -(void)getConfig{
  110. [SVProgressHUD show];
  111. if (!_functionConfig) {
  112. _functionConfig = [[HumanDetectionConfig alloc] init];
  113. _functionConfig.delegate = self;
  114. }
  115. [_functionConfig getHumanDetectConfig];
  116. }
  117. #pragma mark - 获取配置回调
  118. -(void)HumanDetectionConfigGetResult:(NSInteger)result{
  119. if (result >= 0) {
  120. //成功,刷新界面数据
  121. [tableView reloadData];
  122. [SVProgressHUD dismiss];
  123. }else{
  124. [MessageUI ShowErrorInt:(int)result];
  125. }
  126. }
  127. -(void)HumanDetectionConfigSetResult:(NSInteger)result{
  128. if (result >= 0) {
  129. //成功
  130. [SVProgressHUD dismissWithSuccess:TS("Success")];
  131. }else{
  132. [MessageUI ShowErrorInt:(int)result];
  133. }
  134. }
  135. - (void)configSubView {
  136. UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveConfig)];
  137. self.navigationItem.rightBarButtonItem = rightButton;
  138. [self.view addSubview:self.tableView];
  139. }
  140. - (UITableView *)tableView {
  141. if (!tableView) {
  142. tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  143. tableView.delegate = self;
  144. tableView.dataSource = self;
  145. [tableView registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  146. }
  147. return tableView;
  148. }
  149. #pragma mark - 界面和数据初始化
  150. -(void)initDataSource {
  151. titleArray = [[NSMutableArray alloc] initWithObjects:TS("Alarm_function"),TS("Alarm_video"),TS("Alarm_picture"),TS("Send_to_phone"),nil];
  152. }
  153. @end