CNLiveCycleCell.m
6.34 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
//
// CNLiveCycleCell.m
// CNLiveCServiceModule
//
// Created by CNLive on 2021/11/27.
//
#import "CNLiveCycleCell.h"
#import "CNLiveSearchHotsCell.h"
#import "CNLiveMyServicesVC.h"
#import "CNLiveAllServiceVC.h"
#import "CNLiveServiceModel.h"
#import "CNLiveChineServiceCell.h"
#import "CNLiveServiceOrLookCell.h"
@interface CNLiveCycleCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *listCollectionView;
@property (nonatomic, strong) NSArray *dataSource;
@end
static NSString *HotListCellID = @"HotListCellID";
static NSString *ChineseServiceID = @"CNLiveChineServiceCell";
static NSString *CNServiceOrLookID = @"CNLiveServiceOrLookCell";
@implementation CNLiveCycleCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.contentView addSubview:self.listCollectionView];
[self makeSubViewsLayout];
}
return self;
}
-(void)makeSubViewsLayout
{
[super layoutSubviews];
[self.listCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.bottom.equalTo(self);
}];
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == self.dataSource.count) {
[CNLiveMyServicesVC myServiceVC];
}else if (indexPath.row == self.dataSource.count + 1){
[CNLiveAllServiceVC allServiceVCWithId:@"" title:@"全部服务"];
}else{
NSObject *model = self.dataSource[indexPath.row];
if ([model isKindOfClass:[CNCategoryModel class]]) {
CNCategoryModel *categoryModel = (CNCategoryModel *)model;
[CNLiveAllServiceVC allServiceVCWithId:categoryModel.id title:categoryModel.title];
}
if ([model isKindOfClass:[CNLiveSearchModel class]]) {
CNLiveSearchModel *searchModel = (CNLiveSearchModel *)model;
[CNLiveCServiceManagerBridge jumpServiceController:searchModel.id type:searchModel.type to:searchModel.to shopType:searchModel.shopType controller:[CNLiveCServiceManagerBridge viewControllerFromView:self]];
}
if ([model isKindOfClass:[CnLivePageContentModel class]]) {
[CNLiveCServiceManagerBridge jumpViewControllerType:CNCServiceJumpTypeGetPage param:[model mj_keyValues] controller:[CNLiveCServiceManagerBridge viewControllerFromView:self]];
}
}
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if ([self.model.title isEqualToString:@""]) {
return self.dataSource.count + 2;
}
return self.dataSource.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
if ([_model.title isEqualToString:@"中国服务号"]) {
CNLiveChineServiceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ChineseServiceID forIndexPath:indexPath];
cell.model = self.dataSource[indexPath.row];
return cell;
}else if ([_model.title isEqual:@"大家都在用"]){
CNLiveServiceOrLookCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CNServiceOrLookID forIndexPath:indexPath];
cell.model = self.dataSource[indexPath.row];
cell.type = CNLiveCellShowTypeLook;
return cell;
}else{
CNLiveSearchHotsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HotListCellID forIndexPath:indexPath];
if (indexPath.row < self.dataSource.count) {
cell.model = self.dataSource[indexPath.row];
}else if (indexPath.row == self.dataSource.count){
[cell.logoView setImage:[UIImage loadCServiceBundle:@"service_mine"]];
cell.titleLabel.text = @"我的服务";
[cell.titleLabel sizeToFit];
[cell setNeedsLayout];
}else{
[cell.logoView setImage:[UIImage loadCServiceBundle:@"service_more"]];
cell.titleLabel.text = @"更多服务";
[cell.titleLabel sizeToFit];
[cell setNeedsLayout];
}
return cell;
}
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if ([_model.title isEqualToString:@"大家都在用"]) {
return CGSizeMake(collectionView.width, (collectionView.height -40)/3);
}
return CGSizeMake(_model.layout.width, _model.layout.height);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
if ([_model.title isEqual:@"中国服务号"]) {
return UIEdgeInsetsMake(10, 5, 10, 5);
}
if ([_model.title isEqual:@""]) {
return UIEdgeInsetsMake(5, 0, 5, 0);
}
if ([_model.title isEqual:@"大家都在用"]) {
return UIEdgeInsetsMake(15, 0, 0, 0);
}
return UIEdgeInsetsMake(15, 15, 0, 15);
}
#pragma mark - Setting&&Getting
-(void)setModel:(CNLiveSearchHotsModel *)model
{
_model = model;
self.dataSource = model.lists;
}
- (void)setDataSource:(NSArray *)dataSource
{
_dataSource = dataSource;
[self.listCollectionView reloadData];
}
- (UICollectionView *)listCollectionView
{
if (!_listCollectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
_listCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_listCollectionView.scrollEnabled = NO;
_listCollectionView.backgroundColor = kWhiteColor;
_listCollectionView.collectionViewLayout = layout;
_listCollectionView.delegate = self;
_listCollectionView.dataSource = self;
_listCollectionView.backgroundColor = kClearColor;
_listCollectionView.showsVerticalScrollIndicator = NO;
[_listCollectionView registerClass:[CNLiveSearchHotsCell class] forCellWithReuseIdentifier:HotListCellID];
[_listCollectionView registerClass:[CNLiveChineServiceCell class] forCellWithReuseIdentifier:ChineseServiceID];
[_listCollectionView registerClass:[CNLiveServiceOrLookCell class] forCellWithReuseIdentifier:CNServiceOrLookID];
}
return _listCollectionView;
}
@end