JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
//
//  Copyright © 2020 dahua. All rights reserved.
//
 
#import "LCDeviceSettingPersenter.h"
#import "LCDeviceSwitchCell.h"
#import <LCBaseModule/LCSheetView.h>
#import <QuartzCore/QuartzCore.h>
#import "LCToolKit.h"
#import "LCUIKit.h"
#import "LCDeviceSettingArrowCell.h"
#import "LCDeviceSettingSubtitleCell.h"
 
@interface LCDeviceSettingPersenter ()<UIImagePickerControllerDelegate, UITextFieldDelegate>
 
@property (strong, nonatomic) LCDeviceVersionInfo *versionInfo;
 
@property (strong, nonatomic) LCDeviceInfo *deviceInfo;
 
@property (strong, nonatomic) NSTimer *updateCheckTimer;
 
@property (strong, nonatomic) LCButton *updateBtn;
 
@end
 
@implementation LCDeviceSettingPersenter
 
//MARK: - TableViewDelegate
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (self.style == LCDeviceSettingStyleMainPage) {
        //多通道设备通道:设备信息、布防设置。
        //多通道设备:设备信息、云升级、网络配置。
        //其他设备:设备信息,云升级,布防设置,网络配置
        if ([self isMultipleCahannels]) {
            return 2;
        } else if ([self isMultipleDevice]) {
            return [self.manager.currentDevice.status isEqualToString:@"online"] ? 2 : 1;
        } else {
            return [self.manager.currentDevice.status isEqualToString:@"online"] ? 3 : 2;
        }
    }
    return 1;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.style == LCDeviceSettingStyleMainPage) {
        return [self getFirstPageSetCellForIndex:indexPath TableView:tableView];
    }
    if (self.style == LCDeviceSettingStyleDeploy) {
        return [self getDeployPageCellForIndex:indexPath TableView:tableView];
    }
    if (self.style == LCDeviceSettingStyleDeviceDetailInfo) {
        return [self getDeviceInfoPageSetCellForIndex:indexPath TableView:tableView];
    }
    if (self.style == LCDeviceSettingStyleVersionUp) {
        return [self getVersionPageCellForIndex:indexPath TableView:tableView];
    }
    if (self.style == LCDeviceSettingStyleDeviceNameEdit) {
        return [self getEditNamelForIndex:indexPath TableView:tableView];
    }
    return nil;
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.style == LCDeviceSettingStyleMainPage) {
        if (section == 0) {
            return [self isMultipleCahannels] ? 1 : 2;
        } else {
            return 1;
        }
    }
    if (self.style == LCDeviceSettingStyleDeploy) {
        return 1;
    }
    if (self.style == LCDeviceSettingStyleDeviceDetailInfo) {
        if ([self isMultipleCahannels]) {
            return 1;
        }
        return 3;
    }
    if (self.style == LCDeviceSettingStyleVersionUp) {
        if (self.versionInfo.canBeUpgrade) {
            return 2;
        }
        return 1;
    }
    if (self.style == LCDeviceSettingStyleDeviceNameEdit) {
        return 1;
    }
    return 0;
}
 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (self.style == LCDeviceSettingStyleMainPage && section == 1) {
        UILabel *lab = [UILabel new];
        lab.font = [UIFont lcFont_t6];
        lab.textColor = [UIColor dhcolor_c41];
        lab.text = [NSString stringWithFormat:@"   %@",@"setting_device_footer_alarm".lc_T];
        return lab;
    } else if (self.style == LCDeviceSettingStyleMainPage && section == 2) {
        UILabel *lab = [UILabel new];
        lab.font = [UIFont lcFont_t6];
        lab.textColor = [UIColor dhcolor_c41];
        lab.text = [NSString stringWithFormat:@"   %@",@"device_manager_network_config".lc_T];
        return lab;
    }
    return nil;
}
 
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UILabel *lab = [UILabel new];
    lab.font = [UIFont lcFont_t6];
    lab.numberOfLines = 0;
    lab.textAlignment = NSTextAlignmentLeft;
    lab.lineBreakMode = NSLineBreakByWordWrapping;
    lab.textColor = [UIColor dhcolor_c41];
    if (self.style == LCDeviceSettingStyleDeploy) {
        lab.text = @"setting_device_deployment_detail".lc_T;
        return lab;
    }
    if (self.style == LCDeviceSettingStyleVersionUp) {
        lab.text = @"setting_device_latest_version".lc_T;
        if (self.versionInfo.canBeUpgrade) {
            return nil;
        }
        return lab;
    }
    return nil;
}
 
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//    if (self.style == LCDeviceSettingStyleMainPage && indexPath.section == 0 && indexPath.row == 0) {
//        return 65;
//    }
//    return 100;
//}
 
