//
|
// SubregionDetailViewController.m
|
// BuWanVideo2.0
|
//
|
// Created by weikou on 16/8/23.
|
// Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "SubregionDetailViewController.h"
|
#import "searchTableViewCell.h"//本视图所使用的cell与搜索视图使用的cell相同
|
#import "XYRVideoInfoModel.h"
|
#import "searchViewController.h"
|
#import "SearchController.h"
|
#import "LookNoteController.h"
|
#import "XYRDetailViewController.h"
|
#import "XYRVideoInfoModel.h"
|
#import "recommentCollectionViewCell.h"
|
#import "shufflingCollectionReusableView.h"
|
#import "HeaderCollectionReusableView.h"
|
#import "GoogleAdTableViewCell.h"
|
|
|
@interface SubregionDetailViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
|
NSInteger SpeciesNumber;//种类的位置
|
NSInteger typeNumber;//细分类
|
|
UICollectionView *recommendation;//推荐页面的collectionView
|
|
BOOL googleNoAdToShow;//当这个变量为YES时,说明谷歌广告没有资源
|
BOOL LoadGoogleAD;//是否选择加载谷歌广告
|
}
|
|
@property (weak, nonatomic) IBOutlet UISegmentedControl *segView;
|
@property (nonatomic , strong) HMSegmentedControl *segmentedControl;
|
@property (nonatomic , strong) NSMutableArray *SpeciesAry;//种类
|
@property (nonatomic , strong) NSMutableDictionary *dataDic;//种类下的数据源
|
@property (nonatomic, strong) UIScrollView *scrollView;//显示分类内容的视图
|
@property (nonatomic , strong) NSString *CategoryType;//内容类型
|
@property (nonatomic , strong) NSString *Species;//种类
|
|
@property (nonatomic , strong) NSMutableArray *CycleScrollData;//轮播图数据
|
@property (nonatomic , strong) NSMutableArray *hotListData;//榜首数据
|
|
@property (nonatomic , strong) NSMutableArray *addrssForshuffling;//装载推荐轮播图的地址
|
@property (nonatomic , strong) NSMutableArray *TitleForshuffling;//装载轮播图的标题
|
|
@property(nonatomic, strong) UIView *nativeAdView;//装载谷歌广告的视图
|
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *toplayout;
|
@property (nonatomic,assign)NSInteger kNavHeight;
|
|
@property (weak, nonatomic) IBOutlet UIButton *topButton;
|
|
@property (nonatomic, strong) UIView *viewTop;
|
|
@property (nonatomic, assign) BOOL isWhite;
|
@end
|
|
@implementation SubregionDetailViewController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
if (KIsiPhoneX) {
|
self.kNavHeight = 84;
|
}else{
|
self.kNavHeight = 64;
|
}
|
//加载定制的导航栏视图
|
[self loadNavigationView];
|
//请求种类数据
|
[self getDataFirstChildType];
|
//添加分段显示器的属性
|
|
[self addSegment];
|
if (KIsiPhoneX) {
|
_toplayout .constant = 130;
|
}else{
|
_toplayout.constant = 110;
|
}
|
}
|
|
- (void)viewWillAppear:(BOOL)animated
|
{
|
[super viewWillAppear:animated];
|
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
|
//NSString *str=[NSString stringWithFormat:@"分类的%@界面",self.titles];
|
[self.navigationController setNavigationBarHidden:YES animated:animated];
|
self.navigationController.navigationBar.translucent = YES;
|
//[MobClick beginLogPageView:str];
|
}
|
|
- (void)viewWillDisappear:(BOOL)animated
|
{
|
[super viewWillDisappear:animated];
|
if (_isWhite) {
|
self.isWhite = NO;
|
|
} else {
|
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
|
}
|
|
[self.navigationController setNavigationBarHidden:NO animated:animated];
|
self.navigationController.navigationBar.translucent = NO;
|
//NSString *str=[NSString stringWithFormat:@"分类的%@界面",self.titles];
|
//[MobClick endLogPageView:str];
|
}
|
|
/**
|
* 定制导航栏视图
|
*/
|
-(void)loadNavigationView {
|
[self.view addSubview:self.viewTop];
|
self.viewTop.sd_layout.leftSpaceToView(self.view, 0).topSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).heightIs(self.kNavHeight);
|
|
//去掉titlie
|
UIView *tview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0.01, 0.01)];
|
self.navigationItem.titleView = tview;
|
|
//定制返回按钮
|
UIButton *BackBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
|
[BackBtn setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
|
BackBtn.layer.masksToBounds=YES;
|
BackBtn.layer.cornerRadius=15.0;
|
[BackBtn addTarget:self action:@selector(backToRoot:) forControlEvents:UIControlEventTouchUpInside];
|
[self.viewTop addSubview:BackBtn];
|
BackBtn.sd_layout.leftSpaceToView(_viewTop, 16).bottomSpaceToView(_viewTop, 7).widthIs(30).heightIs(30);
|
|
//显示分类名
|
UILabel *nameLabel=[[UILabel alloc] init];
|
nameLabel.backgroundColor=[UIColor clearColor];
|
nameLabel.font=[UIFont systemFontOfSize:15];
|
nameLabel.textAlignment = NSTextAlignmentCenter;
|
[nameLabel setText:self.titles];
|
[nameLabel setTextColor:[UIColor whiteColor]];
|
|
[self.viewTop addSubview:nameLabel];
|
nameLabel.sd_layout.centerXEqualToView(_viewTop).bottomSpaceToView(_viewTop, 7).widthIs(100).heightIs(30);
|
|
//搜索
|
UIButton *SearchBtn = [[UIButton alloc] init];
|
[SearchBtn setImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
|
[SearchBtn addTarget:self action:@selector(JumpToSearchView) forControlEvents:UIControlEventTouchUpInside];
|
|
[self.viewTop addSubview:SearchBtn];
|
SearchBtn.sd_layout.rightSpaceToView(_viewTop, 16).bottomSpaceToView(_viewTop, 7).widthIs(30).heightIs(30);
|
|
//观看记录
|
UIButton *recordBtn = [[UIButton alloc] init];
|
[recordBtn setImage:[UIImage imageNamed:@"历史记录"] forState:UIControlStateNormal];
|
[recordBtn addTarget:self action:@selector(JumpToRecordView) forControlEvents:UIControlEventTouchUpInside];
|
|
[self.viewTop addSubview:recordBtn];
|
recordBtn.sd_layout.rightSpaceToView(SearchBtn, 10).bottomSpaceToView(_viewTop, 7).widthIs(30).heightIs(30);
|
}
|
|
- (IBAction)topTaped:(UIButton *)sender {
|
UITableView *tableview = [self.view viewWithTag:800 + SpeciesNumber ];
|
NSIndexPath* indexPat = [NSIndexPath indexPathForRow:0 inSection:0];
|
[tableview scrollToRowAtIndexPath:indexPat atScrollPosition:UITableViewScrollPositionBottom animated:YES];
|
|
}
|
|
|
/**
|
* 滑动视图
|
*/
|
-(void)addScrollerView{
|
//配置滑动视图
|
NSInteger index = KIsiPhoneX ? 84 :64 ;
|
|
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.kNavHeight+40, KScreenW, KScreenH-self.kNavHeight-40)];
|
self.scrollView.pagingEnabled = YES;
|
self.scrollView.showsHorizontalScrollIndicator = NO;
|
self.scrollView.showsVerticalScrollIndicator=NO;
|
self.scrollView.bounces=NO;
|
self.scrollView.contentSize = CGSizeMake(KScreenW * _SpeciesAry.count, KScreenH-self.kNavHeight-40);
|
self.scrollView.delegate = self;
|
[self.scrollView scrollRectToVisible:CGRectMake(0, 0, KScreenW, KScreenH-self.kNavHeight-40) animated:NO];
|
[self.view addSubview:self.scrollView];
|
|
//非推荐界面视图
|
for (int i=0; i<_SpeciesAry.count; i++) {
|
UITableView *scollerTableView=[[UITableView alloc] initWithFrame:CGRectMake(KScreenW*i, 40 , KScreenW, KScreenH-self.kNavHeight-80) style:UITableViewStylePlain];
|
scollerTableView.tag=800+i;
|
scollerTableView.delegate=self;
|
scollerTableView.dataSource=self;
|
scollerTableView.separatorStyle = NO;
|
//注册Cell
|
[scollerTableView registerNib:[UINib nibWithNibName:@"searchTableViewCell" bundle:nil] forCellReuseIdentifier:@"searchTableViewCellID"];
|
[scollerTableView registerNib:[UINib nibWithNibName:@"GoogleAdTableViewCell" bundle:nil] forCellReuseIdentifier:@"GoogleAdTableViewCellID"];
|
|
//添加下拉刷新
|
scollerTableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
_CategoryType=[NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"CategoryType"]];
|
[self getdataClassVideoWithPage:1];
|
}];
|
//添加下拉加载更多
|
scollerTableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
|
//页数
|
NSString *str=[NSString stringWithFormat:@"pagenumberX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSString *pagenumber=[_dataDic objectForKey:str];
|
if (pagenumber==nil) {
|
pagenumber=@"1";
|
}
|
_CategoryType=[NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"CategoryType"]];
|
[self getdataClassVideoWithPage:[pagenumber integerValue]];
|
}];
|
[self.scrollView addSubview:scollerTableView];
|
}
|
//首次加载视图时,需要加载首页的数据
|
// [recommendation.mj_header beginRefreshing];
|
SpeciesNumber = 0;
|
UITableView *tableview = [self.view viewWithTag:800 + SpeciesNumber ];
|
_Species = [NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"Id"]];
|
typeNumber=1;
|
[self.view bringSubviewToFront:_segView];
|
[tableview.mj_header beginRefreshing];
|
}
|
|
/**
|
* 定制轮播图
|
*/
|
-(void)addSliderView{
|
if (_addrssForshuffling) {
|
_addrssForshuffling=nil;
|
}
|
_addrssForshuffling = [[NSMutableArray alloc] initWithCapacity:0];
|
_TitleForshuffling=[[NSMutableArray alloc] initWithCapacity:0];
|
//判断
|
for (int i = 0; i<_CycleScrollData.count; i++) {
|
[_addrssForshuffling addObject:[[_CycleScrollData objectAtIndex:i] objectForKey:@"Picture"]];
|
if ([[_CycleScrollData objectAtIndex:i] objectForKey:@"Ad"]!=nil) {
|
[_TitleForshuffling addObject:[[[_CycleScrollData objectAtIndex:i] objectForKey:@"Ad"]objectForKey:@"Name"]];
|
}else{
|
[_TitleForshuffling addObject:[[[_CycleScrollData objectAtIndex:i] objectForKey:@"VideoInfo"]objectForKey:@"Name"]];
|
}
|
}
|
}
|
|
|
|
/**
|
* 添加segment的属性
|
*/
|
-(void)addSegment{
|
_segView.tintColor = kGlobalYellowColor;
|
[_segView setTitleTextAttributes:@{NSForegroundColorAttributeName:KGlobalLightGreyColor_153} forState:UIControlStateNormal];
|
[_segView setTitleTextAttributes:@{NSForegroundColorAttributeName:kGlobalMainColor} forState:UIControlStateSelected];
|
[_segView addTarget:self action:@selector(segmentHasClick:) forControlEvents:UIControlEventValueChanged];
|
}
|
|
|
|
/**
|
* 种类布局
|
*/
|
- (void)getaddView{
|
//获取分类
|
NSMutableArray *ar = [[NSMutableArray alloc] initWithCapacity:0];
|
for (int i = 0; i<_SpeciesAry.count; i++) {
|
if (i == 0) {
|
_Species = [[_SpeciesAry objectAtIndex:i] objectForKey:@"Id"];
|
}
|
[ar addObject:[[_SpeciesAry objectAtIndex:i] objectForKey:@"Name"]];
|
NSLog(@"%@",[[_SpeciesAry objectAtIndex:i] objectForKey:@"Name"]);
|
}
|
NSLog(@"%@",ar);
|
|
_segmentedControl= [[HMSegmentedControl alloc] initWithSectionTitles:ar];
|
_segmentedControl.backgroundColor=kGlobalMainColor;
|
_segmentedControl.selectionIndicatorHeight = 2.0f;
|
_segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
|
_segmentedControl.frame = CGRectMake(0, self.kNavHeight, KScreenW, 40);
|
_segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10);
|
_segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
|
_segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
|
_segmentedControl.type=HMSegmentedControlTypeText;
|
_segmentedControl.selectedSegmentIndex = 0;
|
[_segmentedControl setSegmentWidthStyle:HMSegmentedControlSegmentWidthStyleDynamic];
|
_segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName :[UIFont systemFontOfSize:15]};
|
_segmentedControl.selectedTitleTextAttributes=@{NSForegroundColorAttributeName : kGlobalYellowColor,NSFontAttributeName :[UIFont systemFontOfSize:15]};
|
_segmentedControl.selectionIndicatorColor = kGlobalYellowColor;
|
|
__weak typeof(self) weakSelf = self;
|
[_segmentedControl setIndexChangeBlock:^(NSInteger index) {
|
SpeciesNumber = index;
|
typeNumber=1;
|
weakSelf.segView.selectedSegmentIndex=0;
|
weakSelf.Species = [NSString stringWithFormat:@"%@",[[weakSelf.SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"Id"]];
|
[weakSelf.scrollView scrollRectToVisible:CGRectMake(KScreenW * index, self.kNavHeight+40, KScreenW, KScreenH-self.kNavHeight-40) animated:YES];
|
// if (index==0) {
|
// [self.view sendSubviewToBack:_segView];
|
// if (_CycleScrollData==nil&&_hotListData==nil) {
|
// //数据不存在,请求数据
|
// [recommendation.mj_header beginRefreshing];
|
// }else{
|
// //数据存在,直接加载,不需要处理
|
// }
|
// }else{
|
[self.view bringSubviewToFront:_segView];
|
UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
|
NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",weakSelf.Species,(long)SpeciesNumber,(long)typeNumber];
|
NSMutableArray *dataAry=[weakSelf.dataDic objectForKey:str];
|
if(dataAry!=nil){
|
//如果数据存在就加载数据
|
[tableView reloadData];
|
}else{
|
//如果数据不存在就请求数据
|
[tableView.mj_header beginRefreshing];
|
}
|
// }
|
}];
|
[self.view addSubview:_segmentedControl];
|
|
//添加滑动视图
|
[self addScrollerView];
|
[self.view bringSubviewToFront:self.topButton];
|
}
|
|
-(void)changeTheClassifyWith:(NSInteger)index{
|
typeNumber = 1;//默认显示最新更新
|
_segView.selectedSegmentIndex=typeNumber-1;
|
_Species = [[[_SpeciesAry objectAtIndex:index] objectForKey:@"Id"] stringValue];
|
//首先查看是否在字典里面有数据了,如果有数据,就直接使用字典里面的数据,否者刷新,获取数据
|
NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSMutableArray *dataAry=[_dataDic objectForKey:str];
|
UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
|
if(dataAry!=nil){
|
[tableView reloadData];
|
}else{
|
[tableView.mj_header beginRefreshing];
|
}
|
}
|
|
/**
|
* 分段按钮的值变化事件
|
*
|
* @param seg 当前segment
|
*/
|
- (void)segmentHasClick:(UISegmentedControl *)seg{
|
switch (seg.selectedSegmentIndex) {
|
case 0:{//最新更新
|
typeNumber = 1;
|
//刷新视图
|
_segView.selectedSegmentIndex=typeNumber-1;
|
}
|
break;
|
case 1:{//最热视频
|
typeNumber = 2;
|
//刷新视图
|
_segView.selectedSegmentIndex=typeNumber-1;
|
}
|
break;
|
case 2:{//评论最多
|
typeNumber = 3;
|
//刷新视图
|
_segView.selectedSegmentIndex=typeNumber-1;
|
}
|
break;
|
default:
|
break;
|
}
|
NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSMutableArray *dataAry=[_dataDic objectForKey:str];
|
UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
|
if(dataAry!=nil){
|
[tableView reloadData];
|
}else{
|
[tableView.mj_header beginRefreshing];
|
}
|
}
|
|
/**
|
* 跳转到历史记录
|
*/
|
-(void)JumpToRecordView{
|
self.isWhite = YES;
|
LookNoteController *LookNoteLookNoteVC=[[LookNoteController alloc] init];
|
[self.navigationController pushViewController:LookNoteLookNoteVC animated:YES];
|
}
|
|
/**
|
* 跳转到搜索
|
*/
|
-(void)JumpToSearchView{
|
SearchController *vc = [[SearchController alloc] init];
|
vc.ptitle = [YTHsharedManger startManger].searchTitle;
|
[self.navigationController pushViewController:vc animated:YES];
|
}
|
|
/**
|
* 返回
|
*/
|
-(void)backToRoot:(UIButton *)sender{
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
/// Gets an image representing the number of stars. Returns nil if rating is less than 3.5 stars.
|
- (UIImage *)imageForStars:(NSDecimalNumber *)numberOfStars {
|
double starRating = [numberOfStars doubleValue];
|
if (starRating >= 5) {
|
return [UIImage imageNamed:@"stars_5"];
|
} else if (starRating >= 4.5) {
|
return [UIImage imageNamed:@"stars_4_5"];
|
} else if (starRating >= 4) {
|
return [UIImage imageNamed:@"stars_4"];
|
} else if (starRating >= 3.5) {
|
return [UIImage imageNamed:@"stars_3_5"];
|
} else {
|
return nil;
|
}
|
}
|
|
/***********(以下)网络请求**************/
|
/**
|
* 请求分类
|
*/
|
|
- (void)getDataFirstChildType{
|
[[YTHNetInterface startInterface] getFirstChildTypeWithUid:[YTHsharedManger startManger].Uid withParentId:self.Id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
if (!_SpeciesAry) {
|
_SpeciesAry = [[NSMutableArray alloc] initWithCapacity:0];
|
}
|
_SpeciesAry = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
// [_SpeciesAry removeObjectAtIndex:0];
|
NSLog(@"%@",_SpeciesAry);
|
_Species = [NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:0] objectForKey:@"Id"]];
|
_CategoryType=[NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:0] objectForKey:@"CategoryType"]];
|
//种类布局
|
|
[self getaddView];
|
}else{
|
//报错
|
if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
|
[self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
|
}
|
NSLog(@"%@",error);
|
}
|
}];
|
}
|
|
/**
|
* 请求分类下的数据
|
*
|
* @param page 请求第几页
|
*/
|
- (void)getdataClassVideoWithPage:(NSInteger)page{
|
[[YTHNetInterface startInterface] getVideoListWithUid:[YTHsharedManger startManger].Uid withPage:[NSString stringWithFormat:@"%ld",(long)page] withVideoType:_Species withOrder:[NSString stringWithFormat:@"%ld",(long)typeNumber] withSystem:@"1" withCategoryType:_CategoryType withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
NSLog(@"%@",result);
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
//数据
|
NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSMutableArray *_dataAry=[_dataDic objectForKey:str];
|
|
if (!_dataAry) {
|
_dataAry = [[NSMutableArray alloc] initWithCapacity:0];
|
}
|
if (page == 1) {
|
[_dataAry removeAllObjects];
|
}
|
NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
for (int i =0; i<ar.count; i++) {
|
[_dataAry addObject:[ar objectAtIndex:i]];
|
}
|
|
NSString *str2=[NSString stringWithFormat:@"pagenumberX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSString *pagenumber=[NSString stringWithFormat:@"%d",(int)(page+1)];
|
//将获取到的数据存入字典中
|
if (!_dataDic) {
|
_dataDic=[NSMutableDictionary dictionary];
|
}
|
[_dataDic setObject:_dataAry forKey:str];
|
[_dataDic setObject:pagenumber forKey:str2];
|
|
//刷新视图
|
UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
|
[tableView.mj_header endRefreshing];
|
[tableView.mj_footer endRefreshing];
|
if (ar.count == 0) {
|
[tableView.mj_footer endRefreshingWithNoMoreData];
|
}
|
[tableView reloadData];
|
}else{
|
UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
|
[tableView.mj_header endRefreshing];
|
[tableView.mj_footer endRefreshing];
|
//网络连接失败
|
}
|
}];
|
}
|
/**
|
* 获取大分类推荐Banner
|
**/
|
-(void)getVideoBanner{
|
[[YTHNetInterface startInterface] getRecommendCategoryVideoBannerWithUid:[YTHsharedManger startManger].Uid withVideoType:self.Id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
if(!_CycleScrollData){
|
_CycleScrollData=[[NSMutableArray alloc] initWithCapacity:0];
|
}else{
|
[_CycleScrollData removeAllObjects];
|
}
|
NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
for (int i =0; i<ar.count; i++) {
|
[_CycleScrollData addObject:[ar objectAtIndex:i]];
|
}
|
//加载轮播图
|
[self addSliderView];
|
//刷新collectionView
|
[recommendation reloadData];
|
}else{
|
|
}
|
}];
|
|
}
|
|
/**
|
* 获取大分类推荐热榜
|
*/
|
|
-(void)VideoList{
|
[[YTHNetInterface startInterface] getRecommendCategoryVideoListWithUid:[YTHsharedManger startManger].Uid withVideoType:self.Id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
if(!_hotListData){
|
_hotListData=[[NSMutableArray alloc] initWithCapacity:0];
|
}else{
|
[_hotListData removeAllObjects];
|
}
|
NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
for (int i =0; i<ar.count; i++) {
|
[_hotListData addObject:[ar objectAtIndex:i]];
|
}
|
[recommendation.mj_header endRefreshing];
|
//刷新collectionView
|
[recommendation reloadData];
|
}else{
|
|
}
|
}];
|
|
}
|
|
|
/***********(以下)协议**************/
|
#pragma mark - UIScrollViewDelegate
|
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
//因为tableView也是继承自UIScrollView,也会执行这个方法,所以必须做一个判断
|
if(scrollView==self.scrollView){
|
SpeciesNumber = scrollView.contentOffset.x / KScreenW;
|
typeNumber=1;
|
_segView.selectedSegmentIndex=typeNumber-1;
|
_Species = [NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"Id"]];
|
[self.segmentedControl setSelectedSegmentIndex:SpeciesNumber animated:YES];
|
|
if (SpeciesNumber==0) {
|
if (_CycleScrollData==nil&&_hotListData==nil) {
|
//数据不存在,请求数据
|
[recommendation.mj_header beginRefreshing];
|
}else{
|
//数据存在,直接加载,不需要处理
|
}
|
}else{
|
//把选择器移到视图的最顶层
|
[self.view bringSubviewToFront:_segView];
|
|
NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSMutableArray *dataAry=[_dataDic objectForKey:str];
|
|
UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
|
if(dataAry!=nil){
|
//如果数据存在就加载数据
|
[tableView reloadData];
|
}else{
|
//如果数据不存在就请求数据
|
[tableView.mj_header beginRefreshing];
|
}
|
}
|
}
|
}
|
|
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
|
//因为tableView也是继承自UIScrollView,也会执行这个方法,所以必须做一个判断
|
if(scrollView==self.scrollView){
|
[self.view sendSubviewToBack:_segView];
|
}
|
}
|
|
#pragma mark - UITableViewDelegate
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
return 0.1;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
return 95;
|
}
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
if(LoadGoogleAD){//加载广告
|
if (indexPath.row/20>0&&indexPath.row%20!=0) {//这是广告的cell
|
|
}
|
}
|
//这是处理内容的cell
|
NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSMutableArray *dataAry=[_dataDic objectForKey:str];
|
XYRDetailViewController *detailVC=[[XYRDetailViewController alloc] init];
|
[YTHsharedManger startManger].preController = self;
|
detailVC.modalPresentationStyle = 0;
|
if(LoadGoogleAD){//加载广告
|
detailVC.Model=[XYRVideoInfoModel yy_modelWithDictionary:dataAry[indexPath.row-indexPath.row/20]];
|
}else{
|
detailVC.Model=[XYRVideoInfoModel yy_modelWithDictionary:dataAry[indexPath.row]];
|
}
|
[self presentViewController:detailVC animated:YES completion:^{
|
|
}];
|
|
}
|
|
#pragma mark - UITableViewDataSource
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSArray *_dataAry=[_dataDic objectForKey:str];
|
if (_dataAry.count>0) {
|
tableView.separatorStyle = YES;
|
}
|
if (googleNoAdToShow) {//没有请求到广告
|
LoadGoogleAD=NO;
|
return _dataAry.count;
|
}else{//谷歌广告可能还在请求中,或者有广告
|
if(_dataAry.count>20&&self.nativeAdView!=nil){//确认请求到广告
|
LoadGoogleAD=YES;
|
return _dataAry.count+_dataAry.count/20;
|
}else{//广告还在请求中,目前暂不考虑加载
|
LoadGoogleAD=NO;
|
return _dataAry.count;
|
}
|
}
|
}
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
if(LoadGoogleAD){//加载广告
|
if ((indexPath.row/20>0)&&(indexPath.row%20==0)&&self.nativeAdView!=nil) {
|
//显示谷歌广告
|
GoogleAdTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"GoogleAdTableViewCellID"];
|
[cell addSubview:self.nativeAdView];
|
return cell;
|
}
|
}
|
NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
|
NSArray *_dataAry;
|
searchTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"searchTableViewCellID"];
|
|
if ([str isEqual:[NSNull null]]) {
|
str = @"";
|
return cell;
|
}else{
|
_dataAry=[_dataDic objectForKey:str];
|
if (indexPath.row >= _dataAry.count) {
|
return cell;
|
}
|
}
|
//获取到该cell的数据
|
XYRVideoInfoModel *model;
|
if(LoadGoogleAD){//加载了谷歌广告的
|
model = [XYRVideoInfoModel yy_modelWithDictionary:[_dataAry objectAtIndex:(indexPath.row-indexPath.row/20)]];
|
}else{
|
model = [XYRVideoInfoModel yy_modelWithDictionary:[_dataAry objectAtIndex:(indexPath.row)]];
|
}
|
//加载图片
|
[cell.searchTableViewCellImage setYthImageWithURL:model.Hpicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
//显示Tag值
|
cell.SearchTabelViewTag.text=model.Tag;
|
cell.SearchTabelViewTag.textColor=[UIColor grayColor];
|
//加载名称
|
cell.searchTableViewCellTitle.text=model.Name;
|
if([model.Name rangeOfString:@"一家两口"].location !=NSNotFound){
|
NSLog(@"%@\n",model.Hpicture);
|
NSLog(@"%@",[_dataAry objectAtIndex:(indexPath.row)]);
|
|
}
|
|
//观看数量
|
cell.searchTableViewCellWatchNUB.textColor=kGlobalLightGreyColor_210;
|
NSString *recommentStr;
|
if ([model.WatchCount intValue]<10000) {
|
recommentStr=model.WatchCount;
|
}else{
|
recommentStr=[NSString stringWithFormat:@"%0.1f万",[model.WatchCount floatValue]/10000.0];
|
}
|
cell.searchTableViewCellWatchNUB.text=recommentStr;
|
//评论数量CommentCount
|
cell.searchTableViewCellCommentNUB.textColor=kGlobalLightGreyColor_210;
|
NSString *commentCountStr;
|
commentCountStr=[NSString stringWithFormat:@"%ld",(long)model.CommentCount];
|
if (model.CommentCount<10000) {
|
|
}else{
|
commentCountStr=[NSString stringWithFormat:@"%0.1f万",[commentCountStr floatValue]/10000.0];
|
}
|
cell.searchTableViewCellCommentNUB.text=[NSString stringWithFormat:@"%@",commentCountStr];
|
return cell;
|
}
|
|
|
#pragma mark -UICollectionViewDataSource
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
if (section==0) {
|
return 0;
|
}else{
|
return _hotListData.count;
|
}
|
}
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
recommentCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"recommentCollectionViewCell" forIndexPath:indexPath];
|
//设置cell的背景色(白色)
|
cell.backgroundColor=[UIColor whiteColor];
|
//在这里对cell进行设置
|
NSDictionary *VideoInformation=_hotListData[indexPath.row];
|
NSString *picStr=[VideoInformation objectForKey:@"Picture"];
|
//设置图片
|
cell.recommentImageView.contentMode=UIViewContentModeScaleAspectFill;
|
[cell.recommentImageView setYthImageWithURL:picStr placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
|
//设置短评(如果有Tag就设置Tag,没有Tag就设置Score)
|
NSString *TagStr1=[VideoInformation objectForKey:@"Tag"];
|
NSString *Score=[VideoInformation objectForKey:@"Score"];
|
if(TagStr1.length>1){
|
cell.recommentReplyLabel.text=TagStr1;
|
}else if([Score intValue]>0){
|
cell.recommentReplyLabel.text=[NSString stringWithFormat:@"评分:%@",Score];
|
}else{
|
cell.recommentReplyLabel.text=[NSString stringWithFormat:@"评分:无"];
|
}
|
cell.recommentReplyLabel.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
|
//标题
|
cell.recommentTitleLabel.text=[NSString stringWithFormat:@"%@",[VideoInformation objectForKey:@"Name"]];
|
//观看数量
|
cell.recommentrecommentVV.textColor=kGlobalLightGreyColor_210;
|
NSString *recommentStr;
|
if ([[VideoInformation objectForKey:@"WatchCount"] intValue]<10000) {
|
recommentStr=[VideoInformation objectForKey:@"WatchCount"];
|
}else{
|
recommentStr=[NSString stringWithFormat:@"%0.1f万",[[VideoInformation objectForKey:@"WatchCount"] floatValue]/10000.0];
|
}
|
cell.recommentrecommentVV.text=recommentStr;
|
//评论数量CommentCount
|
cell.recommentCommentNub.textColor=kGlobalLightGreyColor_210;
|
NSString *commentCountStr;
|
if ([[VideoInformation objectForKey:@"CommentCount"] intValue]<10000) {
|
commentCountStr=[VideoInformation objectForKey:@"CommentCount"];
|
}else{
|
commentCountStr=[NSString stringWithFormat:@"%0.1f万",[[VideoInformation objectForKey:@"CommentCount"] floatValue]/10000.0];
|
}
|
cell.recommentCommentNub.text=[NSString stringWithFormat:@"%@",commentCountStr];
|
return cell;
|
}
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
return 2;
|
}
|
|
//定制collectionView的head和foot
|
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
|
if (kind == UICollectionElementKindSectionHeader){
|
if(indexPath.section==0){
|
//如果是轮播图
|
shufflingCollectionReusableView *shuffling=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"shufflingCollectionReusableView" forIndexPath:indexPath];
|
//定制轮播图
|
// [shuffling addSubview:_cycleScrollView];
|
return shuffling;
|
|
}else{
|
//分类标头
|
HeaderCollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderCollectionReusableView" forIndexPath:indexPath];
|
header.headerImage.image=[UIImage imageNamed:@"今日热点"];
|
header.HeaderTitle.text=@"全区榜首";
|
[header.headerMore setHidden:YES];
|
return header;
|
}
|
}
|
return nil;
|
}
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
|
//宽度随便定,系统会自动取collectionView的宽度
|
//高度为分组头的高度
|
if(section==0){
|
//设置轮播图的高度
|
return CGSizeMake(0, KScreenW*7/16);
|
}else{
|
return CGSizeMake(0, 50);
|
}
|
}
|
|
#pragma mark -UICollectionViewDelegate
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
|
return YES;
|
}
|
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
return YES;
|
}
|
|
//cell被点击的处理方法
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
if (self.hotListData == nil || self.hotListData.count<1) {
|
return;
|
}
|
XYRDetailViewController *play=[[XYRDetailViewController alloc]init];
|
[YTHsharedManger startManger].preController = self;
|
play.modalPresentationStyle = 0;
|
play.Model = [XYRVideoInfoModel yy_modelWithDictionary:_hotListData[indexPath.row]];
|
[self presentViewController:play animated:YES completion:^{
|
|
}];
|
}
|
|
#pragma mark -UICollectionViewDelegateFlowLayout
|
//协议中的方法,用于返回单元格的大小
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
{
|
return CGSizeMake((KScreenW-30)/2, (KScreenW-30)*10/16/2+55);
|
}
|
|
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
|
//上、左、下、右的边距
|
return UIEdgeInsetsMake(0, 10, 10, 10);
|
}
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
if (scrollView.contentOffset.y<KScreenH/2) {
|
[self.topButton setHidden:YES];
|
}else{
|
[self.topButton setHidden:NO];
|
}
|
}
|
|
- (void)dealloc{
|
|
}
|
|
- (UIView *)viewTop {
|
if (!_viewTop) {
|
_viewTop = [[UIView alloc] init];
|
_viewTop.backgroundColor = [UIColor blackColor];
|
}
|
return _viewTop;
|
}
|
@end
|