CNLIVEViewController.m
5.57 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
//
// CNLIVEViewController.m
// CNLiveWitnessVideoModule
//
// Created by dawanzi on 04/03/2020.
// Copyright (c) 2020 dawanzi. All rights reserved.
//
#import "CNLIVEViewController.h"
#import "CNLiveEnvironment.h"
#import "CNLiveNetworking.h"
#import "NSString+CNLiveExtension.h"
#import "CNLiveBaseKit.h"
#import "CNBWitnessListModel.h"
#import "MJExtension.h"
#import "CNBWitnessListController.h"
#import "CNBWitnessVideoPlayProtocol.h"
#import <CNLiveBeeHive/BeeHive.h>
@interface CNLIVEViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) NSDictionary *data;
@property(nonatomic, copy) NSString *type;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@end
@implementation CNLIVEViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setUPCollectionView];
[self getWitnessListDataTosid:@"10511059" page:1 pageSize:10 type:@"0"];
self.dataSource = [NSMutableArray array];
}
- (void)setUPCollectionView {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
CGFloat itemWidth = (KScreenWidth - 40) / 3;
//设置单元格大小
layout.itemSize = CGSizeMake(itemWidth, itemWidth);
//最小行间距(默认为10)
layout.minimumLineSpacing = 10;
//最小item间距(默认为10)
layout.minimumInteritemSpacing = 10;
//设置UICollectionView的滑动方向
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
//设置UICollectionView的间距
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
_collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 40, KScreenWidth, KScreenHeight) collectionViewLayout:layout];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
//遵循CollectionView的代理方法
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.backgroundColor = [UIColor clearColor];
//注册cell
[self.view addSubview:self.collectionView];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCell" forIndexPath:indexPath];
if (!cell) {
cell = [[UICollectionViewCell alloc]init];
}
cell.backgroundColor = [UIColor cyanColor];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CNBWitnessListModel *model = self.dataSource[indexPath.row];
// CNBWitnessListController *vc = [[CNBWitnessListController alloc]initControllerWithData:self.data currentIndex:indexPath.row pageNum:1 type:@"0"];
// [self.navigationController pushViewController:vc animated:YES];
id <CNBWitnessVideoPlayProtocol>service = [[BeeHive shareInstance]createService:@protocol(CNBWitnessVideoPlayProtocol)];
[service pushToWitnessVideoController:self.data currentIndex:12 pageNum:1 type:@"0"];
}
- (void)getWitnessListDataTosid:(NSString *)toSid page:(NSInteger)page pageSize:(NSInteger)pageSize type:(NSString *)type {
NSString *url = @"";
NSDictionary *param = [NSDictionary dictionary];
if ([type isEqualToString:@"0"]) { //0 作品跳进来
param = @{
@"toSid" :CNLiveStringIsEmpty(toSid)? @"":toSid,
@"pageNo" :[NSString stringWithFormat:@"%ld",page],
@"pageSize" :[NSString stringWithFormat:@"%ld",pageSize],
@"type":@"0",
@"reviewStatus":@"1"
};
url = cn_API_Host(@"/Daren/bWitness/getBWitnessList.action");
}else if ([type isEqualToString:@"1"]) { //1 动态跳进来的
param = @{
@"toSid":CNLiveStringIsEmpty(toSid)? @"":toSid,
@"pageNo" :[NSString stringWithFormat:@"%ld",page],
@"pageSize" :[NSString stringWithFormat:@"%ld",pageSize]
};
url = CNGetWitnessCollectionListContent;
}
__weak typeof(self) weakSelf = self;
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:NO];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:url Param:param CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
NSLog(@"打印这个responseObjeect%@",responseObject);
if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
NSString *errorCode = [NSString stringWithFormat:@"%@",responseObject[@"errorCode"]];
if ([errorCode isEqualToString:@"0"]) {
NSDictionary *data = responseObject[@"data"];
weakSelf.data = data;
if ([responseObject[@"data"][@"witnessBeans"]isKindOfClass:[NSArray class]] && responseObject[@"data"][@"witnessBeans"]) {
NSArray *lists = responseObject[@"data"][@"witnessBeans"];
for (NSDictionary *dic in lists) {
[self.dataSource addObject:[CNBWitnessListModel mj_objectWithKeyValues:dic]];
}
}
[self.collectionView reloadData];
}
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end