| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- //
- // HumanDetectionViewController.m
- // FunSDKDemo
- //
- // Created by wujiangbo on 2018/12/27.
- // Copyright © 2018 wujiangbo. All rights reserved.
- //
- #import "HumanDetectionViewController.h"
- #import "HumanDetectionConfig.h"
- #import "ItemTableviewCell.h"
- #import "EncodeItemViewController.h"
- #import "Header.h"
- @interface HumanDetectionViewController ()<UITableViewDataSource,UITableViewDelegate,HumanDetectionDelegate>
- {
- NSMutableArray *titleArray; //人形检测数组
- UITableView *tableView; //人形检测列表
- }
- @property (nonatomic, strong) HumanDetectionConfig *functionConfig;
- @end
- @implementation HumanDetectionViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- //初始化数据和界面
- [self initDataSource];
- [self configSubView];
- //设置导航栏
- [self setNaviStyle];
- //获取配置
- [self getConfig];
- }
- -(void)viewWillDisappear:(BOOL)animated{
- if ([SVProgressHUD isVisible]) {
- [SVProgressHUD dismiss];
- }
- }
- - (void)setNaviStyle {
- self.navigationItem.title = TS("appEventHumanDetectAlarm");
- }
- #pragma mark - tableView代理方法
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return titleArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
- if (!cell) {
- cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
- }
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- NSString *title = [titleArray objectAtIndex:indexPath.row];
- cell.textLabel.text = title;
- int enable = 0;
- if ([title isEqualToString:TS("Alarm_function")]) {
- enable = [self.functionConfig getHumanDetectEnable];
- }
- else if ([title isEqualToString:TS("Alarm_video")]){
- enable = [self.functionConfig getHumanDetectRecordEnable];
- }
- else if ([title isEqualToString:TS("Alarm_picture")]){
- enable = [self.functionConfig getHumanDetectSnapEnable];
- }
- else{
- enable = [self.functionConfig getHumanDetectMessageEnable];
- }
-
- cell.Labeltext.text = enable == 0 ? TS("close"):TS("open");
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- NSString *titleStr = titleArray[indexPath.row];
- //初始化各个配置的item单元格
- EncodeItemViewController *itemVC = [[EncodeItemViewController alloc] init];
- [itemVC setTitle:titleStr];
-
- __weak typeof(self) weakSelf = self;
- itemVC.itemSelectStringBlock = ^(NSString *encodeString) {
- //itemVC的单元格点击回调,设置各种属性
- ItemTableviewCell *cell = [weakSelf.tableView cellForRowAtIndexPath:indexPath];
- cell.Labeltext.text = encodeString;
- };
- [itemVC setValueArray:[@[TS("close"),TS("open")] mutableCopy]];
- [self.navigationController pushViewController:itemVC animated:YES];
- }
- #pragma mark - 保存配置
- -(void)saveConfig{
- [SVProgressHUD show];
- for (int i = 0; i < titleArray.count; i++) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
- ItemTableviewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
- NSString *valueStr = cell.Labeltext.text;
- NSString *title = [titleArray objectAtIndex:i];
- int enable = 0;
- if ([valueStr isEqualToString:TS("open")]) {
- enable = 1;
- }
- if ([title isEqualToString:TS("Alarm_function")]) {
- [self.functionConfig setHumanDetectEnable:enable];
- }
- else if ([title isEqualToString:TS("Alarm_video")]){
- [self.functionConfig setHumanDetectRecordEnable:enable];
- }
- else if ([title isEqualToString:TS("Alarm_picture")]){
- [self.functionConfig setHumanDetectSnapEnable:enable];
- }
- else{
- [self.functionConfig setHumanDetectMessageEnable:enable];
- }
- }
-
- [self.functionConfig SetConfig];
- }
- #pragma mark - 获取人形检测配置
- -(void)getConfig{
- [SVProgressHUD show];
- if (!_functionConfig) {
- _functionConfig = [[HumanDetectionConfig alloc] init];
- _functionConfig.delegate = self;
- }
- [_functionConfig getHumanDetectConfig];
- }
- #pragma mark - 获取配置回调
- -(void)HumanDetectionConfigGetResult:(NSInteger)result{
- if (result >= 0) {
- //成功,刷新界面数据
- [tableView reloadData];
- [SVProgressHUD dismiss];
- }else{
- [MessageUI ShowErrorInt:(int)result];
- }
- }
- -(void)HumanDetectionConfigSetResult:(NSInteger)result{
- if (result >= 0) {
- //成功
- [SVProgressHUD dismissWithSuccess:TS("Success")];
- }else{
- [MessageUI ShowErrorInt:(int)result];
- }
- }
- - (void)configSubView {
- UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveConfig)];
- self.navigationItem.rightBarButtonItem = rightButton;
- [self.view addSubview:self.tableView];
- }
- - (UITableView *)tableView {
- if (!tableView) {
- tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
- tableView.delegate = self;
- tableView.dataSource = self;
- [tableView registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
- }
- return tableView;
- }
- #pragma mark - 界面和数据初始化
- -(void)initDataSource {
- titleArray = [[NSMutableArray alloc] initWithObjects:TS("Alarm_function"),TS("Alarm_video"),TS("Alarm_picture"),TS("Send_to_phone"),nil];
- }
- @end
|