CNLiveServiceVC.m
12.7 KB
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
//
// CNLiveServiceVC.m
// CNLiveNewTripartiteManagement
//
// Created by CNLive on 2021/11/22.
//
#import "CNLiveServiceVC.h"
#import "CNLiveMainSearch.h"
#import "CNLiveServiceSearchVC.h"
#import "CNLiveServicePresent.h"
#import "CNLiveServiceModel.h"
#import "CNLiveMyServicesVC.h"
#import "CNLiveSearchHeaderView.h"
#import "CNLiveGoodsOrVideoHeaderView.h"
#import "CNLiveServiceChinasCell.h"
#import "CNLiveServiceEpiCell.h"
#import "CNLiveServiceLookCell.h"
#import "CNLiveRecommendCell.h"
#import "CNLiveVideoRecommendCell.h"
#import "CNLiveCycleActiveCell.h"
static NSString *CNServiceChinaCellID = @"CNLiveServiceChinasCell";
static NSString *CNServiceEpiCellID = @"CNLiveServiceEpiCell";
static NSString *CNServiceLookCellID = @"CNLiveServiceLookCell";
static NSString *CNCycleActiveCellID = @"CNLiveCycleActiveCell";
static NSString *CNRecommendCellID = @"CNLiveRecommendCell";
static NSString *CNServiceheaderID = @"CNLiveSearchHeaderView";
static NSString *CNGoodsOrVideoheaderID = @"CNLiveGoodsOrVideoHeaderView";
@interface CNLiveServiceVC ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UIImageView *topBackView;//头部背景色
@property (nonatomic, strong) CNLiveMainSearch *searchView;//搜索栏目
@property (nonatomic, strong) NSArray *dataSource;//服务号数据
@property (nonatomic, strong) NSArray *pageListSource;
@property (nonatomic, strong) NSArray *hots;
@property (nonatomic, strong) UICollectionView *listCollectionView;
@end
@implementation CNLiveServiceVC
- (void)requestService{
if (![CNLiveNetworking isNetworking]) {
if (self.dataSource.count>0 && self.pageListSource.count>0) {
return;
}
[self showEmptyViewWithImage:[UIImage loadCServiceBundle:@"service_noNet"] text:@"网络开小差了,刷新试试" detailText:nil buttonTitle:@" 刷新 " buttonAction:@selector(requestService)];
self.emptyView.frame = CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop);
[self setCNAPIErrorEmptyView];
return;
}
dispatch_group_t requestGroup = dispatch_group_create();
dispatch_group_enter(requestGroup);
weakself
[CNLiveServicePresent requestServiceListResult:^(NSArray * _Nonnull dataArray, NSArray * _Nonnull hots) {
strongself
[self removeEmptyView];
self.dataSource = dataArray;
self.hots = hots;
dispatch_group_leave(requestGroup);
} error:^{
strongself
if (self.dataSource.count>0 && self.pageListSource.count>0) {
return;
}
[self showEmptyViewWithImage:[UIImage loadCServiceBundle:@"service_failure"] text:@"加载失败,请点击重试" detailText:nil buttonTitle:@" 重试 " buttonAction:@selector(requestService)];
self.emptyView.frame = CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop);
[self setCNAPIErrorEmptyView];
dispatch_group_leave(requestGroup);
}];
dispatch_group_enter(requestGroup);
[CNLiveServicePresent requesrServiceGetPageResult:^(NSArray * _Nonnull dataArray) {
weakSelf.pageListSource = dataArray;
dispatch_group_leave(requestGroup);
} error:^{
strongself
if (self.dataSource.count>0 && self.pageListSource.count>0) {
return;
}
[self showEmptyViewWithImage:[UIImage loadCServiceBundle:@"service_failure"] text:@"加载失败,请点击重试" detailText:nil buttonTitle:@" 重试 " buttonAction:@selector(requestService)];
self.emptyView.frame = CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop);
[self setCNAPIErrorEmptyView];
dispatch_group_leave(requestGroup);
}];
dispatch_group_notify(requestGroup, dispatch_get_main_queue(), ^{
strongself
if (self.dataSource.count>0&&self.pageListSource.count>0) {
[self.listCollectionView reloadData];
}
});
}
-(void)removeEmptyView
{
[self.emptyView removeFromSuperview];
self.emptyView = nil;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.topBackView];
[self.view sendSubviewToBack:self.topBackView];
[self.view addSubview:self.searchView];
[self.view addSubview:self.listCollectionView];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
[self requestService];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.topBackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
make.height.offset(159.5 *KScreenHeight / 667);
}];
[self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
if (self.mas_topLayoutGuide > 0) {
make.top.equalTo(self.mas_topLayoutGuide);
}else{
make.top.equalTo(self.view).offset(35.5);
}
make.left.equalTo(self.view).offset(10);
make.right.equalTo(self.view).offset(-10);
make.height.offset(36);
}];
[self.listCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.searchView.mas_bottom).offset(10);
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.mas_bottomLayoutGuide);
}];
}
#pragma mark - Action
- (void)seachPushTap
{
[CNLiveServiceSearchVC serviceSearchVC:self.hots];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if (section < self.dataSource.count) {
CNLiveSearchHotsModel *model = self.dataSource[section];
return model.lists.count;
}else {
return 1;
}
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return self.dataSource.count + self.pageListSource.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section < self.dataSource.count) {
CNLiveSearchHotsModel *model = self.dataSource[indexPath.section];
CNLiveServiceChinasCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CNServiceChinaCellID forIndexPath:indexPath];
cell.model = model.lists[indexPath.row];
return cell;
}else{
CNliveServicePageModel *model = self.pageListSource[indexPath.section - self.dataSource.count];
if ([model.blockName isEqualToString:@"疫情服务专区"]){
CNLiveServiceEpiCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CNServiceEpiCellID forIndexPath:indexPath];
cell.model = model;
return cell;
}else if ([model.blockName isEqualToString:@"大家都在用"]){
CNLiveServiceLookCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CNServiceLookCellID forIndexPath:indexPath];
cell.model = model;
return cell;
}else if ([model.blockName isEqualToString:@"轮播"]){
CNLiveCycleActiveCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CNCycleActiveCellID forIndexPath:indexPath];
cell.model = model;
return cell;
}
else{
CNLiveRecommendCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CNRecommendCellID forIndexPath:indexPath];
cell.model = model;
return cell;
}
}
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section < self.dataSource.count) {
CNLiveSearchHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:CNServiceheaderID forIndexPath:indexPath];
CNLiveSearchHotsModel *model = self.dataSource[indexPath.section];
header.type = CNServiceHeaderTypeService;
header.model = model.lists[indexPath.row];
return header;
}else{
CNLiveGoodsOrVideoHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:CNGoodsOrVideoheaderID forIndexPath:indexPath];
CNliveServicePageModel *model = self.pageListSource[indexPath.section - self.dataSource.count];
header.pageModel = model;
return header;
}
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section < self.dataSource.count) {
CNLiveSearchHotsModel *model = self.dataSource[indexPath.section];
return CGSizeMake(collectionView.width, model.cellHeight);
}else{
CNliveServicePageModel *model = self.pageListSource[indexPath.section - self.dataSource.count];
return CGSizeMake(collectionView.width, model.cellHeight);
}
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 0, 10, 0);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
if (section < self.dataSource.count) {
CNLiveSearchHotsModel *model = self.dataSource[section];
if ([model.title isEqualToString:@""]) {
return CGSizeMake(0, 0);
}
}else {
CNliveServicePageModel *model = self.pageListSource[section - self.dataSource.count];
if ([model.blockName isEqualToString:@"轮播"] ||[model.blockName isEqualToString:@"疫情服务专区"]||[model.blockName isEqualToString:@"大家都在用"]) {
return CGSizeMake(0, 0);
}
}
return CGSizeMake(collectionView.width, 40);
}
#pragma mark - Setting&&Getting
- (UIImageView *)topBackView
{
if (!_topBackView) {
_topBackView = [[UIImageView alloc] init];
[_topBackView setImage:[UIImage loadCServiceBundle:@"service_top"]];
}
return _topBackView;
}
- (CNLiveMainSearch *)searchView
{
if (!_searchView) {
_searchView = [[CNLiveMainSearch alloc] initWithType:CNSearchViewShowTypePush];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(seachPushTap)];
[_searchView addGestureRecognizer:tap];
}
return _searchView;
}
- (UICollectionView *)listCollectionView
{
if (!_listCollectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
_listCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_listCollectionView.backgroundColor = kWhiteColor;
_listCollectionView.collectionViewLayout = layout;
_listCollectionView.delegate = self;
_listCollectionView.dataSource = self;
_listCollectionView.backgroundColor = kClearColor;
_listCollectionView.showsVerticalScrollIndicator = NO;
[_listCollectionView registerClass:[CNLiveServiceChinasCell class] forCellWithReuseIdentifier:CNServiceChinaCellID];
[_listCollectionView registerClass:[CNLiveServiceEpiCell class] forCellWithReuseIdentifier:CNServiceEpiCellID];
[_listCollectionView registerClass:[CNLiveServiceLookCell class] forCellWithReuseIdentifier:CNServiceLookCellID];
[_listCollectionView registerClass:[CNLiveCycleActiveCell class] forCellWithReuseIdentifier:CNCycleActiveCellID];
[_listCollectionView registerClass:[CNLiveRecommendCell class] forCellWithReuseIdentifier:CNRecommendCellID];
[_listCollectionView registerClass:[CNLiveSearchHeaderView class] forSupplementaryViewOfKind:@"UICollectionElementKindSectionHeader" withReuseIdentifier:CNServiceheaderID];
[_listCollectionView registerClass:[CNLiveGoodsOrVideoHeaderView class] forSupplementaryViewOfKind:@"UICollectionElementKindSectionHeader" withReuseIdentifier:CNGoodsOrVideoheaderID];
}
return _listCollectionView;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end