CNLIVEViewController.m 5.57 KB
//
//  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