- (LCDeviceVideoManager *)manager {
    if (!_manager) {
        _manager = [LCDeviceVideoManager manager];
    }
    return _manager;
}
 
- (UITableViewCell *)getFirstPageSetCellForIndex:(NSIndexPath *)indexPath TableView:(UITableView *)tableview {
    weakSelf(self);
    if (indexPath.section == 0 && indexPath.row == 0) {
        LCDeviceSettingArrowCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingArrowCell"];
        cell.title = [self isMultipleCahannels] ? self.manager.currentChannelInfo.channelName : self.manager.currentDevice.name;
        if ([self isMultipleCahannels]) {
            [cell loadImage:self.manager.currentChannelInfo.picUrl DeviceId:self.manager.currentDevice.deviceId ChannelId:[NSString stringWithFormat:@"%ld",(long)self.manager.currentChannelIndex]];
        } else {
            [cell loadImage:self.manager.currentChannelInfo.picUrl DeviceId:self.manager.currentDevice.deviceId ChannelId:@"0"];
        }
        
        cell.block = ^(NSInteger index) {
            [weakself.container.navigationController pushToDeviceSettingDeviceDetail];
        };
        return cell;
    } else if (indexPath.section == 0 && indexPath.row == 1) {
        LCDeviceSettingSubtitleCell *tempCell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingSubtitleCell" forIndexPath:indexPath];
        tempCell.title = @"setting_device_version".lc_T;
        tempCell.subtitle = self.manager.currentDevice.version;
        tempCell.userInteractionEnabled = [self.manager.currentDevice.status isEqualToString:@"online"];
        tempCell.block = ^{
            [weakself.container.navigationController pushToDeviceSettingVersion];
        };
        return tempCell;
    } else if (indexPath.section == 1) {
        if ([self isMultipleDevice]) {
            LCDeviceSettingArrowCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingArrowCell"];
            cell.title = @"device_manager_network_config".lc_T;
            cell.block = ^(NSInteger index) {
                [weakself.container.navigationController pushToWifiSettings:self.manager.currentDevice.deviceId];
            };
            return cell;
        } else {
            LCDeviceSettingArrowCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingArrowCell"];
            cell.title = @"setting_device_deployment".lc_T;
            cell.block = ^(NSInteger index) {
                [weakself.container.navigationController pushToDeviceSettingDeploy];
            };
            return cell;
        }
    } else {
        LCDeviceSettingArrowCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingArrowCell"];
        cell.title = @"device_manager_network_config".lc_T;
        cell.block = ^(NSInteger index) {
            [weakself.container.navigationController pushToWifiSettings:self.manager.currentDevice.deviceId];
        };
        return cell;
    }
    return nil;
}
 
- (UITableViewCell *)getDeviceInfoPageSetCellForIndex:(NSIndexPath *)indexPath TableView:(UITableView *)tableview {
    weakSelf(self);
    if (indexPath.row == 0) {
        LCDeviceSettingArrowCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingArrowCell"];
        cell.title = @"setting_device_device_name".lc_T;
        cell.subtitle = [self isMultipleCahannels] ? self.manager.currentChannelInfo.channelName : self.manager.currentDevice.name;
        cell.block = ^(NSInteger index) {
            [weakself.container.navigationController pushToDeviceSettingEditName];
        };
        return cell;
    } else if (indexPath.row == 1) {
        LCDeviceSettingSubtitleCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingSubtitleCell"];
        cell.title = @"setting_device_device_model".lc_T;
        cell.subtitle = self.manager.currentDevice.deviceModel;
        return cell;
    } else {
        LCDeviceSettingArrowCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingArrowCell"];
        cell.title = @"setting_device_serial_number".lc_T;
        cell.subtitle = self.manager.currentDevice.deviceId;
        [cell setArrowImage:LC_IMAGENAMED(@"setting_icon_copy")];
        cell.block = ^(NSInteger index) {
            if (index == 1) {
                UIPasteboard *board = [UIPasteboard generalPasteboard];
                board.string = self.manager.currentDevice.deviceId;
                [LCProgressHUD showMsg:@"setting_device_had_paste".lc_T];
            }
        };
        return cell;
    }
}
 
