//
|
// FuLiSheViewController.m
|
// BuWanVideo2.0
|
//
|
// Created by apple on 16/12/1.
|
// Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "FuLiSheViewController.h"
|
#import "searchViewController.h"
|
#import "LookNoteController.h"
|
#import "recommentCollectionViewCell.h"
|
#import "XYRDetailViewController.h"
|
|
@interface FuLiSheViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
|
UICollectionView *_CollectionView;//福利社的瀑布流
|
int page;
|
}
|
@property (nonatomic , strong) NSMutableArray *arrDate;//福利社数据
|
@end
|
|
@implementation FuLiSheViewController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
// Do any additional setup after loading the view from its nib.
|
//初始化数据
|
page=1;
|
//加载定制的导航栏视图
|
[self loadNavigationView];
|
//请求数据
|
[self loadData];
|
//创建界面
|
[self CreatUI];
|
}
|
|
/**
|
* 定制导航栏视图
|
*/
|
-(void)loadNavigationView{
|
//去掉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];
|
UIBarButtonItem *backBarItem=[[UIBarButtonItem alloc] initWithCustomView:BackBtn];
|
|
//显示分类名
|
UILabel *nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 65, 20)];
|
nameLabel.backgroundColor=[UIColor clearColor];
|
nameLabel.font=[UIFont systemFontOfSize:15];
|
[nameLabel setText:self.titles];
|
[nameLabel setTextColor:[UIColor whiteColor]];
|
UIBarButtonItem *nameBarItem=[[UIBarButtonItem alloc] initWithCustomView:nameLabel];
|
|
//添加分类名和返回按钮到导航栏
|
self.navigationItem.leftBarButtonItems=[[NSArray alloc] initWithObjects:backBarItem,nameBarItem,nil];
|
|
//观看记录
|
UIButton *recordBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
|
[recordBtn setImage:[UIImage imageNamed:@"历史记录"] forState:UIControlStateNormal];
|
[recordBtn addTarget:self action:@selector(JumpToRecordView) forControlEvents:UIControlEventTouchUpInside];
|
UIBarButtonItem *recordBarItem=[[UIBarButtonItem alloc] initWithCustomView:recordBtn];
|
|
//搜索
|
UIButton *SearchBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
|
[SearchBtn setImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
|
[SearchBtn addTarget:self action:@selector(JumpToSearchView) forControlEvents:UIControlEventTouchUpInside];
|
UIBarButtonItem *SearchBarItem=[[UIBarButtonItem alloc] initWithCustomView:SearchBtn];
|
|
//空白间距
|
UILabel *WhiteLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 8, 10)];
|
WhiteLabel.backgroundColor=[UIColor clearColor];
|
UIBarButtonItem *WhiteBarItem=[[UIBarButtonItem alloc] initWithCustomView:WhiteLabel];
|
|
//添加 观看记录/下载/搜索 到导航栏
|
self.navigationItem.rightBarButtonItems=[[NSArray alloc] initWithObjects:SearchBarItem,WhiteBarItem,recordBarItem,nil];
|
}
|
|
-(void)loadData{
|
[SVProgressHUD showWithStatus:@"疯狂加载中..."];
|
[[YTHNetInterface startInterface] getMoreVideoWithUid:[YTHsharedManger startManger].Uid withType:self.Id withSystem:@"1" withPage:[NSString stringWithFormat:@"%d",page] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
if (!_arrDate) {
|
_arrDate=[NSMutableArray arrayWithCapacity:0];
|
}
|
if (page == 1) {
|
[_arrDate removeAllObjects];
|
}
|
NSArray *ar = [[result objectForKey:@"Data"] objectForKey:@"data"];
|
for (int i =0; i<ar.count; i++) {
|
[_arrDate addObject:[ar objectAtIndex:i]];
|
}
|
[_CollectionView reloadData];
|
[SVProgressHUD dismiss];
|
}else{
|
//请求失败
|
[SVProgressHUD dismiss];
|
if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
|
[self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
|
}
|
}
|
}];
|
}
|
|
-(void)CreatUI{
|
if (!_CollectionView) {
|
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
|
//指定布局方式为垂直
|
flow.scrollDirection = UICollectionViewScrollDirectionVertical;
|
flow.minimumLineSpacing = 10;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距)
|
flow.minimumInteritemSpacing = 10;//两个单元格之间的最小间距
|
|
_CollectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH) collectionViewLayout:flow];
|
}
|
_CollectionView.delegate=self;
|
_CollectionView.dataSource=self;
|
_CollectionView.backgroundColor=kGlobalBackgroundColor;
|
[_CollectionView registerNib:[UINib nibWithNibName:@"recommentCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"recommentCollectionViewCell"];
|
[self.view addSubview:_CollectionView];
|
}
|
|
|
/**
|
* 跳转到历史记录
|
*/
|
-(void)JumpToRecordView{
|
LookNoteController *LookNoteLookNoteVC=[[LookNoteController alloc] init];
|
[self.navigationController pushViewController:LookNoteLookNoteVC animated:YES];
|
}
|
|
/**
|
* 跳转到搜索
|
*/
|
-(void)JumpToSearchView{
|
searchViewController *searchVC=[[searchViewController alloc] init];
|
[self.navigationController pushViewController:searchVC animated:YES];
|
}
|
|
/**
|
* 返回
|
*/
|
-(void)backToRoot:(UIButton *)sender{
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
#pragma mark -UICollectionViewDelegate
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
return _arrDate.count;
|
|
}
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
recommentCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"recommentCollectionViewCell" forIndexPath:indexPath];
|
//设置cell的背景色(白色)
|
cell.backgroundColor=[UIColor whiteColor];
|
//在这里对cell进行设置
|
NSDictionary *VideoInformation=_arrDate[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"];
|
|
if(TagStr1.length>1){
|
cell.recommentReplyLabel.text=TagStr1;
|
}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"]==nil||[[VideoInformation objectForKey:@"WatchCount"] isEqualToString:@"(null)"]){
|
recommentStr=[NSString stringWithFormat:@"0"];
|
}else 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"]==nil) {
|
commentCountStr=[NSString stringWithFormat:@"0"];
|
}else 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];
|
|
//添加阴影
|
cell.layer.masksToBounds = NO;
|
cell.layer.contentsScale = [UIScreen mainScreen].scale;
|
cell.layer.shadowOpacity = 0.7f;
|
cell.layer.shadowRadius = 1.0f;
|
cell.layer.shadowOffset = CGSizeMake(0,2);
|
cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
|
cell.layer.shadowColor = kGlobalLightGreyColor_223.CGColor;
|
//设置缓存
|
cell.layer.shouldRasterize = YES;
|
//设置抗锯齿边缘
|
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
return cell;
|
}
|
|
#pragma mark -UICollectionViewDataSource
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
XYRDetailViewController *play=[[XYRDetailViewController alloc] init];
|
[YTHsharedManger startManger].preController = self;
|
play.modalPresentationStyle = 0;
|
play.Model = [XYRVideoInfoModel yy_modelWithDictionary:_arrDate[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/32+55);
|
}
|
|
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
|
//上、左、下、右的边距
|
return UIEdgeInsetsMake(10, 10, 10, 10);
|
}
|
|
|
|
|
/*
|
#pragma mark - Navigation
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
// Get the new view controller using [segue destinationViewController].
|
// Pass the selected object to the new view controller.
|
}
|
*/
|
|
@end
|