JLChen
2021-11-04 1443556e9ccb1a19ed8e6710c16c8adc4d4f4fb3
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
//
//  Copyright © 2019 dahua. All rights reserved.
//
 
#import "LCDeviceListCell.h"
#import "LCDeviceListChannelCell.h"
 
 
@interface LCDeviceListCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
 
/// collection
@property (strong, nonatomic) UICollectionView *channelList;
 
/// collect布局
@property (strong, nonatomic) UICollectionViewFlowLayout *layout;
 
/// titleLab
@property (strong, nonatomic) UILabel *titleLab;
 
/// 云服务按钮
@property (strong, nonatomic) LCButton *cloudServiceIcon;
 
/// 默认图
@property (strong, nonatomic) UIImageView *defaultImageView;
 
/// 设置按钮
@property (strong, nonatomic) LCButton *setIcon;
 
/// emptyLabel
@property (strong, nonatomic) UILabel *emptyLabel;
 
 
@end
 
@implementation LCDeviceListCell
 
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
 
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupView];
        self.backgroundColor = [UIColor dhcolor_c43];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}
 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
 
    // Configure the view for the selected state
}
 
- (void)setupView {
    weakSelf(self);
    UIView *lineView = [UIView new];
    [self addSubview:lineView];
    lineView.backgroundColor = [UIColor dhcolor_c54];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(self);
        make.height.mas_equalTo(5);
    }];
    
    UILabel *titleLab = [UILabel new];
    [self.contentView addSubview:titleLab];
    self.titleLab = titleLab;
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(self).offset(15);
    }];
    
    LCButton *setIcon = [LCButton lcButtonWithType:LCButtonTypeCustom];
    self.setIcon = setIcon;
    [self.contentView addSubview:setIcon];
    [setIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).offset(-15);
        make.height.mas_equalTo(setIcon.mas_width);
        make.centerY.mas_equalTo(titleLab.mas_centerY);
    }];
    [setIcon setBackgroundImage:LC_IMAGENAMED(@"home_icon_device_setting") forState:UIControlStateNormal];
    setIcon.touchUpInsideblock = ^(LCButton * _Nonnull btn) {
        if (weakself.resultBlock) {
            weakself.resultBlock(weakself.deviceInfo, 0, 1);
        }
    };
    
    LCButton *cloudServiceIcon = [LCButton lcButtonWithType:LCButtonTypeCustom];
    self.cloudServiceIcon = cloudServiceIcon;
    cloudServiceIcon.hidden = YES;
    [self.contentView addSubview:cloudServiceIcon];
    [cloudServiceIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(setIcon.mas_left);
        make.height.mas_equalTo(cloudServiceIcon.mas_width);
        make.centerY.mas_equalTo(titleLab.mas_centerY);
    }];
    [cloudServiceIcon setBackgroundImage:LC_IMAGENAMED(@"home_icon_using") forState:UIControlStateNormal];
    cloudServiceIcon.touchUpInsideblock = ^(LCButton * _Nonnull btn) {
        if (weakself.resultBlock) {
            weakself.resultBlock(weakself.deviceInfo, 0, 2);
        }
    };
    
//    LCButton * playAll = [LCButton lcButtonWithType:LCButtonTypeCustom];
//    self.cloudServiceIcon = cloudServiceIcon;
//    [self.contentView addSubview:playAll];
//    [playAll mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(cloudServiceIcon.mas_left);
//        make.height.mas_equalTo(cloudServiceIcon.mas_width);
//        make.centerY.mas_equalTo(titleLab.mas_centerY);
//    }];
//    [playAll setBackgroundImage:LC_IMAGENAMED(@"home_icon_item_playall") forState:UIControlStateNormal];
    
 
    self.layout = [[UICollectionViewFlowLayout alloc] init];
    [self.layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    self.channelList = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:_layout];
    [self.contentView addSubview:self.channelList];
    [self.channelList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(45);
        make.left.mas_equalTo(titleLab);
        make.right.bottom.mas_equalTo(self).offset(-15);
    }];
    self.channelList.showsHorizontalScrollIndicator = NO;
    self.channelList.backgroundColor = [UIColor dhcolor_c00];
    self.channelList.dataSource = self;
    self.channelList.delegate = self;
    [self.channelList registerClass:[LCDeviceListChannelCell class] forCellWithReuseIdentifier:@"LCDeviceListChannelCell"];
    
    self.defaultImageView = [[UIImageView alloc] initWithImage:LC_IMAGENAMED(@"common_defaultcover_big")];
    [self.contentView addSubview:self.defaultImageView];
    [self.defaultImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.mas_equalTo(self.channelList);
    }];
    
    self.emptyLabel = [[UILabel alloc]init];
    self.emptyLabel.textColor = [UIColor dhcolor_c44];
    self.emptyLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.emptyLabel.text = @"home_empty_channel".lc_T;
    [self.defaultImageView addSubview:self.emptyLabel];
    [self.emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.centerY.mas_equalTo(self.defaultImageView.mas_centerY);
    }];
}
 
- (void)setDeviceInfo:(LCDeviceInfo *)deviceInfo {
    _deviceInfo = deviceInfo;
    self.titleLab.text = deviceInfo.name;
//    [self.cloudServiceIcon setHidden:deviceInfo.]
 
    if (deviceInfo.channels.count == 0) {
        self.defaultImageView.hidden = NO;
    } else {
        self.defaultImageView.hidden = YES;
        [self.channelList reloadData];
    }
    
    //增加设置按钮随通道个数
    //self.setIcon.hidden = deviceInfo.channels.count == 0 ? YES : NO;
    
    [self setNeedsLayout];
    [self setNeedsUpdateConstraints];
}
 
 
//MARK: - Private Methods
 
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (self.resultBlock) {
        self.resultBlock(self.deviceInfo, indexPath.item,0);
    }
}
 
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.deviceInfo.channels.count;
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LCDeviceListChannelCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LCDeviceListChannelCell" forIndexPath:indexPath];
    cell.index = indexPath.item;
    cell.deviceInfo = self.deviceInfo;
    return cell;
}
 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return [self getCollectionCellSize];
}
 
- (CGSize)getCollectionCellSize {
    if ([self.deviceInfo.catalog isEqualToString:@"NVR"]) {
        //多通道
        return CGSizeMake(250, 141);
    }
    return self.channelList.frame.size;
}
 
 
 
@end