- (LCDeviceSwitchCell *)getDeployPageCellForIndex:(NSIndexPath *)indexPath TableView:(UITableView *)tableview {
    weakSelf(self);
    __block LCDeviceSwitchCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSwitchCell"];
    [cell setEnable:[self.manager.currentDevice.status isEqualToString:@"online"] ? YES : NO];
    cell.title = [NSString stringWithFormat:@"%@-%@", @"setting_device_deployment_switch".lc_T, self.manager.currentChannelInfo.channelName];
    [LCDeviceManagerInterface bindDeviceChannelInfoWithDevice:self.manager.currentDevice.deviceId ChannelId:[self currentChannelID:indexPath] success:^(LCBindDeviceChannelInfo *_Nonnull info) {
        [cell setSwitch:info.alarmStatus];
    } failure:^(LCError *_Nonnull error) {
        [cell setSwitch:NO];
        [LCProgressHUD showMsg:error.errorMessage];
    }];
    __block LCDeviceSwitchCell *tempCell = cell;
    cell.block = ^(BOOL value) {
        if (value) {
            [LCOCAlertView lc_ShowAlertWith:@"Alert_Title_Notice".lc_T Detail:@"setting_device_alarm_alert".lc_T ConfirmTitle:@"Alert_Title_Button_Confirm".lc_T CancleTitle:@"Alert_Title_Button_Cancle".lc_T Handle:^(BOOL isConfirmSelected) {
                if (isConfirmSelected) {
                    [weakself setDeviceAlarmStatus:value cell:tempCell indexPath:indexPath];
                } else {
                    [tempCell setSwitch:!value];
                }
            }];
        } else {
            [LCOCAlertView lc_ShowAlertWith:@"Alert_Title_Notice".lc_T Detail:@"setting_device_alarm_alert_close".lc_T ConfirmTitle:@"Alert_Title_Button_Confirm".lc_T CancleTitle:@"Alert_Title_Button_Cancle".lc_T Handle:^(BOOL isConfirmSelected) {
                if (isConfirmSelected) {
                    [weakself setDeviceAlarmStatus:value cell:tempCell indexPath:indexPath];
                } else {
                    [tempCell setSwitch:!value];
                }
            }];
        }
    };
 
    return cell;
}
 
- (void)setDeviceAlarmStatus:(BOOL)value cell:(LCDeviceSwitchCell *)cell indexPath:(NSIndexPath *)indexPath {
    [LCProgressHUD showHudOnView:nil];
    [LCDeviceHandleInterface modifyDeviceAlarmStatus:self.manager.currentDevice.deviceId channelId:[self currentChannelID:indexPath] enable:value success:^{
        [LCProgressHUD hideAllHuds:nil];
    } failure:^(LCError *_Nonnull error) {
        [LCProgressHUD hideAllHuds:nil];
        [cell setSwitch:!value];
        [LCProgressHUD showMsg:error.errorMessage];
    }];
}
 
