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
202
203
204
205
206
207
208
209
//
//  Copyright © 2020 dahua. All rights reserved.
//
 
#import "LCVideoHistoryView.h"
#import "LCUIKit.h"
#import "LCVideotapeHistoryCell.h"
#import <LCBaseModule/DHActivityIndicatorView.h>
#import "LCDeviceVideoManager.h"
 
@interface LCVideoHistoryView ()<UICollectionViewDelegate,UICollectionViewDataSource>
 
/// 云录像按钮
@property (strong, nonatomic) LCButton *cloudBtn;
 
/// 本地录像按钮
@property (strong, nonatomic) LCButton *localBtn;
 
///录像列表
@property (strong,nonatomic)UICollectionView * videotapeList;
 
///录像数据
@property (strong,nonatomic)NSMutableArray * dataArray;
 
///录像数据
@property (strong,nonatomic)LCDeviceVideoManager * manager;
 
///错误展示页面
@property (strong,nonatomic)UIView * errorView;
 
///错误展示页面
@property (strong,nonatomic)DHActivityIndicatorView * loadingView;
 
@end
 
@implementation LCVideoHistoryView
 
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupView];
        [self startAnimation];
    }
    return self;
}
 
-(void)setupView{
    weakSelf(self);
    self.backgroundColor = [UIColor dhcolor_c43];
    self.cloudBtn = [LCButton lcButtonWithType:LCButtonTypeCustom];
    [self addSubview:self.cloudBtn];
    self.cloudBtn.selected = YES;
    [self.cloudBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top).offset(10);
        make.left.mas_equalTo(self.mas_left).offset(80);
        make.width.mas_equalTo(SCREEN_WIDTH/2-80);
    }];
    [self.cloudBtn setTitle:@"play_module_cloud_record".lc_T forState:UIControlStateNormal];
    [self.cloudBtn setImage:LC_IMAGENAMED(@"timeline_icon_cloudvideo_normal") forState:UIControlStateNormal];
    [self.cloudBtn setImage:LC_IMAGENAMED(@"timeline_icon_cloudvideo_selected") forState:UIControlStateSelected];
    [self.cloudBtn setTitleColor:[UIColor dhcolor_c10] forState:UIControlStateSelected];
    self.cloudBtn.titleLabel.font = [UIFont lcFont_t4];
    [self.cloudBtn setTitleColor:[UIColor dhcolor_c40] forState:UIControlStateNormal];
    [self.cloudBtn.KVOController observe:self keyPath:@"isCurrentCloud" options:NSKeyValueObservingOptionNew block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
        self.cloudBtn.selected = [change[@"new"] boolValue];
    }];
    self.isCurrentCloud = YES;
    self.cloudBtn.touchUpInsideblock = ^(LCButton * _Nonnull btn) {
        weakself.isCurrentCloud = YES;
        if (weakself.dataSourceChange) {
            weakself.dataSourceChange(0);
        }
    };
    
    self.localBtn = [LCButton lcButtonWithType:LCButtonTypeCustom];
    [self addSubview:self.localBtn];
    [self.localBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top).offset(10);
        make.right.mas_equalTo(self.mas_right).offset(-80);
        make.width.mas_equalTo(SCREEN_WIDTH/2-80);
    }];
    self.localBtn.titleLabel.font = [UIFont lcFont_t4];
    [self.localBtn setTitle:@"play_module_device_record".lc_T forState:UIControlStateNormal];
    [self.localBtn setImage:LC_IMAGENAMED(@"timeline_icon_localvideo_normal") forState:UIControlStateNormal];
    [self.localBtn setImage:LC_IMAGENAMED(@"timeline_icon_localvideo_selected") forState:UIControlStateSelected];
    [self.localBtn setTitleColor:[UIColor dhcolor_c10] forState:UIControlStateSelected];
    [self.localBtn setTitleColor:[UIColor dhcolor_c40] forState:UIControlStateNormal];
    [self.localBtn.KVOController observe:self keyPath:@"isCurrentCloud" options:NSKeyValueObservingOptionNew block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
        self.localBtn.selected = ![change[@"new"] boolValue];
    }];
    self.localBtn.touchUpInsideblock = ^(LCButton * _Nonnull btn) {
        weakself.isCurrentCloud = NO;
        if (weakself.dataSourceChange) {
            weakself.dataSourceChange(1);
        }
    };
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake((SCREEN_WIDTH - 15)/3.0, 80.0);
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    self.videotapeList = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:layout];
    [self addSubview:self.videotapeList];
    self.videotapeList.dataSource = self;
    self.videotapeList.delegate = self;
    self.videotapeList.hidden = YES;
    self.videotapeList.showsHorizontalScrollIndicator = NO;
    self.videotapeList.backgroundColor = [UIColor dhcolor_c43];
    [self.videotapeList registerNib:[UINib nibWithNibName:@"LCVideotapeHistoryCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"LCVideotapeHistoryCell"];
    [self.videotapeList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.cloudBtn.mas_bottom).offset(10);
        make.bottom.mas_equalTo(self.mas_bottom);
        make.right.left.mas_equalTo(self);
        make.height.mas_equalTo(80);
    }];
}
-(LCDeviceVideoManager *)manager{
    if (!_manager) {
        _manager = [LCDeviceVideoManager manager];
    }
    return _manager;
}
 
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count + 1;
}
 
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    LCVideotapeHistoryCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LCVideotapeHistoryCell" forIndexPath:indexPath];
    if (indexPath.item==self.dataArray.count) {
        cell.isMore = YES;
    }else{
        id item = self.dataArray[indexPath.item];
        cell.isMore = NO;
        cell.detail = [[NSString stringWithFormat:@"%@",[item valueForKey:@"beginTime"]] componentsSeparatedByString:@" "][1];
        if ([item isKindOfClass:[LCCloudVideotapeInfo class]]) {
            LCCloudVideotapeInfo * info = (LCCloudVideotapeInfo *)item;
            [cell loadVideotapImage:info.thumbUrl DeviceId:self.manager.currentDevice.deviceId Key:self.manager.currentPsk];
        }else{
            [cell loadVideotapImage:nil DeviceId:self.manager.currentDevice.deviceId Key:self.manager.currentPsk];
        }
    }
   
    return cell;
}
 
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    id info = nil;
    if (indexPath.item<self.dataArray.count) {
        info = self.dataArray[indexPath.item];
    }
    if (self.historyClickBlock) {
        self.historyClickBlock(info,(self.isCurrentCloud==YES?0:1));
    }
}
 
