//
|
// liveOnLineView.m
|
// BuWanVideo2.0
|
//
|
// Created by apple on 16/10/26.
|
// Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "liveOnLineView.h"
|
|
#import "HotLiveTableViewCell.h"
|
#import "AllLiveTypeTableViewCell.h"
|
#import "LiveListTableViewCell.h"
|
|
#import "WEBViewController.h"
|
|
#import "liveTopicViewController.h"//直播的专题页面
|
@interface liveOnLineView()<UITableViewDelegate,UITableViewDataSource>{
|
NSMutableArray *_HotLive;//获取热门直播
|
NSMutableArray *_AllLiveType;//直播类别
|
NSMutableArray *_LiveList;//直播列表
|
UITableView *_livetableView;//直播列表
|
int nowPage;//最新直播请求多少页
|
}
|
|
@end
|
|
@implementation liveOnLineView
|
|
- (instancetype)initWithFrame:(CGRect)frame{
|
self = [super initWithFrame:frame];
|
if (self) {
|
nowPage = 1;
|
if (!_livetableView) {
|
_livetableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStyleGrouped];
|
_livetableView.delegate=self;
|
_livetableView.dataSource=self;
|
[_livetableView registerNib:[UINib nibWithNibName:@"HotLiveTableViewCell" bundle:nil] forCellReuseIdentifier:@"HotLiveTableViewCell"];
|
[_livetableView registerNib:[UINib nibWithNibName:@"AllLiveTypeTableViewCell" bundle:nil] forCellReuseIdentifier:@"AllLiveTypeTableViewCell"];
|
[_livetableView registerNib:[UINib nibWithNibName:@"LiveListTableViewCell" bundle:nil] forCellReuseIdentifier:@"LiveListTableViewCell"];
|
|
_livetableView.separatorStyle = UITableViewCellSelectionStyleNone;
|
|
//下拉刷新
|
_livetableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
nowPage = 1;
|
[self reloadHotLiveData];
|
}];
|
//上拉加载更多
|
_livetableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
|
[self reloadLiveList];
|
}];
|
|
[self addSubview:_livetableView];
|
[_livetableView.mj_header beginRefreshing];
|
}
|
}
|
|
return self;
|
}
|
|
/**
|
获取热门直播
|
*/
|
-(void)reloadHotLiveData{
|
[[YTHNetInterface startInterface] getHotLiveWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if(isSuccessful){
|
[self reloadAllLiveType];
|
|
_HotLive=[[result objectForKey:@"Data"] objectForKey:@"data"];
|
|
}else{
|
[self reloadAllLiveType];
|
NSLog(@"网络连接失败!");
|
}
|
}];
|
}
|
|
/**
|
获取直播类别
|
*/
|
-(void)reloadAllLiveType{
|
[[YTHNetInterface startInterface] getAllLiveTypeWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if(isSuccessful){
|
[self reloadLiveList];
|
|
_AllLiveType=[[result objectForKey:@"Data"] objectForKey:@"data"];
|
|
}else{
|
[self reloadLiveList];
|
NSLog(@"网络连接失败!");
|
}
|
}];
|
}
|
|
/**
|
获取直播列表
|
*/
|
-(void)reloadLiveList{
|
[[YTHNetInterface startInterface] getLiveListWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withPage:[NSString stringWithFormat:@"%d",nowPage] WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if(isSuccessful){
|
if (nowPage == 1) {
|
_LiveList=[[result objectForKey:@"Data"] objectForKey:@"data"];
|
}else{
|
NSMutableArray *tempArr=[NSMutableArray arrayWithCapacity:0];
|
tempArr=[[result objectForKey:@"Data"] objectForKey:@"data"];
|
[_LiveList addObjectsFromArray:tempArr];
|
}
|
|
++nowPage;
|
//刷新
|
[_livetableView reloadData];
|
|
[_livetableView.mj_header endRefreshing];
|
[_livetableView.mj_footer endRefreshing];
|
}else{
|
[_livetableView.mj_header endRefreshing];
|
[_livetableView.mj_footer endRefreshing];
|
NSLog(@"网络连接失败!");
|
}
|
}];
|
}
|
|
/**
|
统计直播点击
|
*/
|
-(void)addStatisticsPostWithType:(NSString *)Type WithRoomId:(NSString *)RoomId{
|
[[YTHNetInterface startInterface] addStatisticsWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithType:Type WithRoomId:RoomId WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSLog(@"统计上传成功!");
|
}
|
}];
|
}
|
|
/**
|
* 返回当前视图的控制器
|
*/
|
- (UIViewController *)viewController {
|
for (UIView* next = [self superview]; next; next = next.superview) {
|
UIResponder *nextResponder = [next nextResponder];
|
if ([nextResponder isKindOfClass:[UIViewController class]]) {
|
return (UIViewController *)nextResponder;
|
}
|
}
|
return nil;
|
}
|
|
#pragma mark -UITableViewDataSource
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
return 3;
|
}
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
return 1;
|
}
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
if (indexPath.section == 0) {
|
HotLiveTableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:@"HotLiveTableViewCell" forIndexPath:indexPath];
|
cell1.cellData=_HotLive;
|
cell1.backgroundColor=[UIColor whiteColor];
|
cell1.clickIndexpath = ^(NSIndexPath *index) {
|
WEBViewController *webVC=[[WEBViewController alloc] init];
|
webVC.url=[_HotLive[index.row] objectForKey:@"H5Url"];
|
webVC.orMake=UIInterfaceOrientationMaskPortrait;
|
[[self viewController] presentViewController:webVC animated:YES completion:^{
|
|
}];
|
};
|
return cell1;
|
}else if (indexPath.section == 1){
|
AllLiveTypeTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:@"AllLiveTypeTableViewCell" forIndexPath:indexPath];
|
cell2.cellData=_AllLiveType;
|
cell2.backgroundColor=[UIColor whiteColor];
|
cell2.clickIndexpath = ^(NSIndexPath *index) {
|
|
|
liveTopicViewController *liveTopicView=[[liveTopicViewController alloc] init];
|
liveTopicView.titleStr=[_AllLiveType[index.row] objectForKey:@"Name"];
|
liveTopicView.type=[_AllLiveType[index.row] objectForKey:@"Id"];
|
[[self viewController].navigationController pushViewController:liveTopicView animated:YES];
|
};
|
|
return cell2;
|
}else{
|
LiveListTableViewCell *cell3 = [tableView dequeueReusableCellWithIdentifier:@"LiveListTableViewCell" forIndexPath:indexPath];
|
cell3.cellData=_LiveList;
|
cell3.clickIndexpath = ^(NSIndexPath * index) {
|
WEBViewController *webVC=[[WEBViewController alloc] init];
|
webVC.url=[_LiveList[index.row] objectForKey:@"H5Url"];
|
webVC.orMake=UIInterfaceOrientationMaskPortrait;
|
[[self viewController] presentViewController:webVC animated:YES completion:^{
|
|
}];
|
};
|
|
return cell3;
|
}
|
}
|
|
#pragma mark -UITableViewDelegate
|
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
|
return NO;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
if (section==0) {
|
return 40;
|
}
|
return 10;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
return 1;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
if (indexPath.section==0) {
|
return 160;
|
}else if(indexPath.section==1){
|
if (_AllLiveType.count==0) {
|
return 0.01;
|
}else{
|
return 85;
|
}
|
}else{
|
return (_LiveList.count/2)*((KScreenW-8)/2+50);
|
}
|
}
|
|
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
if (section==0) {
|
UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 40)];
|
headerView.backgroundColor=[UIColor whiteColor];
|
|
UILabel *headerLabel=[[UILabel alloc] initWithFrame:CGRectMake(13, 0, KScreenW-13, 40)];
|
headerLabel.text=@"热门推荐";
|
headerLabel.font=[UIFont systemFontOfSize:15];
|
headerLabel.textColor=YTHColor(110, 110, 110);
|
[headerView addSubview:headerLabel];
|
return headerView;
|
}
|
return nil;
|
}
|
|
@end
|