- (LCDeviceSettingSubtitleCell *)getVersionPageCellForIndex:(NSIndexPath *)indexPath TableView:(UITableView *)tableview {
    weakSelf(self);
    LCDeviceSettingSubtitleCell *cell = [tableview dequeueReusableCellWithIdentifier:@"LCDeviceSettingSubtitleCell"];
    if (indexPath.row == 0) {
        cell.title = @"setting_device_now_version".lc_T;
        cell.subtitle = self.versionInfo.version;
    }
    if (indexPath.row == 1) {
        cell.title = @"setting_device_last_version".lc_T;
        cell.subtitle = self.versionInfo.upgradeInfo.version;
        cell.detail = self.versionInfo.upgradeInfo.LcDescription;
    }
    if (!self.updateBtn) {
        self.updateBtn = [LCButton lcButtonWithType:LCButtonTypeCustom];
    }
    //如果可以升级则展示升级按钮
    if (self.versionInfo.canBeUpgrade) {
        self.updateBtn.hidden = NO;
        [self.updateBtn setBackgroundColor:[UIColor dhcolor_c43]];
        [self.updateBtn setTitle:@"setting_device_update".lc_T forState:UIControlStateNormal];
        if ([self.deviceInfo.status isEqualToString:@"offline"]) {
            self.updateBtn.enabled = NO;
        }
        if ([self.deviceInfo.status isEqualToString:@"upgrading"] || self.updateBtn.selected == YES) {
            [self.updateBtn setTitle:@"setting_device_updateing".lc_T forState:UIControlStateNormal];
            self.updateBtn.enabled = NO;
        }
        [self.updateBtn setTitleColor:[UIColor dhcolor_c62] forState:UIControlStateNormal];
        [self.updateBtn setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        self.updateBtn.touchUpInsideblock = ^(LCButton *_Nonnull btn) {
            [LCOCAlertView lc_ShowAlertWith:@"Alert_Title_Notice".lc_T Detail:@"setting_device_update_alert".lc_T ConfirmTitle:@"Alert_Title_Button_Confirm".lc_T CancleTitle:@"Alert_Title_Button_Cancle".lc_T Handle:^(BOOL isConfirmSelected) {
                if (isConfirmSelected) {
                    [LCProgressHUD showHudOnView:nil];
                    [weakself.updateCheckTimer invalidate];
                    weakself.updateCheckTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:weakself selector:@selector(checkUpdateStatus) userInfo:nil repeats:YES];
                    [LCDeviceHandleInterface upgradeDevice:weakself.manager.currentDevice.deviceId success:^{
                        [btn setTitle:@"setting_device_updateing".lc_T forState:UIControlStateNormal];
                        btn.enabled = NO;
                        weakself.updateBtn.selected = YES;
                        [LCProgressHUD hideAllHuds:nil];
                    } failure:^(LCError *_Nonnull error) {
                        [LCProgressHUD hideAllHuds:nil];
                        weakself.updateBtn.selected = NO;
                        [LCProgressHUD showMsg:error.errorMessage];
                    }];
                }
            }];
        };
        tableview.tableFooterView = self.updateBtn;
    } else {
        self.updateBtn.hidden = YES;
    }
 
    return cell;
}
 
- (void)checkUpdateStatus {
    weakSelf(self);
    __block LCDeviceInfo *deviceInfo = nil;
    __block LCDeviceVersionInfo *versionInfo = nil;
    dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t globalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_enter(group);
    dispatch_async(globalQueue, ^{
        if (self.manager.isbindFromLeChange) {
            [LCDeviceManagerInterface deviceBaseDetailListFromLeChangeWithSimpleList:@[weakself.manager.currentDevice] success:^(NSMutableArray<LCDeviceInfo *> *_Nonnull infos) {
                if (infos[0]) {
                    deviceInfo = infos[0];
                }
                dispatch_group_leave(group);
            } failure:^(LCError *_Nonnull error) {
                dispatch_group_leave(group);
            }];
        } else {
            [LCDeviceManagerInterface deviceOpenDetailListFromLeChangeWithSimpleList:@[weakself.manager.currentDevice] success:^(NSMutableArray<LCDeviceInfo *> *_Nonnull infos) {
                if (infos[0]) {
                    deviceInfo = infos[0];
                }
                dispatch_group_leave(group);
            } failure:^(LCError *_Nonnull error) {
                dispatch_group_leave(group);
            }];
        }
    });
 
    dispatch_group_enter(group);
    dispatch_async(globalQueue, ^{
        [LCDeviceManagerInterface deviceVersionForDevices:@[weakself.manager.currentDevice.deviceId] success:^(NSMutableArray<LCDeviceVersionInfo *> *_Nonnull info) {
            versionInfo = [info objectAtIndex:0];
            dispatch_group_leave(group);
        } failure:^(LCError *_Nonnull error) {
            dispatch_group_leave(group);
        }];
    });
    dispatch_group_notify(group, globalQueue, ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            if (deviceInfo) {
                weakself.deviceInfo = deviceInfo;
            }
            if (versionInfo) {
                weakself.versionInfo = versionInfo;
            }
            NSLog(@"dev:%@,ver:%@,设备升级,当前是否可升级:%d,当前设备状态:%@", deviceInfo, versionInfo, versionInfo.canBeUpgrade, deviceInfo.status);
            weakself.needReload = YES;
        });
    });
}
 
- (void)stopCheckUpdate {
    if (self.updateCheckTimer) {
        [self.updateCheckTimer invalidate];
        self.updateCheckTimer = nil;
    }
}
 
