LVCVodPlayerListView.m 4.25 KB
//
//  LVCVodPlayerListView.m
//  LiveVideoCloud
//
//  Created by cnliveJunBo on 17/6/26.
//  Copyright © 2017年 cnlive. All rights reserved.
//

#import "LVCVodPlayerListView.h"
#import "LVCVodPlayerTableViewCell.h"

static NSString *vodCellId = @"vodCellId";

@interface LVCVodPlayerListView()<UITableViewDelegate, UITableViewDataSource> {
    
    AFHTTPRequestOperation *_operation;
    NSMutableArray *_programArrayM;
}

@property (nonatomic, strong)UITableView *tableView;

@end

@implementation LVCVodPlayerListView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _programArrayM = [[NSMutableArray alloc] init];
        [self requestVodPlayerList];
    }
    return self;
}

- (void)requestVodPlayerList {
    
    NSString *uid;
    if ([UserTools isLogin]) {
        uid = [UserInformationModel manager].uid;
    } else {
        uid = [NSString stringWithFormat:@"%u", arc4random()%3];
    }
    NSString *tm = [NSString stringWithFormat:@"%u_%@", arc4random()%10, uid];
    
    NSDictionary *parameter = @{@"cid": @"82_news/",
                                @"page": [NSString stringWithFormat:@"%d", 1],
                                @"pagesize": @"15",
                                @"tm": tm};
    
    [[AFHTTPRequestOperationManager manager] GET:Newslist parameters:[self addParameters:parameter] success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        responseObject = [responseObject validatedDictionary];
        
        if (responseObject[@"programs"] && [responseObject[@"programs"] isKindOfClass:[NSArray class]]) {
            
            for (NSDictionary *dic in responseObject[@"programs"]) {
                ProgramModel *programModel = [ProgramModel modelWithDic:dic];
                [_programArrayM addObject:programModel];
                if (dic[@"comments"] && [dic[@"comments"] isKindOfClass:[NSArray class]] && [dic[@"comments"] count] > 0) {
                    NSMutableArray *comments = [[NSMutableArray alloc] init];
                    for (NSDictionary *commentDic in dic[@"comments"]) {
                        LVCCommentModel *commentModel = [LVCCommentModel modelWithDic:commentDic];
                        [comments addObject:commentModel];
                    }
                    [_programArrayM addObject:comments];
                }
            }
        }
        [self.tableView reloadData];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"点播列表请求失败!");
    }];
}

#pragma mark - UITableViewDelegate !!!!!!!!!!!!!!!!!!!!!!!!

#pragma mark - UITableViewDataSource !!!!!!!!!!!!!!!!!!!!!!!!
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _programArrayM.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return nil;
}

#pragma mark - GetMethod !!!!!!!!!!!!!!!!!!!!!!!!!!!!
- (UITableView *)tableView {
    
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -KScreenHeight, KScreenWidth, KScreenHeight)];
        view.backgroundColor = [UIColor backgroundColor];
        [_tableView addSubview:view];
    
        [_tableView registerClass:[LVCVodPlayerTableViewCell class] forCellReuseIdentifier:vodCellId];
    }
    return _tableView;
}

#pragma mark ------------------------------ 分割线 ----------------------------------------------
- (NSDictionary *)addParameters:(NSDictionary *)dict {
    
    if (![dict isKindOfClass:[NSDictionary class]]) {
        return dict;
    }
    if (!dict) {
        return @{@"appid": JBAppId, @"plat": @"i", @"version": JBAppVersion};
    } else {
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:dict];
        [dic addEntriesFromDictionary:@{@"appid": JBAppId, @"plat": @"i", @"version": JBAppVersion}];
        return [[NSDictionary alloc] initWithDictionary:dic];
    }
}

@end