ifish/Ifish/controllers/IfishTabControllers/探索/IfishLive/IfishLivelist/IfishKanKanListViewControll...

537 lines
16 KiB
Objective-C

//
// IfishKanKanListViewController.m
// Ifish
//
// Created by imac on 16/11/8.
// Copyright © 2016年 lianxiang. All rights reserved.
//
#import "IfishKanKanListViewController.h"
#import "IfishKankanListModel.h"
#import "LXAdScrollView.h"
#import "WoDeKanKanViewController.h"
#define TABBAR_H self.tabBarController.tabBar.frame.size.height
#import "KanKanListTableCell.h"
#import "IfishP2PLivePlayViewController.h"
#import "KanKanBanner.h"
#import "MineKankanEditViewController.h"
#import "JHRefresh.h"
#import "KanKanListDataHelper.h"
#import "PushMasssageWebViewController.h"
#import "IfishBannerData.h"
@interface IfishKanKanListViewController ()<UITableViewDelegate, UITableViewDataSource ,RecommendTableCellDelegate,MBProgressHUDDelegate>
{
BOOL _isRefreshing;
BOOL _isLoadMore;
BOOL _isPushEdit;
}
@property(nonatomic,copy) NSString* total;
@property(nonatomic,strong) LXAdScrollView *adView;
@property(nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) NSMutableArray *bannerArray;
@property (nonatomic,strong) NSMutableArray *bannerImgArr;
@property(nonatomic,strong) NSDictionary*para;
@property(nonatomic)BOOL isRefreshing;
@property(nonatomic)BOOL isLoadMore;
@property(nonatomic,copy) NSString *oders;
@property(nonatomic) int page;
@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,strong) MBProgressHUD *progressHud;
@end
/*
*老界面已废弃
*/
@implementation IfishKanKanListViewController
- (void)viewDidLoad {
[super viewDidLoad];
_isPushEdit = NO;
// Do any additional setup after loading the view.
_bannerArray = [[NSMutableArray alloc] init];
_bannerImgArr= [[NSMutableArray alloc] init];
_dataArray = [[NSMutableArray alloc] init];
[self loadPageData];
[self addTitleViewWithTitle:@"爱鱼看看"];
self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightButton.frame = CGRectMake(0, 0, 60, 44);
[self.rightButton setImage:[UIImage imageNamed:@"live_navicon_look"] forState:UIControlStateNormal];
[self.rightButton setImageEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
[self.rightButton addTarget:self action:@selector(popAppear) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightItem =[[UIBarButtonItem alloc] init];
rightItem.customView =self.rightButton;
self.navigationItem.rightBarButtonItem = rightItem;
[self creatUI];
[self creatReatRefreshView];
//[self loadBannerData];
[self loadNewBannerData];
}
-(void)loadPageData{
NSInteger firstResult = 0;
NSInteger pageSize = 10;
NSString *startoders = @"";
NSString *userId = [dataContorl dataControlGetUserIdInfo];
[AFHttpTool getLiveRoomsfirstResult:firstResult pageSize:pageSize userId:userId orders:startoders success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSDictionary *dataDic=reDic[@"data"];
NSArray*roomArr=dataDic[@"liveRoomInfo"];
if ([reDic[@"result"] isEqualToString:@"100"]) {
NSString *fedbackOder=dataDic[@"orders"];
NSString *total=dataDic[@"total"];
[self.dataArray removeAllObjects];
for (NSDictionary *dic in roomArr) {
IfishKankanListModel *mode=[[IfishKankanListModel alloc] init];
[KanKanListDataHelper formatKanKanLisetData:mode liveRoomInfo:dic];
[self.dataArray addObject:mode];
}
self.oders = fedbackOder;
self.total = total;
//NSLog(@"_dataArray直播1列表%lu",(unsigned long)_dataArray.count);
}
[self.tableView reloadData];
} failure:^(NSError *err) {
[self.view makeToast:@"NSError请求异常"];
}];
}
-(void)popAppear{
[self pushMyKankan];
}
-(void)pushMyKankan{
self.hidesBottomBarWhenPushed = YES;
// WoDeKanKanViewController *wodeKakanVC=[[WoDeKanKanViewController alloc] init];
MineKankanEditViewController *editVC = [[MineKankanEditViewController alloc] init];
_isPushEdit = YES;
[self.navigationController pushViewController:editVC animated:YES];
}
#pragma mark -v4.1 前 看看banner
-(void)loadBannerData{
__weak typeof (self)weskSelf=self;
[AFHttpTool getLiveBannerSuccess:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([reDic[@"result"] isEqualToString:@"100"]){
NSArray*bannerArr=reDic[@"data"];
for (NSDictionary *bannerDic in bannerArr) {
KanKanBanner *banner=[[KanKanBanner alloc] init];
banner.appShow = bannerDic[@"appShow"];
banner.bannerId = bannerDic[@"bannerId"];
banner.bannerImg = bannerDic[@"bannerImg"];
banner.bannerLink = bannerDic[@"bannerLink"];
banner.bannerType = bannerDic[@"bannerType"];
[_bannerImgArr addObject:banner.bannerImg];
[_bannerArray addObject:banner];
}
[weskSelf setingBannerViewData];
}
} failure:^(NSError *err) {
NSLog(@"loadBannererr%@",err);
}];
}
#pragma mark -v4.1 后看看banner
-(void)loadNewBannerData{
__weak typeof (self)weskSelf=self;
[AFHttpTool getIfishBannerData:IfishAdTypeKankan success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([reDic[@"result"] isEqualToString:@"100"]){
NSArray*bannerArr=reDic[@"data"];
for (NSDictionary *bannerDic in bannerArr) {
IfishBannerData *banner=[[IfishBannerData alloc] initWithDict:bannerDic];
[_bannerImgArr addObject:banner.adImage];
[_bannerArray addObject:banner];
}
[weskSelf setingBannerViewData];
}
} failure:^(NSError *err) {
}];
}
-(void)creatUI{
//[self cratHUD];
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
_tableView.dataSource=self;
_tableView.delegate=self;
_tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor= TABLE_BACKGROUD_COLOR;
//_tableView.backgroundColor= [UIColor redColor];
UIView *footerView=[[UIView alloc] initWithFrame:CGRectMake(0,0, kScreenSize.width, 0.1)];
footerView.backgroundColor = [UIColor clearColor];
_tableView.tableFooterView = footerView;
LXAdScrollView *adView = [[LXAdScrollView alloc]initWithFrame:CGRectMake(0,0,kScreenSize.width,kScreenSize.width*0.427)];
adView.backgroundColor = [UIColor lightGrayColor];
_adView = adView;
_tableView.tableHeaderView=_adView;
[self.view addSubview:_tableView];
}
-(void)cratHUD{
if (self.progressHud) {
self.progressHud = [[MBProgressHUD alloc] initWithView:self.view];
}
[self.view addSubview:self.progressHud];
self.progressHud.mode=MBProgressHUDModeIndeterminate;
self.progressHud.customView = [[UIView alloc] init];
self.progressHud.delegate = self;
self.progressHud.labelText = @"加载中...";
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (_isPushEdit) {
[_tableView reloadData];
}
[self setingBannerViewData];
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.progressHud hide:YES];
}
-(void)setingBannerViewData{
// 取消导航影响 广告栏
// self.automaticallyAdjustsScrollViewInsets = NO;
__weak typeof (self)weskSelf=self;
if (_bannerArray.count !=0) {
_adView.adList = _bannerImgArr;
_adView.tapActionBlock = ^(LXAdScrollView *adScrollView) {
NSInteger adIndx=adScrollView.currentPage;
KanKanBanner *banner=weskSelf.bannerArray[adIndx];
[weskSelf tapBannerWith:banner];
};
}else{
_adView.adList = @[@"kankan_listbanner.jpg"];
_adView.tapActionBlock = ^(LXAdScrollView *adScrollView) {
[weskSelf pushMyKankan];
};
}
}
#pragma mark -banner 事件
-(void)tapBannerWith:(KanKanBanner *)banner
{
if (banner.bannerType) {
//打开网页
[self pushWebwithLink:banner.bannerLink];
}else{
[self.view makeToast:@"未知广告类型"];
}
}
#pragma mark 打开网页
-(void)pushWebwithLink:(NSString*)url{
_isPushEdit = NO;
PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init];
webVC.pushlink =url;
webVC.pushtitle = @"网页";
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:webVC animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identfire=@"RecommendTableCell";
KanKanListTableCell *cell=[tableView dequeueReusableCellWithIdentifier:identfire];
if (!cell) {
cell=[[KanKanListTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identfire];
}
cell.delegate = self;
cell.selectionStyle=UITableViewCellSelectionStyleNone;
[cell loadDta:self.dataArray];
cell.backgroundColor = TABLE_BACKGROUD_COLOR;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//int sliderValue=(int)(slider.value+0.5);
//内容高度
int rowNumb = 0;
rowNumb = (int)(self.dataArray.count +1)/2 ;
//return (((270*KWidth_Scale-3*5)/2)*rowNumb)/2 + KWidth_Scale*100;
return ((270*KWidth_Scale-3*5)/2)*rowNumb + KWidth_Scale*100 + 5*rowNumb;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
-(void)TapRecommendTableCellDelegate:(IfishKankanListModel *)listModel
{
self.progressHud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.progressHud];
self.progressHud.mode=MBProgressHUDModeCustomView;
self.progressHud.customView = [[UIView alloc] init];
self.progressHud.delegate = self;
self.progressHud.labelText = @"加载中...";
__weak typeof (self)weskSelf=self;
[self.progressHud showAnimated:YES whileExecutingBlock:^{
[weskSelf pushShareP2pView:listModel];
} onQueue:dispatch_get_main_queue()];
}
-(void)pushShareP2pView:(IfishKankanListModel *)listModel
{
KanHuListModel *kanHuCamera =[[KanHuListModel alloc] init];
//kanHuCamera.cameraId = @"3573889";
kanHuCamera.cameraId = listModel.cameraId;
IfishP2PLivePlayViewController *shareVideoVC=[[IfishP2PLivePlayViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
shareVideoVC.kanHuCamera = kanHuCamera;
shareVideoVC.listRoomInfo = listModel;
_isPushEdit = NO;
[self.navigationController pushViewController:shareVideoVC animated:YES];
}
-(void)hudWasHidden:(MBProgressHUD *)hud
{
}
-(void)creatReatRefreshView{
__weak typeof (self)weskSelf=self;
// 下拉刷新
[_tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshAmazingAniView class] beginRefresh:^{
if (weskSelf.isRefreshing) {
return ;
}
weskSelf.isRefreshing=YES;
_page=0;
NSInteger firstResult = 0;
NSInteger pageSize = 10;
[weskSelf addRefreshHeaderTaskWithFirst:firstResult pageSize:pageSize isRefresh:YES];
}];
//上拉加载更多
[_tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
if (weskSelf.isLoadMore) {
return ;
}
weskSelf.isLoadMore=YES;
NSInteger pagecount =[self.total integerValue]/10+1;
if (weskSelf.page<pagecount-1) {
weskSelf.page++;
NSInteger first=(NSInteger)weskSelf.page*10;
NSInteger pageSize = 10;
[weskSelf addRefreshFooterTaskWithFirst:first pageSize:pageSize isRefresh:YES];
}else{
[weskSelf endRefreshing];
[weskSelf.view makeToast:@"已无更多数据"];
}
}];
}
-(void)endRefreshing{
if (self.isRefreshing) {
self.isRefreshing=NO;
[_tableView headerEndRefreshingWithResult:JHRefreshResultNone];
}
if (self.isLoadMore) {
self.isLoadMore=NO;
[_tableView footerEndRefreshing];
}
}
#pragma mark -刷新
-(void)addRefreshHeaderTaskWithFirst:(NSInteger)firstResult pageSize:(NSInteger)pageSize isRefresh:(BOOL)isRefresh{
if (isRefresh) {
[_dataArray removeAllObjects];
}
NSString*userId = [dataContorl dataControlGetUserIdInfo];
NSString *orders = @"";
[AFHttpTool getLiveRoomsfirstResult:firstResult pageSize:pageSize userId:userId orders:orders success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSDictionary *dataDic=reDic[@"data"];
NSArray*roomArr=dataDic[@"liveRoomInfo"];
if ([reDic[@"result"] isEqualToString:@"100"]) {
self.oders =dataDic[@"orders"];
self.total =dataDic[@"total"];
[_dataArray removeAllObjects];
for (NSDictionary *dic in roomArr) {
IfishKankanListModel *mode=[[IfishKankanListModel alloc] init];
[KanKanListDataHelper formatKanKanLisetData:mode liveRoomInfo:dic];
[_dataArray addObject:mode];
}
NSLog(@"_dataArray列表%lu",(unsigned long)_dataArray.count);
[_tableView reloadData];
[self endRefreshing];
}else{
[self endRefreshing];
}
} failure:^(NSError *err) {
[self endRefreshing];
[self.view makeToast:@"网络异常"];
}];
}
#pragma mark -加载更多
-(void)addRefreshFooterTaskWithFirst:(NSInteger)firstResult pageSize:(NSInteger)pageSize isRefresh:(BOOL)isRefresh
{
NSString*userId = [dataContorl dataControlGetUserIdInfo];
NSString *orders = self.oders;
[AFHttpTool getLiveRoomsfirstResult:firstResult pageSize:pageSize userId:userId orders:orders success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSDictionary *dataDic=reDic[@"data"];
NSArray*roomArr=dataDic[@"liveRoomInfo"];
if ([reDic[@"result"] isEqualToString:@"100"]) {
self.oders =dataDic[@"orders"];
self.total =dataDic[@"total"];
//[_dataArray removeAllObjects];
for (NSDictionary *dic in roomArr) {
IfishKankanListModel *mode=[[IfishKankanListModel alloc] init];
[KanKanListDataHelper formatKanKanLisetData:mode liveRoomInfo:dic];
[_dataArray addObject:mode];
}
[_tableView reloadData];
[self endRefreshing];
NSLog(@"_dataArray列表%lu",(unsigned long)_dataArray.count);
}else{
[self endRefreshing];
}
} failure:^(NSError *err) {
[self.view makeToast:@"网络异常"];
[self endRefreshing];
}];
}
@end