// // HDLEZDetectionTypeViewController.m // EZSDK // // Created by Davin on 2023/8/5. // #import "HDLEZDetectionTypeViewController.h" #import "HDLESDetectionTypeHeaderView.h" #import "HDLEZDetectionTypeView.h" #import "MJRefreshNormalHeader.h" @interface HDLEZDetectionTypeViewController () @property (nonatomic, strong) HDLESDetectionTypeHeaderView *detectionTypeHeaderView; @property (nonatomic, strong) HDLEZDetectionTypeView *detectionTypeView; @property (nonatomic, strong) MJRefreshNormalHeader *header;//刷新header @property (nonatomic, strong) UIButton *sureButton; @property (nonatomic, strong) NSArray *detectionTypeArray; @property (nonatomic, strong) NSString *selectedCode; // 选中要设置的检测类型 @end @implementation HDLEZDetectionTypeViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController.navigationBar setHidden:YES]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setTopBarViewWithTitle:HDLEZLocallizedString(@"device_detection_type")]; [self.topBarView.bottomLine setHidden:YES]; // [self.navigationController.navigationBar setHidden:YES]; [self createSubviews]; } - (void)createSubviews { self.view.backgroundColor = HDLEZHEXCOLOR(0xF2F3F7, 1.); self.selectedCode = @""; [self.view addSubview:self.detectionTypeHeaderView]; [self.view addSubview:self.detectionTypeView]; [self.view addSubview:self.sureButton]; [self.detectionTypeHeaderView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(HDLEZ_APP_TOP_BAR_HEIGHT); make.left.right.equalTo(self.view); make.height.mas_equalTo(60); }]; [self.detectionTypeView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(HDLEZ_APP_TOP_BAR_HEIGHT + 70); make.left.right.equalTo(self.view); }]; [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.detectionTypeView.mas_bottom).offset(16.); make.bottom.mas_equalTo(self.view.mas_bottom).offset(-56.); make.centerX.mas_equalTo(self.view.mas_centerX); make.width.mas_equalTo(220.); make.height.mas_equalTo(44.); }]; //#warning mock test // NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:0]; // HDLEZDetectionTypeModel *firstModel = [[HDLEZDetectionTypeModel alloc] init]; // firstModel.title = @"AI人形或车型检测"; // firstModel.isSelected = NO; // [mArray addObject:firstModel]; // // HDLEZDetectionTypeModel *secondModel = [[HDLEZDetectionTypeModel alloc] init]; // secondModel.title = @"AI人形检测"; // secondModel.isSelected = NO; // [mArray addObject:secondModel]; // // HDLEZDetectionTypeModel *thirdmodel = [[HDLEZDetectionTypeModel alloc] init]; // thirdmodel.title = @"车型检测"; // thirdmodel.isSelected = NO; // [mArray addObject:thirdmodel]; // // HDLEZDetectionTypeModel *fourthModel = [[HDLEZDetectionTypeModel alloc] init]; // fourthModel.title = @"画面变化检测"; // fourthModel.isSelected = NO; // [mArray addObject:fourthModel]; // // HDLEZDetectionTypeModel *fifthModel = [[HDLEZDetectionTypeModel alloc] init]; // fifthModel.title = @"关闭活动检测提醒"; // fifthModel.isSelected = NO; // [mArray addObject:fifthModel]; // // self.detectionTypeView.detectionTypeList = mArray; __weak __typeof(self)weakSelf = self; BOOL isDefence = (self.deviceInfo.defence != 0); [self updateDetectionView:isDefence]; [self.detectionTypeHeaderView configSelected:isDefence switchResult:^(BOOL isSelected) { __weak MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.labelText = NSLocalizedString(@"setting_switching", @"正在切换,请稍候..."); /** * 注意;该demo只处理了IPC设备的布撤防,所有只有YES/NO,关于A系列设备请判断设备后修改枚举值再处理 */ [EZOPENSDK setDefence:isSelected deviceSerial:weakSelf.deviceInfo.deviceSerial completion:^(NSError *error) { [hud hide:YES]; if (error) { [weakSelf.view makeToast:NSLocalizedString(@"setting_opration_fail", @"操作失败") duration:2.0 position:@"center"]; [weakSelf.detectionTypeHeaderView configSelected:!isSelected]; } else{ weakSelf.deviceInfo.defence = isSelected; } BOOL isDefence = (weakSelf.deviceInfo.defence != 0); [weakSelf updateDetectionView:isDefence]; }]; }]; [self.detectionTypeView didSelectedDetectionType:^(NSString * _Nonnull code) { weakSelf.selectedCode = code; }]; //下拉刷新 // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法) _header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshData)]; // 设置自动切换透明度(在导航栏下面自动隐藏) _header.automaticallyChangeAlpha = YES; // 隐藏时间 _header.lastUpdatedTimeLabel.hidden = YES; // 隐藏刷新状态文本 _header.stateLabel.hidden = YES; _detectionTypeView.mj_header=_header; //开始加载数据 [_header beginRefreshing]; [self.sureButton addTarget:self action:@selector(sureAction) forControlEvents:UIControlEventTouchUpInside]; } - (void)updateDetectionView:(BOOL)isDefence { self.detectionTypeView.hidden = !isDefence; self.sureButton.hidden = !isDefence; } /*刷新数据 */ -(void)refreshData{ self.detectionTypeArray=[[NSMutableArray alloc] init]; [self getMsgList]; } /*获取历史记录 */ -(void)getMsgList{ __weak __typeof(self)weakSelf = self; [[EZHttpUtil sharedManager] getAiSupportDetectionList:self.deviceInfo.deviceSerial completion:^(ResponseData * _Nonnull responseData) { [weakSelf.header endRefreshing]; if (responseData.success) { weakSelf.detectionTypeArray=[NSArray yy_modelArrayWithClass:[HDLEZDetectionTypeModel class] json:responseData.data]; weakSelf.detectionTypeView.detectionTypeList = weakSelf.detectionTypeArray; }else{ [weakSelf.view makeToast:responseData.message duration:1.5 position:@"center"]; } }]; } #pragma mark - PrivateMethod - (void)checkSelectedCode { for (HDLEZDetectionTypeModel *typeModel in self.detectionTypeArray) { if (typeModel.status) { self.selectedCode = typeModel.code; break; } } } - (void)sureAction { if (self.selectedCode && self.selectedCode.length > 0) { __weak __typeof(self)weakSelf = self; __weak MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.labelText = NSLocalizedString(@"setting_switching", @"正在切换,请稍候..."); [[EZHttpUtil sharedManager] setAiSupportDetection:self.deviceInfo.deviceSerial code:self.selectedCode completion:^(ResponseData * _Nonnull responseData) { [hud hide:YES]; if (responseData.success) { [weakSelf.view makeToast:HDLEZLocallizedString(@"setting_opration_success") duration:1.5 position:@"center"]; [weakSelf.navigationController popViewControllerAnimated:YES]; } else { [weakSelf.view makeToast:responseData.message duration:1.5 position:@"center"]; } }]; } } #pragma mark - Getter - (HDLESDetectionTypeHeaderView *)detectionTypeHeaderView { if (!_detectionTypeHeaderView) { _detectionTypeHeaderView = [[HDLESDetectionTypeHeaderView alloc] init]; _detectionTypeHeaderView.backgroundColor = [UIColor whiteColor]; } return _detectionTypeHeaderView; } - (HDLEZDetectionTypeView *)detectionTypeView { if (!_detectionTypeView) { _detectionTypeView = [[HDLEZDetectionTypeView alloc] init]; _detectionTypeView.backgroundColor = [UIColor clearColor]; } return _detectionTypeView; } - (UIButton *)sureButton { if (!_sureButton) { _sureButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_sureButton setTitle:HDLEZLocallizedString(@"device_temp_sure") forState:UIControlStateNormal]; [_sureButton setTitleColor:HDLEZ_COLOR_TITLE_BLACK forState:UIControlStateNormal]; _sureButton.titleLabel.font = HDLEZ_Get_FontRegularWithSize(HDLEZ_FontSize_16); _sureButton.backgroundColor = UIColor.whiteColor; _sureButton.layer.cornerRadius = 22.; _sureButton.clipsToBounds = YES; } return _sureButton; } @end