JLChen
2021-10-28 e96683081abd5c1a94608dd33d092d8f45371cd6
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
//
//  Copyright © 2020 dahua. All rights reserved.
//
 
#import "LCDeviceSettingViewController.h"
 
@interface LCDeviceSettingViewController ()
 
/// 列表
@property (strong, nonatomic) UITableView *listView;
 
/// persenter
@property (strong, nonatomic) LCDeviceSettingPersenter *persenter;
 
@end
 
@implementation LCDeviceSettingViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.persenter.style = self.style;
    if (self.style == LCDeviceSettingStyleDeviceNameEdit) {
        UIGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTap:)];
        [self.view addGestureRecognizer:tap];
    }
    [self setupView];
}
 
- (void)viewTap:(UITapGestureRecognizer *)tap{
    [super viewTap:tap];
    self.persenter.endEdit = YES;
}
 
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self.persenter stopCheckUpdate];
}
 
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.listView reloadData];
    weakSelf(self);
    if (self.style == LCDeviceSettingStyleDeviceNameEdit) {
        [self lcCreatNavigationBarWith:LCNAVIGATION_STYLE_SUBMIT buttonClickBlock:^(NSInteger index) {
            if (index==0) {
                [weakself.navigationController popViewControllerAnimated:YES];
            }else{
                [self.view endEditing:YES];
                [weakself.persenter modifyDevice];
            }
        }];
        [[self lc_getRightBtn].KVOController observe:self.persenter keyPath:@"deviceName" options:NSKeyValueObservingOptionNew block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
               if ([NSString stringWithFormat:@"%@",change[@"new"]].length>0) {
                   [self lc_getRightBtn].enabled = YES;
               }else{
                   [self lc_getRightBtn].enabled = NO;
               }
           }];
    } else {
         [self lcCreatNavigationBarWith:LCNAVIGATION_STYLE_DEFAULT buttonClickBlock:nil];
    }
 
}
 
- (LCDeviceSettingPersenter *)persenter {
    if (!_persenter) {
        _persenter = [LCDeviceSettingPersenter new];
        _persenter.container = self;
    }
    return _persenter;
}
 
- (void)setupView {
    weakSelf(self);
    self.listView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
    self.listView.dataSource = self.persenter;
    self.listView.tag = 999;
    self.listView.delegate = self.persenter;
    [self.listView registerClass:NSClassFromString(@"LCDeviceSwitchCell") forCellReuseIdentifier:@"LCDeviceSwitchCell"];
    [self.listView registerClass:NSClassFromString(@"UITableViewCell") forCellReuseIdentifier:@"UITableViewCell"];
    [self.listView registerNib:[UINib nibWithNibName:@"LCDeviceSettingArrowCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"LCDeviceSettingArrowCell"];
    [self.listView registerNib:[UINib nibWithNibName:@"LCDeviceSettingSubtitleCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"LCDeviceSettingSubtitleCell"];
    [self.view addSubview:self.listView];
    self.listView.rowHeight = UITableViewAutomaticDimension;
    self.listView.estimatedRowHeight = 100.0f;
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    [self.listView.KVOController observe:self.persenter keyPath:@"needReload" options:NSKeyValueObservingOptionNew block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
        [weakself.listView reloadData];
    }];
    
    LCButton * deleteBtn = [LCButton lcButtonWithType:LCButtonTypeMinor];
    [self.view addSubview:deleteBtn];
    [deleteBtn setTitle:@"mobile_common_delete".lc_T forState:UIControlStateNormal];
    [deleteBtn setTitleColor:[UIColor dhcolor_c30] forState:UIControlStateNormal];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.height.mas_equalTo(45);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-20);
    }];
    
    //设置主界面判断,乐橙设备判断,多通道详情判断
    if (self.style == LCDeviceSettingStyleMainPage) {
        if (self.persenter.manager.isbindFromLeChange) {
            deleteBtn.hidden = YES;
        } else {
            if (self.persenter.manager.currentDevice.channels.count > 1 && self.persenter.manager.currentChannelIndex > -1) {
                deleteBtn.hidden = YES;
            } else {
                deleteBtn.hidden = NO;
            }
        }
    } else {
        deleteBtn.hidden = YES;
    }
    deleteBtn.touchUpInsideblock = ^(LCButton * _Nonnull btn) {
        [LCOCAlertView lc_ShowAlertWith:@"Alert_Title_Notice".lc_T Detail:@"setting_device_delete_alert".lc_T ConfirmTitle:@"Alert_Title_Button_Confirm".lc_T CancleTitle:@"Alert_Title_Button_Cancle".lc_T Handle:^(BOOL isConfirmSelected) {
            if (isConfirmSelected) {
                 [weakself.persenter deleteDevice];
            }
        }];
        
    };
}
 
- (void)dealloc {
 
}
 
@end