JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
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
//
//  Copyright © 2020 dahua. All rights reserved.
//
 
#import "LCVideotapeListViewController.h"
#import "LCVideotapePersenter.h"
#import "LCVideotapeListDateControl.h"
#import <LCBaseModule/UIScrollView+Tips.h>
 
@interface LCVideotapeListViewController ()
 
///底部滑动视图
@property (nonatomic, strong) UIScrollView *backgroundScrlooView;
 
///日期选择器
@property (nonatomic, strong) LCVideotapeListDateControl *dateControl;
 
///下载按钮
@property (nonatomic, strong) LCButton *deleteBtn;
 
///persenter
@property (nonatomic, strong) LCVideotapePersenter *persenter;
 
@end
 
@implementation LCVideotapeListViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self configListenAction];
    [self drawNavi];
    [self changeLoadSourceWithSelect:self.defaultType];
    
}
 
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self lcCreatNavigationBarWith:LCNAVIGATION_STYLE_CLEARWITHLINE buttonClickBlock:nil];
}
 
- (LCVideotapePersenter *)persenter {
    if (!_persenter) {
        _persenter = [LCVideotapePersenter new];
        _persenter.videoListPage = self;
    }
    return _persenter;
}
 
- (LCVideotapeListDateControl *)dateControl {
    if (!_dateControl) {
        _dateControl = [LCVideotapeListDateControl new];
        [self.view addSubview:_dateControl];
        weakSelf(self);
        [_dateControl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(kNavBarAndStatusBarHeight);
            make.left.mas_equalTo(weakself.view.mas_left);
            make.width.mas_equalTo(weakself.view);
            make.height.mas_equalTo(35);
        }];
    }
    return _dateControl;
}
 
- (UIScrollView *)backgroundScrlooView {
    if (!_backgroundScrlooView) {
        _backgroundScrlooView = [UIScrollView new];
        [self.view addSubview:_backgroundScrlooView];
        weakSelf(self);
        [_backgroundScrlooView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(weakself.view);
            make.top.mas_equalTo(weakself.dateControl.mas_bottom);
            make.bottom.mas_equalTo(self.view.mas_bottom).offset(-kBottomSafeHeight);
        }];
        _backgroundScrlooView.delegate = self.persenter;
        _backgroundScrlooView.pagingEnabled = YES;
        _backgroundScrlooView.showsHorizontalScrollIndicator = NO;
    }
    return _backgroundScrlooView;
}
 
- (UICollectionView *)cloudVideoList {
    if (!_cloudVideoList) {
        weakSelf(self);
        _cloudVideoList = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:[self getCollectionViewFlow]];
        _cloudVideoList.tag = 1000;
        _cloudVideoList.dataSource = self.persenter;
        _cloudVideoList.delegate = self.persenter;
        [_cloudVideoList registerClass:NSClassFromString(@"LCVideotapeListHeardView") forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"LCVideotapeListHeardView"];
        [self.backgroundScrlooView addSubview:_cloudVideoList];
        [_cloudVideoList mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.mas_equalTo(weakself.backgroundScrlooView);
            make.width.mas_equalTo(weakself.view);
            make.height.mas_equalTo(weakself.backgroundScrlooView.mas_height);
        }];
        [_cloudVideoList lc_setEmyptImageName:@"common_pic_novideotape" andDescription:@"video_module_none_record".lc_T];
        [_cloudVideoList registerNib:[UINib nibWithNibName:@"LCVideotapeListCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"LCVideotapeListCell"];
//        if (![self.persenter.videoManager.currentChannelInfo.storageStrategyStatus isEqualToString:@"using"]) {
//             [_cloudVideoList lc_setEmyptImageName:@"common_pic_novideotape" andDescription:@"device_manager_no_cloud_storage".lc_T];
//        }else{
//            _cloudVideoList.mj_header = [LCRefreshHeader headerWithRefreshingBlock:^{
//                [weakself.persenter refreshCloudVideoListWithDate:weakself.dateControl.nowDate];
//            }];
//            _cloudVideoList.mj_footer = [LCRefreshFooter footerWithRefreshingBlock:^{
//                [weakself.persenter loadMoreCloudVideoListWithDate:weakself.dateControl.nowDate];
//            }];
//        }
        _cloudVideoList.mj_header = [LCRefreshHeader headerWithRefreshingBlock:^{
            [weakself.persenter refreshCloudVideoListWithDate:weakself.dateControl.nowDate];
        }];
        _cloudVideoList.mj_footer = [LCRefreshFooter footerWithRefreshingBlock:^{
            [weakself.persenter loadMoreCloudVideoListWithDate:weakself.dateControl.nowDate];
        }];
        _cloudVideoList.backgroundColor = [UIColor dhcolor_c54];
    }
    return _cloudVideoList;
}
 