- (UITableViewCell *)getEditNamelForIndex:(NSIndexPath *)indexPath TableView:(UITableView *)tableview {
    UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    DHTextField *textField = [DHTextField lcTextFieldWithResult:^(NSString *_Nonnull result) {
        result = [result vaildDeviceName];
        if (result.length == 0 || result == nil) {
            self.container.navigationItem.rightBarButtonItem.enabled = NO;
            return;
        }
        self.container.navigationItem.rightBarButtonItem.enabled = YES;
        self.deviceName = result;
    }];
    textField.delegate = self;
    self.deviceName = [self isMultipleCahannels] ? self.manager.currentChannelInfo.channelName : self.manager.currentDevice.name;
    [textField.KVOController observe:self keyPath:@"endEdit" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
        [textField endEditing:YES];
    }];
    textField.placeholder = @"setting_device_edit_name_placeholder".lc_T;
    textField.text = [self isMultipleCahannels] ? self.manager.currentChannelInfo.channelName : self.manager.currentDevice.name;
    textField.clearButtonMode = UITextFieldViewModeAlways;
    [cell addSubview:textField];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.mas_equalTo(cell);
        make.height.mas_equalTo(52);
    }];
 
    return cell;
}
 
- (void)textFieldDidEndEditing:(UITextField *)textField reason:(UITextFieldDidEndEditingReason)reason {
    if (textField.text.length == 0 || textField.text == nil) {
        self.container.navigationItem.rightBarButtonItem.enabled = NO;
        return;
    }
    self.container.navigationItem.rightBarButtonItem.enabled = YES;
    self.deviceName = [textField.text vaildDeviceName];
}
 
- (BOOL)textFieldShouldClear:(UITextField *)textField {
    self.container.navigationItem.rightBarButtonItem.enabled = NO;
    return YES;
}
 
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *temp = [textField.text stringByReplacingCharactersInRange:range withString:string];
    NSString *result = [textField.text filterCharactor:temp withRegex:@"[^\u4e00-\u9fa5]"];
    /*
        TO DEV:此处的名称输入限制开发者可以根据自己的需要进行处理,设备对名称并不限制
    **/
    
    if (![string isEqualToString:@""] && temp.length > 20) {
        return NO;
    }
    if (![string isEqualToString:@""] && result.length > 10) {
        return NO;
    }
    if (![string isEqualToString:@""] && ![string isVaildDeviceName]) {
        return NO;
    }
    if (temp.length == 0) {
        self.container.navigationItem.rightBarButtonItem.enabled = NO;
    } else {
        self.container.navigationItem.rightBarButtonItem.enabled = YES;
    }
 
    return YES;
}
 
- (void)setStyle:(LCDeviceSettingStyle)style {
    _style = style;
    if (style == LCDeviceSettingStyleVersionUp) {
        [self checkUpdateStatus];
    }
}
 
//多通设备的通道
- (BOOL)isMultipleCahannels {
    //多通道且下标大于-1
    if (self.manager.currentDevice.channels.count > 1 && self.manager.currentChannelIndex > -1) {
        return YES;
    }
    return NO;
}
 
//多通道设备
- (BOOL)isMultipleDevice {
    //多通道且下标等于-1
    if ((self.manager.currentDevice.channels.count > 1 || [self.manager.currentDevice.catalog isEqualToString:@"NVR"]) && self.manager.currentChannelIndex == -1) {
        return YES;
    }
    return NO;
}
 
- (NSString *)currentChannelID:(NSIndexPath *)indexPath {
    return self.manager.currentChannelInfo ? self.manager.currentChannelInfo.channelId : self.manager.currentDevice.channels[indexPath.row].channelId;
}
 
- (void)showActionSheet {
    weakSelf(self);
    LCSheetView *sheetView = [[LCSheetView alloc] initWithTitle:nil message:nil delegate:self cancelButton:@"Alert_Title_Button_Cancle".lc_T otherButtons:@[@"More_Device_Shoot".lc_T, @"More_Device_Choose_Comefrom_Picture".lc_T]];
    sheetView.clickedBlock = ^(NSInteger index) {
        if (index == 1) {
            //拍照
            [weakself showImagePicker:YES];
        }
        if (index == 2) {
            //相册
            [weakself showImagePicker:NO];
        }
    };
    [sheetView show];
}
 
