萤石云 iOSSDK,移植跨平台相关工程
Davin
2024-12-18 a67450d72c47f400e56525125318ff1d6ca0a2e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//
//  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 <HDLEZDetectionTypeModel *>*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