- (UICollectionView *)localVideoList {
    if (!_localVideoList) {
        weakSelf(self);
        _localVideoList = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:[self getCollectionViewFlow]];
        _localVideoList.tag = 1001;
        _localVideoList.dataSource = self.persenter;
        _localVideoList.delegate = self.persenter;
        [_localVideoList registerClass:NSClassFromString(@"LCVideotapeListHeardView") forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"LCVideotapeListHeardView"];
        [self.backgroundScrlooView addSubview:_localVideoList];
        [_localVideoList mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_equalTo(weakself.backgroundScrlooView);
            make.left.mas_equalTo(weakself.cloudVideoList.mas_right);
            make.width.mas_equalTo(weakself.view);
            make.height.mas_equalTo(weakself.backgroundScrlooView.mas_height);
        }];
        [self.backgroundScrlooView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(weakself.localVideoList.mas_right);
        }];
        _localVideoList.backgroundColor = [UIColor dhcolor_c54];
        [_localVideoList lc_setEmyptImageName:@"common_pic_novideotape" andDescription:@"video_module_none_record".lc_T];
        [_localVideoList registerNib:[UINib nibWithNibName:@"LCVideotapeListCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"LCVideotapeListCell"];
        _localVideoList.mj_header = [LCRefreshHeader headerWithRefreshingBlock:^{
            [weakself.persenter refreshLocalVideoListWithDate:weakself.dateControl.nowDate];
        }];
        _localVideoList.mj_footer = [LCRefreshFooter footerWithRefreshingBlock:^{
            [weakself.persenter loadMoreLocalVideoListWithDate:weakself.dateControl.nowDate];
        }];
    }
    return _localVideoList;
}
 
- (void)changeLoadSourceWithSelect:(NSInteger)select {
    CGPoint point = CGPointMake(0, 0);
    if (select != 0) {
        point.x = SCREEN_WIDTH;       //选择本地录像
        self.persenter.isCloudMode = NO;
        [self.persenter refreshLocalVideoListWithDate:nil];
    }else{
        self.persenter.isCloudMode = YES;
        [self.persenter refreshCloudVideoListWithDate:nil];
    }
    [self.backgroundScrlooView layoutIfNeeded];
    [self.backgroundScrlooView setContentOffset:point animated:YES];
 
}
 
- (void)drawNavi {
    weakSelf(self);
    LCSegmentController *segment = [LCSegmentController segmentWithFrame:CGRectMake(0, kStatusBarHeight, 150, 30) DefaultSelect:self.defaultType Items:@[@"play_module_cloud_record".lc_T, @"play_module_device_record".lc_T] SelectedBlock:^(NSUInteger index) {
        [weakself changeLoadSourceWithSelect:index];
    }];
    self.segment = segment;
    [self.view addSubview:segment];
    segment.center = CGPointMake(SCREEN_WIDTH / 2.0, segment.center.y);
    [segment.KVOController observe:self.persenter keyPath:@"isEdit" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
        segment.enable = ![change[@"new"] boolValue];
    }];
 
    LCButton *leftBtn = [LCButton lcButtonWithType:LCButtonTypeCustom];
    [self.view addSubview:leftBtn];
    [leftBtn setTintColor:[UIColor dhcolor_c60]];
    [leftBtn setImage:LC_IMAGENAMED(@"nav_back") forState:UIControlStateNormal];
    [leftBtn setTitleColor:[UIColor dhcolor_c10] forState:UIControlStateSelected];
    [leftBtn setTitleColor:[UIColor dhcolor_c10] forState:UIControlStateNormal];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(segment.mas_centerY);
        make.left.mas_equalTo(weakself.view).offset(15);
    }];
 
    leftBtn.touchUpInsideblock = ^(LCButton *_Nonnull btn) {
        if (self.persenter.isEdit) {
            //执行全选操作
            btn.selected = !btn.isSelected;
            self.persenter.isSelectAll = !self.persenter.isSelectAll;
        } else {
            [weakself.navigationController popViewControllerAnimated:YES];
        }
    };
    [leftBtn.KVOController observe:self.persenter keyPath:@"isEdit" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
        if ([change[@"new"] boolValue]) {
            //如果进入编辑
            [leftBtn setTitle:@"SelectAll".lc_T forState:UIControlStateNormal];
            [leftBtn setTitle:@"CancelSelectAll".lc_T forState:UIControlStateSelected];
            [leftBtn setImage:nil forState:UIControlStateNormal];
        } else {
            leftBtn.selected = NO;//完成时,结束全部选中状态
            [leftBtn setTitle:nil forState:UIControlStateNormal];
            [leftBtn setTitle:nil forState:UIControlStateSelected];
            [leftBtn setImage:LC_IMAGENAMED(@"nav_back") forState:UIControlStateNormal];
        }
    }];
 
    LCButton *rightBtn = [LCButton lcButtonWithType:LCButtonTypeCustom];
    [rightBtn setTitle:@"More_MyFamily_EditBtnTitle_Edit".lc_T forState:UIControlStateNormal];
    [rightBtn setTitle:@"common_done".lc_T forState:UIControlStateSelected];
    [rightBtn setTitleColor:[UIColor dhcolor_c10] forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor dhcolor_c10] forState:UIControlStateSelected];
    [self.view addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view.mas_right).offset(-15);
        make.centerY.mas_equalTo(segment.mas_centerY);
    }];
    rightBtn.touchUpInsideblock = ^(LCButton *_Nonnull btn) {
        weakself.persenter.isEdit = !btn.isSelected;
        btn.selected = !btn.isSelected;
    };
    [rightBtn.KVOController observe:self.persenter keyPath:@"isCloudMode" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
        rightBtn.hidden = ![change[@"new"] boolValue];
    }];
}
 
