CNLiveCMineInteViewController.m
11 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
//
// CNLiveCMineInteViewController.m
// CNLiveCMineModule
//
// Created by open on 2021/12/27.
//
#import "CNLiveCMineInteViewController.h"
#import "CNLiveCMineInteCollectionViewCell.h"
#import "CNLiveCMineInteHeaderCustomView.h"
#import "CNLiveCMineInteHeaderView.h"
#import "CNLiveCMineInteViewModel.h"
#import "CNLiveCMineInteModel.h"
@interface CNLiveCMineInteViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) NSMutableArray * dataArray;//总数据源
@property (nonatomic, strong) CNLiveCMineInteScoreModel * scoreModel; //签到数据
@property (nonatomic, strong) CNLiveCMineInteTaskListModel * taskModel;//任务列表及积分数据
@property (nonatomic, strong) CNLiveCMineInteListModel * announModel; //公告数据
@property (nonatomic, strong) CNLiveCMineInteListModel * activModel; //活动数据
@property (nonatomic, strong) CNLiveCMineInteHeaderView *headerView;//头视图
@property (nonatomic, strong) CNLiveNavigationBar * navigationBar;//导航栏
@property (nonatomic, strong) UICollectionView * mainCollectionView;//主界面
@property (nonatomic, strong) UIImageView * backView;
@end
@implementation CNLiveCMineInteViewController
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// self.navigationController.navigationBarHidden = YES;
[self reloadDataSource];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// self.navigationController.navigationBarHidden = NO;
}
-(BOOL)preferredNavigationBarHidden
{
return YES;
}
-(void)reloadDataSource
{
__weak typeof(self) weakSelf = self;
[QMUITips showLoadingInView:self.view];
[CNLiveCMineInteViewModel requestWithIntegraTaskWithSignMedthodForCompleterBlock:^(NSMutableArray * _Nonnull dataArray, NSString * _Nonnull errorMessage) {
[QMUITips hideAllTipsInView:weakSelf.view];
weakSelf.dataArray = dataArray;
weakSelf.scoreModel = ![dataArray[0] isKindOfClass:NSString.class]?dataArray[0]:nil;
weakSelf.taskModel = ![dataArray[1] isKindOfClass:NSString.class]?dataArray[1]:nil;
weakSelf.announModel = ![dataArray[2] isKindOfClass:NSString.class]?dataArray[2]:nil;
weakSelf.activModel = ![dataArray[3] isKindOfClass:NSString.class]?dataArray[3]:nil;
weakSelf.taskModel.from = weakSelf.isFrom;
weakSelf.taskModel.feedback = weakSelf.isFeedback;
[weakSelf.mainCollectionView reloadData];
}];
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:kCNLiveCMineInteTaskAddScoreRequestSuccessNotification object:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColorHex(0xffffff);
[self.view addSubview:self.navigationBar];
[self.view addSubview:self.backView];
[self.view addSubview:self.mainCollectionView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(successAddScoreNotification:) name:kCNLiveCMineInteTaskAddScoreRequestSuccessNotification object:nil];
}
-(void)successAddScoreNotification:(NSNotification *)note
{
NSInteger addScore = [note.userInfo[@"score"] integerValue];
NSInteger scored = [self.taskModel.integral integerValue];
self.taskModel.integral = [NSString stringWithFormat:@"%ld",scored + addScore];
[self.headerView setupWithScoreModel:self.scoreModel taskModel:self.taskModel announModel:self.announModel activModel:self.activModel];
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
if (@available(iOS 13.0, *)) {
return UIStatusBarStyleDarkContent;
} else {
return UIStatusBarStyleDefault;
}
}
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.activModel.list.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CNLiveCMineInteCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([CNLiveCMineInteCollectionViewCell class]) forIndexPath:indexPath];
CNLiveCMineInteListSubModel * taskModel = self.activModel.list[indexPath.row];
cell.taskModel = taskModel;
return cell;
}
-(UIEdgeInsets)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(5, 5, 0, 5);
}
-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
return CGSizeMake(kScreenWidth, self.announModel ? 310 : 260);
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString*)kind atIndexPath:(NSIndexPath*)indexPath {
// 判断返回表头类型 还是表尾类型
if([kind isEqualToString:UICollectionElementKindSectionHeader]) {
CNLiveCMineInteHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass(CNLiveCMineInteHeaderView.class) forIndexPath:indexPath];
headerView.backgroundColor= [UIColor clearColor];
[headerView setupWithScoreModel:self.scoreModel taskModel:self.taskModel announModel:self.announModel activModel:self.activModel];
__weak typeof(self) weakSelf = self;
[headerView setClickActionBlock:^(CNLiveCMineInteScoreModel * _Nonnull scoreModel, CNLiveCMineInteTaskListModel * _Nonnull taskModel, CNLiveCMineInteListModel * _Nonnull announModel, CNLiveCMineInteHeaderClick headerClick) {
if (headerClick == CNLiveCMineInteHeaderClickDetail) {
CNLiveCMineInteDetailViewController * inteView = [[CNLiveCMineInteDetailViewController alloc] initWithInte:!CNLiveStringIsEmpty(taskModel.integral)?taskModel.integral:@"0"];
[weakSelf.navigationController pushViewController:inteView animated:YES];
} else if (headerClick == CNLiveCMineInteHeaderClickAnnotation) {
CNLiveCMineInteAnnouListViewController * annouView = [[CNLiveCMineInteAnnouListViewController alloc] initWithAnnouModel:announModel];
[weakSelf.navigationController pushViewController:annouView animated:YES];
} else {
NSString * url = cn_API_Managemall(@"/html/select_good/1/#/pointsMall");
[[CNLiveCMineService shareMineProtocol] pushCMineInteContentForCMainWebViewWithURL:url statue:CNLiveCMineIntePushWebViewStatueMall];
}
}];
self.headerView = headerView;
return headerView;
}
return nil;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
CNLiveCMineInteListSubModel * model = self.activModel.list[indexPath.row];
if ([model.contentId isEqualToString:@"21"]) {//跳转原生
CNLiveCMineInteTaskViewController * taskView = [[CNLiveCMineInteTaskViewController alloc] initWithTaskModel:self.taskModel];
[self.navigationController pushViewController:taskView animated:YES];
}else{
[[CNLiveCMineService shareMineProtocol] pushCMineInteContentForCMainWebViewWithURL:model.thirdUrl statue:CNLiveCMineIntePushWebViewStatueTask];
}
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y;
self.mainCollectionView.backgroundColor = [UIColor colorWithWhite:1 alpha:(offsetY/200.0f)];
}
#pragma mark = getter
-(UICollectionView *)mainCollectionView
{
if (!_mainCollectionView) {
CGFloat item_w = (KScreenWidth - 30)/3;
UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(item_w, item_w * 1.25);
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
_mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, KScreenWidth, KScreenHeight - kNavigationBarHeight - kVerticalBottomSafeHeight) collectionViewLayout:layout];
_mainCollectionView.delegate = self;
_mainCollectionView.dataSource = self;
_mainCollectionView.backgroundColor = [UIColor clearColor];
_mainCollectionView.showsVerticalScrollIndicator = YES;
_mainCollectionView.showsHorizontalScrollIndicator = NO;
[_mainCollectionView registerClass:[CNLiveCMineInteCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass(CNLiveCMineInteCollectionViewCell.class)];
[_mainCollectionView registerClass:[CNLiveCMineInteHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass(CNLiveCMineInteHeaderView.class)];
}
return _mainCollectionView;
}
- (CNLiveNavigationBar *)navigationBar {
if (!_navigationBar) {
_navigationBar = [CNLiveNavigationBar navigationBar];
_navigationBar.leftImage = [CNLiveCMineService imageWithMineName:@"c_mine_skip_push_back"];
__weak typeof(self) weakSelf = self;
_navigationBar.lineHidden = YES;
_navigationBar.backgroundColor = UIColorHex(0xFFE9EA);
_navigationBar.onClickLeftButton = ^{
[weakSelf.navigationController popViewControllerAnimated:YES];
};
_navigationBar.title.text = @"我的积分";
_navigationBar.right.hidden = NO;
_navigationBar.rightImage = [CNLiveCMineService imageWithMineName:@"c_mine_skip_push_more"];
_navigationBar.right.frame = CGRectMake(KScreenWidth - 44, kStatusHeight, 44, 44);
[_navigationBar.right setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[_navigationBar.right setUserInteractionEnabled:YES];
_navigationBar.onClickRightButton = ^{
[CNLiveCMineInteHeaderCustomView showHeaderAlertViewWithCurrentVC:weakSelf CompleterBlock:^(CNLiveCMineInteHeaderClick headerClick) {
if (headerClick == CNLiveCMineInteHeaderClickRule) {
[[CNLiveCMineService shareMineProtocol] pushCMineInteContentForCMainWebViewWithURL:@"" statue:CNLiveCMineIntePushWebViewStatueRule];
}
if (headerClick == CNLiveCMineInteHeaderClickService) {
[[CNLiveCMineService shareMineProtocol] pushCMineInteContentForCMainPlatFromCurrentVC:weakSelf];
}
}];
};
}
return _navigationBar;
}
-(UIImageView *)backView
{
if (!_backView) {
_backView = [[UIImageView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, kScreenWidth, 200)];
_backView.contentMode = UIViewContentModeScaleAspectFill;
_backView.clipsToBounds = YES;
_backView.backgroundColor = [UIColor whiteColor];
_backView.image = [CNLiveCMineService imageWithMineName:@"c_mine_content_header_back_groud"];
}
return _backView;
}
@end