//MARK: - Public Methods
-(void)reloadData:(NSMutableArray *)dataArys{
    if (!self.videotapeList||dataArys.count==0) {
        return;
    }
    self.videotapeList.hidden = NO;
    [self stopAnimation];
    self.dataArray = dataArys;
    [self.videotapeList reloadData];
}
 
-(void)setupErrorView:(UIView *)errorView{
    [self _clearErrorView];
    [self addSubview:errorView];
    self.errorView = errorView;
    self.videotapeList.hidden = YES;
    [self.errorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(10);
        make.top.mas_equalTo(self.cloudBtn.mas_bottom).offset(20);
        make.bottom.right.mas_equalTo(self).offset(-10);
    }];
    [self stopAnimation];
}
 
-(void)_clearErrorView{
    if (self.errorView) {
        [self.errorView removeFromSuperview];
    }
}
 
-(void)startAnimation{
    [self _clearErrorView];
    [self.loadingView startAnimating];
}
 
-(void)stopAnimation{
    [self.loadingView stopAnimating];
    [self.loadingView removeFromSuperview];
    self.loadingView = nil;
}
 
-(DHActivityIndicatorView *)loadingView{
    if (!_loadingView) {
        _loadingView = [[DHActivityIndicatorView alloc] init];
        [_loadingView startAnimating];
        [self addSubview:_loadingView];
        [_loadingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.mas_centerX);
            make.centerY.mas_equalTo(self.mas_centerY);
        }];
    }
    return _loadingView;
}
@end