- (LCButton *)deleteBtn {
    if (!_deleteBtn) {
        weakSelf(self);
        _deleteBtn = [LCButton lcButtonWithType:LCButtonTypeMinor];
        [_deleteBtn setTitle:@"mobile_common_delete".lc_T forState:UIControlStateNormal];
        [_deleteBtn setImage:LC_IMAGENAMED(@"common_icon_deleteall") forState:UIControlStateNormal];
        [self.view addSubview:_deleteBtn];
        [_dateControl.KVOController observe:self.persenter keyPath:@"isEdit" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
            self->_dateControl.enable = ![change[@"new"] boolValue];
        }];
        _deleteBtn.touchUpInsideblock = ^(LCButton * _Nonnull btn) {
            [DHAlertController showWithTitle:@"setting_device_delete_alert".lc_T message:@"" cancelButtonTitle:@"common_cancel".lc_T otherButtonTitle:@"common_confirm".lc_T handler:^(NSInteger index) {
                if (index == 1) {
                    [weakself.persenter deleteCloudViewotape];
                }
            }];
        };
    }
    return _deleteBtn;
}
 
- (UICollectionViewFlowLayout *)getCollectionViewFlow {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 3;
    layout.itemSize = CGSizeMake((SCREEN_WIDTH - 30) / 4.0, (SCREEN_WIDTH - 30) / 4.0 / 0.75);
    return layout;
}
 
- (void)configListenAction {
    weakSelf(self);
    self.dateControl.result = ^(NSDate *_Nonnull date) {
        if (weakself.backgroundScrlooView.contentOffset.x == 0) {
            //当前在云视频
            [weakself.persenter refreshCloudVideoListWithDate:date];
        } else {
            [weakself.persenter refreshLocalVideoListWithDate:date];
        }
    };
    [self.localVideoList.KVOController observe:self.persenter keyPath:@"localVideoArray" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
        [weakself.localVideoList reloadData];
    }];
    [self.cloudVideoList.KVOController observe:self.persenter keyPath:@"cloudVideoArray" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
        [weakself.cloudVideoList reloadData];
    }];
    [self.KVOController observe:self.persenter keyPath:@"isEdit" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
        weakself.backgroundScrlooView.scrollEnabled = !weakself.backgroundScrlooView.scrollEnabled;
        if ([change[@"new"] boolValue]) {
            //进入编辑,展示删除
            self.deleteBtn.hidden = NO;
            self.dateControl.enable = NO;
            [self.deleteBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.mas_equalTo(weakself.view);
                make.height.mas_equalTo(50);
            }];
            [self.backgroundScrlooView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(weakself.view).offset(-50);
            }];
        } else {
            self.dateControl.enable = YES;
            self.deleteBtn.hidden = YES;
            [self.deleteBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.mas_equalTo(weakself.view);
                make.height.mas_equalTo(0);
            }];
            [self.backgroundScrlooView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(weakself.view).offset(0);
            }];
        }
        [UIView animateWithDuration:0.3 animations:^{
            [weakself.view updateConstraints];
        }];
    }];
}
 
@end