- (void)showImagePicker:(BOOL)isCamera {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.modalPresentationStyle = UIModalPresentationPopover; //UIModalPresentationOverFullScreen
    picker.navigationBarHidden = YES;
    picker.toolbarHidden = YES;
    //    picker.allowsEditing = YES; //去掉编辑框
 
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] && isCamera) {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    }
 
    if (!isCamera) {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    [self.container presentViewController:picker animated:YES completion:^{}];
}
 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
    //更新预览图
    UIImage *preViewImage = [img lc_thumbnailWithImageWithSize:CGSizeMake(325, 150)];
    [[UIImageView new] lc_storeImage:preViewImage ForDeviceId:self.manager.currentDevice.deviceId ChannelId:self.manager.currentChannelInfo.channelId];
    //预上传图片压缩
    UIImage *uploadImage = [img lc_thumbnailWithImageWithSize:CGSizeMake(1280, 1280 * 150 / 325)];
    [picker dismissViewControllerAnimated:YES completion:nil];
}
 
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    //DTS000110534
    [picker dismissViewControllerAnimated:YES completion:^{}];
}
 
#pragma mark - public
 
- (void)reloadDeviceInfo {
    static LCDeviceInfo *info = nil;
    dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t globalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    if (self.manager.isbindFromLeChange) {
        [LCDeviceManagerInterface deviceBaseDetailListFromLeChangeWithSimpleList:[NSMutableArray arrayWithArray:@[self.manager.currentDevice]] success:^(NSMutableArray<LCDeviceInfo *> *_Nonnull devices) {
            if (devices.count > 0) {
                info = devices[0];
            }
        } failure:^(LCError *_Nonnull error) {
        }];
    } else {
        [LCDeviceManagerInterface deviceOpenDetailListFromLeChangeWithSimpleList:[NSMutableArray arrayWithArray:@[self.manager.currentDevice]] success:^(NSMutableArray<LCDeviceInfo *> *_Nonnull devices) {
            if (devices.count > 0) {
                info = devices[0];
            }
        } failure:^(LCError *_Nonnull error) {
        }];
    }
    dispatch_group_enter(group);
    dispatch_async(globalQueue, ^{
    });
    dispatch_group_notify(group, globalQueue, ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            if (info) {
                //获取信息成功
                self.manager.currentDevice = info;
            }
        });
    });
}
 
- (void)modifyDevice {
    weakSelf(self);
    [LCProgressHUD showHudOnView:nil];
    [LCDeviceManagerInterface modifyDeviceForDevice:self.manager.currentDevice.deviceId Channel:self.manager.currentChannelInfo ? self.manager.currentChannelInfo.channelId : nil NewName:self.deviceName.vaildDeviceName success:^{
        
        //单通道
        if (weakself.manager.currentDevice.channels.count == 1) {
            weakself.manager.currentDevice.name = self.deviceName;
            weakself.manager.currentDevice.channels[0].channelName = self.deviceName;
        } else {
            if ([self isMultipleCahannels]) {
                weakself.manager.currentChannelInfo.channelName = self.deviceName;
            } else {
                weakself.manager.currentDevice.name = self.deviceName;
            }
        }
        [weakself.container.navigationController popViewControllerAnimated:YES];
        [LCProgressHUD showMsg:@"livepreview_localization_success".lc_T];
        [LCProgressHUD hideAllHuds:nil];
    } failure:^(LCError *_Nonnull error) {
        [LCProgressHUD showMsg:error.errorMessage];
        [LCProgressHUD hideAllHuds:nil];
    }];
}
 
- (void)deleteDevice {
    weakSelf(self);
    [LCProgressHUD showHudOnView:nil];
    [LCDeviceManagerInterface unBindDeviceWithDevice:self.manager.currentDevice.deviceId success:^{
        //删除成功后返回设备列表
        [LCProgressHUD hideAllHuds:nil];
        [self.container.navigationController lc_popToViewController:@"LCDeviceListViewController" Filter:nil animated:YES];
        [LCProgressHUD showMsg:@"device_delete_success".lc_T];
        //删除本地的截图
        [[UIImageView new] lc_deleteThumbImageWithDeviceId:weakself.manager.currentDevice.deviceId ChannelId:weakself.manager.currentChannelInfo.channelId];
    } failure:^(LCError *_Nonnull error) {
        [LCProgressHUD hideAllHuds:nil];
        [LCProgressHUD showMsg:error.errorMessage];
    }];
}
 
- (void)dealloc {
    
}
 
@end