//
|
// XYRDetailViewController.m
|
// BuWanVideo2.0
|
//
|
// Created by weikou on 16/8/5.
|
// Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "AppDelegate.h"
|
|
#import "XYRDetailViewController.h"
|
#import "PPTVController.h"
|
#import "XYRVideoDetailModel.h"
|
#import "UIImageView+WebCache.h"
|
|
#import "CMuneBar.h"//视频源
|
#import "HMSegmentedControl.h"//详情与评论
|
|
//3种collectionViewCell的样式
|
#import "GroupCollectionViewCell.h"//选集
|
#import "IntroductionCollectionViewCell.h"//简介
|
#import "GuessYouLikeCollectionViewCell.h"//猜你喜欢
|
|
#import "titleCollectionReusableView.h"
|
#import "GroupSection.h"
|
#import "GroupSmallSection.h"
|
#import "GroupfootSection.h"
|
#import "ADCollectionReusableView.h"
|
#import "AttentionCollectionReusableView.h"
|
#import "newADCollectionViewCell.h"
|
|
//登录
|
#import "LoggingViewController.h"
|
|
#import "commentHeaderView.h"
|
#import "CommentTableViewCell.h"
|
|
//加载网页视图的框架,WK需要使用到的头文件
|
#import <WebKit/WebKit.h>
|
|
#import "Share.h"
|
#import "WEBViewController.h"
|
|
//广点通原生广告
|
//#import "GDTNativeAd.h"
|
//广点通banner广告
|
//#import "GDTMobBannerView.h"
|
|
//优酷播放器
|
//#import "YTEngineOpenViewManager.h"
|
//#import "YYMediaPlayerEvents.h"
|
|
//PPTV播放器导入
|
//#import "PPTVview.h"
|
//#import <PPTVSdk/PPTVSdk.h>
|
|
#import "LGLAlertView.h"
|
|
#import "GDTNativeExpressAd.h"
|
#import "GDTNativeExpressAdView.h"
|
|
#import <BUAdSDK/BUAdSDK.h>
|
|
#define MARGIN 5
|
#define BACK_WIDTH (DEVICE_TYPE_IPAD ? 30 : 20)
|
#define ui_round_size(x) (DEVICE_TYPE_IPAD ? ((x) < 50 ? 50 : (x)) : ((x) < 44 ? 44 : (x)))
|
#define TEXTVIEW_FONT (DEVICE_TYPE_IPAD ? 15 : 12)
|
#define TEXTVIEW_WIDTH (DEVICE_TYPE_IPAD ? 400 : 250)
|
#define TEXTVIEW_HEIGHT 30
|
#define BETWEEN_BOUND_FULL 100
|
#define BETWEEN_BOUND_NORMAL 20
|
|
@interface XYRDetailViewController ()<CMuneBarDelegate,UIScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,YTHNetDelegateRecommend,UIGestureRecognizerDelegate,YTHBacktoApplicationsDelegate,GDTNativeExpressAdDelegete,HXEasyCustomShareViewDelegate,BUNativeExpressFullscreenVideoAdDelegate>{
|
int _gather;//集数加载更多的控制变量,默认为1
|
int isCollectNum;//当前选中的集
|
|
UIView *_replyMessageView;//回复的输入视图
|
UIButton *sendButton;//回复按钮
|
UITextField *_textField;//回复的输入框
|
NSString *_clickedStr;//点击的哪一个回复评论,用于记录位置信息
|
|
NSDictionary *_commentDataDic;//当前用户的评论信息
|
NSMutableArray *_commentDataArr;//当前视频的用户评论的回复信息
|
|
int abc;
|
int commentPage;//评论请求第几页,一页30条评论
|
|
BOOL displayInsIntroduction;//用于判断是否显示简介,通过改变简介大高度达到隐藏简介的效果
|
|
CGSize CELLSize;//选择集cell的大小
|
|
//广点通原生广告
|
// GDTNativeAd *_nativeAd; //原生广告实例
|
// NSMutableArray *nativeArray;//存储请求下来的原生广告信息
|
}
|
|
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageH;//顶部图片的高
|
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *MarkToTop;//返回键离顶部的距离
|
@property (weak, nonatomic) IBOutlet UIView *ADBannerView;//芒果banner广告视图
|
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ADBannerViewH;//广告视图banner的高
|
|
@property (strong, nonatomic) CMuneBar *MuneBar;//视频源选择器
|
@property (weak, nonatomic) IBOutlet UIButton *playBtn;//播放按钮
|
|
@property (weak, nonatomic) IBOutlet UIButton *backBtn;//详情页面的返回按钮
|
@property (weak, nonatomic) IBOutlet YYAnimatedImageView *image;//顶部视频图片
|
@property (weak, nonatomic) IBOutlet UILabel *detailTitle;//顶部的标题
|
@property (weak, nonatomic) IBOutlet UILabel *detailTitleBackgroundColor;//顶部标题背景
|
@property (weak, nonatomic) IBOutlet UIButton *backgroundButton;//覆盖在头图片的Button,响应播放事件
|
|
@property (weak, nonatomic) IBOutlet UILabel *SegmentView;
|
|
@property (nonatomic , strong) UICollectionView *collectionView;
|
@property (nonatomic , strong) UITableView *commenttableview;
|
|
@property (nonatomic , strong) XYRVideoDetailModel *DetailModel;//详细界面的数据模型
|
@property (nonatomic , strong) NSArray *VideoDetailList;//获取到得集数
|
@property (nonatomic , strong) NSMutableArray *ResourceList;//视频源列表
|
@property (nonatomic , strong) NSString *NewResource;//当前的视频源
|
|
@property (nonatomic, strong) HMSegmentedControl *segmentedControl;//评论与详情的segment
|
@property (nonatomic, strong) UIScrollView *scrollView;//评论与详情的视图
|
|
@property (nonatomic,strong) NSArray *RelativeVideos;//获取到的相关视频的数据
|
@property (nonatomic,strong) NSArray *GuessYoulike;//获取到的猜你喜欢的数据
|
@property (nonatomic,strong) NSArray *PeopleSeeVideo;//获取到的大家都在看的数据
|
|
//优酷的三个属性:
|
//@property (nonatomic, retain) YTEngineOpenViewManager *viewManager;
|
//@property (nonatomic, strong) YYMediaPlayer *cloudPlayer;
|
@property (nonatomic, retain) UIButton *backButton;
|
@property (nonatomic, retain) UITextView *textView;
|
@property (nonatomic, assign) BOOL YKloadSuccess; //优酷创建成功
|
|
//PPTV
|
//@property (nonatomic, strong) PPTVview *pptvview;
|
@property (nonatomic, assign) BOOL isPPTVSuccess; //PPTV创建成功
|
@property (nonatomic, strong) UIButton *collectionbt; //外部收藏按钮
|
@property (nonatomic, strong) NSString *showurl; //PPTV来源
|
@property (nonatomic, assign) CGRect playerFrame;
|
@property (nonatomic, assign) CGRect cloudPlayerFrame;
|
@property (nonatomic, strong) NSDate *startTime;
|
@property (nonatomic, strong) NSArray *expressAdViews;
|
@property (nonatomic, strong) GDTNativeExpressAd *nativeExpressAd;
|
|
@property (nonatomic, strong) BUNativeExpressFullscreenVideoAd *fullscreenVideoAd;
|
|
@end
|
|
@implementation XYRDetailViewController
|
//@synthesize player = _player;
|
@synthesize islocal;
|
@synthesize videoItem;
|
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
self.startTime = [NSDate date];
|
//实现网络监控的代理
|
ApplicationDelegate.YNetdelegateRecommend = self;
|
//实现出去应用或者回到应用的处理
|
ApplicationDelegate.YBackAppDelegate = self;
|
if (KIsiPhoneX) {
|
// self.topLayout.constant = 20;
|
self.backLayout.constant = 39;
|
}else{
|
// self.topLayout.constant = 0;
|
self.backLayout.constant = 19;
|
|
}
|
//加载基础数据
|
[self loadData];
|
//视频名称背景色
|
[self addTitleBackView];
|
//加载视频详情页面的数据
|
[self getVideoDetailViewWithMovieId:self.Model.Id WithThirdType:self.Model.ThirdType WithResourceId:nil];
|
}
|
|
- (void)loadFullscreenVideoAd {
|
|
NSDictionary *dictionary = [[NSUserDefaults standardUserDefaults] objectForKey:@"buUserInfo"];
|
NSDate *datenow = [NSDate date]; // 现在时间
|
NSInteger timeSp = [datenow timeIntervalSince1970]*1000;
|
if(dictionary)
|
{
|
if ([dictionary[@"vipExpireTime"] integerValue] > timeSp) {
|
return;
|
}
|
}
|
|
self.fullscreenVideoAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:@"945472378"];
|
self.fullscreenVideoAd.delegate = self;
|
[self.fullscreenVideoAd loadAdData];
|
}
|
|
//此方法在视频广告素材加载成功时调用。
|
- (void)nativeExpressFullscreenVideoAdDidLoad:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
|
}
|
|
//当视频广告素材加载失败时调用此方法。
|
- (void)nativeExpressFullscreenVideoAd:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
|
|
}
|
|
//此方法在成功呈现nativeExpressAdView时调用。
|
- (void)nativeExpressFullscreenVideoAdViewRenderSuccess:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd {
|
|
}
|
|
//当nativeExpressAdView无法呈现时,将调用此方法
|
- (void)nativeExpressFullscreenVideoAdViewRenderFail:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error {
|
|
}
|
//当视频缓存成功时调用此方法
|
- (void)nativeExpressFullscreenVideoAdDidDownLoadVideo:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
[fullscreenVideoAd showAdFromRootViewController:self];
|
}
|
|
//此方法在用户单击“跳过”按钮时调用
|
- (void)nativeExpressFullscreenVideoAdDidClickSkip:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
|
}
|
|
//此方法在视频广告即将关闭时调用。
|
- (void)nativeExpressFullscreenVideoAdWillClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
|
}
|
|
//关闭视频广告时调用此方法
|
- (void)nativeExpressFullscreenVideoAdDidClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
|
}
|
|
//此方法在视频广告播放完成或发生错误时调用。
|
- (void)nativeExpressFullscreenVideoAdDidPlayFinish:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
|
|
|
}
|
|
- (void)viewWillAppear:(BOOL)animated {
|
[super viewWillAppear:animated];
|
//让页面保持常亮
|
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
|
//增加通知中心监听,当键盘出现或消失时收出消息
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
//增加通知中心监听,
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(replyMessage:) name:@"reply" object:nil];
|
//友盟页面统计
|
//[MobClick beginLogPageView:@"视频播放页面"];
|
//显示状态栏
|
[[UIApplication sharedApplication] setStatusBarHidden:NO];
|
//网络状态
|
[self NetWorkStuas];
|
}
|
|
-(void)viewWillDisappear:(BOOL)animated{
|
[super viewWillDisappear:animated];
|
//删除通知中心的监听
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
//让页面关闭常亮
|
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
//友盟页面统计
|
// [MobClick endLogPageView:@"视频播放页面"];
|
|
//强制竖屏
|
NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
|
[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
|
|
NSNumber *PortraitorientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
|
[[UIDevice currentDevice] setValue:PortraitorientationUnknown forKey:@"orientation"];
|
//显示状态栏
|
[[UIApplication sharedApplication] setStatusBarHidden:NO];
|
}
|
|
/**
|
* 退出视频播放详细界面
|
*/
|
- (IBAction)backToMainViewController:(id)sender {
|
[self backToRootView];
|
|
}
|
|
|
- (void)viewWillLayoutSubviews{
|
[super viewWillLayoutSubviews];
|
[self.collectionView.collectionViewLayout invalidateLayout];
|
}
|
|
/**
|
* 点击收藏视频
|
*
|
* @param sender 收藏按钮
|
*/
|
- (void)ClickCollection:(UIButton *)sender {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
|
if (sender.isSelected) {
|
[sender setSelected:NO];
|
[[YTHNetInterface startInterface] getScoreCollectWithUid:[YTHsharedManger startManger].Uid withId:self.Model.Id withThirdType:self.Model.ThirdType WithType:@"0" withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
if([self.NewResource intValue]==16){
|
// [_pptvview SuccessCollection:NO]; //通知PPTV播放器收藏
|
}
|
}else{//取消收藏失败
|
[sender setSelected:YES];
|
}
|
}];
|
}else{
|
[sender setSelected:YES];
|
[[YTHNetInterface startInterface] getScoreCollectWithUid:[YTHsharedManger startManger].Uid withId:self.Model.Id withThirdType:self.Model.ThirdType WithType:@"1" withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
if([self.NewResource intValue]==16){
|
// [_pptvview SuccessCollection:YES]; //通知PPTV播放器收藏
|
}
|
}else{//收藏失败
|
[sender setSelected:NO];
|
}
|
}];
|
}
|
}else{
|
//未登录,引导用户登录
|
LoggingViewController *loginVC=[[LoggingViewController alloc] init];
|
loginVC.modalPresentationStyle = 0;
|
loginVC.ispresent=YES;
|
[self presentViewController:loginVC animated:YES completion:^{
|
|
}];
|
|
}
|
|
}
|
|
|
|
/**
|
* 加载已经获取到的数据
|
*/
|
-(void)loadData{
|
commentPage=1;
|
abc=1;
|
//集数的控制显示,默认为1
|
_gather=1;
|
//视频名称
|
self.detailTitle.text=self.Model.Name;
|
//设置图片的高
|
self.imageH.constant=KScreenW/16*9;
|
//设置banner广告视图的高
|
self.ADBannerViewH.constant=50;
|
//视频的图片
|
self.image.clipsToBounds=YES;
|
self.image.contentMode=UIViewContentModeScaleAspectFill;
|
[self.image setYthImageWithURL:self.Model.Hpicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
}
|
|
|
/**
|
* 视频名称背景色
|
*/
|
-(void)addTitleBackView{
|
CAGradientLayer *gradientLayer= [CAGradientLayer layer]; //设置渐变效果
|
gradientLayer.bounds = _detailTitleBackgroundColor.bounds;
|
gradientLayer.borderWidth = 0;
|
gradientLayer.frame =CGRectMake(_detailTitleBackgroundColor.bounds.origin.x, _detailTitleBackgroundColor.bounds.origin.y, KScreenW, 55);
|
gradientLayer.colors = [NSArray arrayWithObjects:
|
(id)[kGlobalMainColor CGColor],
|
(id)[[UIColor clearColor] CGColor], nil];
|
gradientLayer.startPoint = CGPointMake(0.0, 0.0);
|
gradientLayer.endPoint = CGPointMake(0.0, 1.0);
|
[_detailTitleBackgroundColor.layer insertSublayer:gradientLayer atIndex:0];
|
}
|
|
|
/**
|
* 评论与详情的切换视图
|
*/
|
-(void)segmentView{
|
if(_segmentedControl==nil){
|
self.segmentedControl = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 80, 35)];
|
self.segmentedControl.selectedSegmentIndex = 0;
|
self.segmentedControl.selectionIndicatorHeight = 3.0f;
|
self.segmentedControl.backgroundColor = [UIColor whiteColor];
|
self.segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15]};
|
self.segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15]};
|
self.segmentedControl.selectionIndicatorColor = kGlobalYellowColor;
|
self.segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
|
self.segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
|
self.segmentedControl.type=HMSegmentedControlTypeText;
|
self.SegmentView.userInteractionEnabled=YES;
|
[self.SegmentView addSubview:self.segmentedControl];
|
|
__weak typeof(self) weakSelf = self;
|
[self.segmentedControl setIndexChangeBlock:^(NSInteger index) {
|
[weakSelf.scrollView scrollRectToVisible:CGRectMake(KScreenW * index, KScreenW/48*27+35, KScreenW, KScreenH-(KScreenW/48*27)-35) animated:YES];
|
//考虑到用户在输入的时候突然切换到详情,这个时候就需要取消评论框的第一响应
|
if(index==0){
|
[_textField resignFirstResponder];
|
}
|
}];
|
|
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, KScreenW/48*27+35, KScreenW, KScreenH-(KScreenW/48*27)-35)];
|
self.scrollView.backgroundColor =[UIColor whiteColor];
|
self.scrollView.pagingEnabled = YES;
|
self.scrollView.showsHorizontalScrollIndicator = NO;
|
self.scrollView.contentSize = CGSizeMake(KScreenW , KScreenH-(KScreenW/48*27)-35);
|
self.scrollView.delegate = self;
|
[self.scrollView scrollRectToVisible:CGRectMake(0, 0, KScreenW, KScreenH-(KScreenW/48*27)-35) animated:NO];
|
[self.view addSubview:weakSelf.scrollView];
|
//初始化详情视图
|
[self detailedInformationView];
|
//初始化评论视图
|
[self commentView];
|
}
|
|
//评论数
|
// NSString *commentNub=[NSString stringWithFormat:@"评 论(%ld)",(long)_DetailModel.Data.CommentCount];
|
self.segmentedControl.sectionTitles = @[@"详 情"];
|
}
|
|
/**
|
* 初始化详情视图
|
*/
|
|
-(void)detailedInformationView{
|
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
|
//指定布局方式为垂直
|
flow.scrollDirection = UICollectionViewScrollDirectionVertical;
|
flow.minimumLineSpacing = 10;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距)
|
flow.minimumInteritemSpacing = 10;//两个单元格之间的最小间距
|
|
//创建CollectionView并指定布局对象
|
if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
|
self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, _scrollView.frame.size.height ) collectionViewLayout:flow];
|
}else{
|
self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, _scrollView.frame.size.height-50) collectionViewLayout:flow];
|
}
|
self.collectionView.backgroundColor = kGlobalBackgroundColor;
|
self.collectionView.dataSource = self;
|
self.collectionView.delegate = self;
|
[self.scrollView addSubview:self.collectionView];
|
|
//注册cell
|
//集数的cell
|
[self.collectionView registerNib:[UINib nibWithNibName:@"GroupCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"GroupCellID"];
|
//简介 IntroductionCollectionViewCell
|
[self.collectionView registerNib:[UINib nibWithNibName:@"IntroductionCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"IntroductionCollectionViewCell"];
|
//猜你喜欢、相关视频、大家都在看
|
[self.collectionView registerNib:[UINib nibWithNibName:@"GuessYouLikeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"GuessYouLikeCollectionViewCell"];
|
//5月18号,新增加的广告位
|
[self.collectionView registerNib:[UINib nibWithNibName:@"newADCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"newADCollectionViewCell"];
|
//collectiom的headView和footView
|
[self.collectionView registerNib:[UINib nibWithNibName:@"titleCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleCollectionReusableViewID"];
|
[self.collectionView registerNib:[UINib nibWithNibName:@"GroupSection" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"GroupSectionID"];
|
[self.collectionView registerNib:[UINib nibWithNibName:@"GroupSmallSection" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"GroupSmallSection"];
|
[self.collectionView registerNib:[UINib nibWithNibName:@"GroupfootSection" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"GroupfootSectionID"];
|
[self.collectionView registerNib:[UINib nibWithNibName:@"ADCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView"];
|
[self.collectionView registerNib:[UINib nibWithNibName:@"AttentionCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"AttentionCollectionReusableViewID"];
|
}
|
|
/**
|
* 初始化评论视图
|
*/
|
-(void)commentView{
|
//显示评论的视图
|
_commenttableview= [[UITableView alloc] initWithFrame:CGRectMake(KScreenW, 0, KScreenW, _scrollView.frame.size.height-50) style:UITableViewStyleGrouped];
|
_commenttableview.backgroundColor=kGlobalBackgroundColor;
|
_commenttableview.delegate=self;
|
_commenttableview.dataSource=self;
|
_commenttableview.separatorStyle = UITableViewCellSeparatorStyleNone;
|
_commenttableview.backgroundColor=kGlobalBackgroundColor;
|
[_commenttableview registerNib:[UINib nibWithNibName:@"CommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"CommentCellId"];
|
_commenttableview.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
[self reloadCommentView];
|
}];
|
|
//创建手势事件
|
UITapGestureRecognizer *Tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignResponder)];
|
[_commenttableview addGestureRecognizer:Tap];
|
Tap.delegate=self;
|
|
UIImageView *backimage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, KScreenW-80 , 30)];
|
backimage.image=[[UIImage imageNamed:@"输入框"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 40, 20, backimage.frame.size.width-40)];
|
|
//回复的输入视图
|
if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
|
_replyMessageView=[[UIView alloc] initWithFrame:CGRectMake(KScreenW, _scrollView.frame.size.height-50, KScreenW, 50)];
|
}else{
|
_replyMessageView=[[UIView alloc] initWithFrame:CGRectMake(0, KScreenH-50, KScreenW, 50)];
|
}
|
_replyMessageView.backgroundColor=[UIColor whiteColor];
|
|
//回复的输入框
|
_textField=[[UITextField alloc] initWithFrame:CGRectMake(20, 10, KScreenW-90, 30)];
|
_textField.delegate=self;
|
_textField.backgroundColor=kGlobalBackgroundColor;
|
_textField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
_textField.placeholder=@" 我也来说两句...";
|
|
//回复发送按钮
|
sendButton=[[UIButton alloc] initWithFrame:CGRectMake(KScreenW-60, 10, 50, 30)];
|
sendButton.tag=888;
|
[sendButton setBackgroundImage:[[UIImage imageNamed:@"发表"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
|
|
[sendButton setTitleColor:kGlobalMainColor forState:UIControlStateNormal];
|
[sendButton setTitle:@"发送" forState:UIControlStateNormal];
|
[sendButton addTarget:self action:@selector(ClickSendComment) forControlEvents:UIControlEventTouchUpInside ];
|
|
[_replyMessageView addSubview:backimage];
|
[_replyMessageView addSubview:_textField];
|
[_replyMessageView addSubview:sendButton];
|
|
[self.scrollView addSubview:_commenttableview];
|
if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
|
[self.scrollView addSubview:_replyMessageView];
|
}else{
|
[self.view addSubview:_replyMessageView];
|
}
|
}
|
|
/**
|
* 加载视频源
|
*/
|
-(void)loadResourceItem{
|
self.ResourceList=[[NSMutableArray alloc] initWithArray:_DetailModel.Data.ResourceList];
|
NSMutableArray *arr=[[NSMutableArray alloc] initWithCapacity:(_DetailModel.Data.ResourceList.count+5)];
|
NSArray *ResourceList=[[NSMutableArray alloc] initWithArray:_DetailModel.Data.ResourceList];
|
for (int i=0; i<_DetailModel.Data.ResourceList.count; i++) {
|
arr[i]=[ResourceList[i] objectForKey:@"Picture"];
|
if ([[ResourceList[i] objectForKey:@"Checked"] intValue]==1) {
|
self.NewResource=[ResourceList[i] objectForKey:@"Id"];
|
//交换数组元素,让默认的播放源放在第一个
|
NSString *str=arr[i];
|
arr[i]=arr[0];
|
arr[0]=str;
|
|
Resourcelist *res=ResourceList[i];
|
_ResourceList[i]=ResourceList[0];
|
_ResourceList[0]=res;
|
}
|
}
|
|
if(arr.count>0){
|
if (_MuneBar!=nil) {
|
_MuneBar=nil;
|
}
|
_MuneBar= [[CMuneBar alloc] initWithItems:arr size:CGSizeMake(40, 40) type:kMuneBarTypeLineRight];
|
[_MuneBar setUserInteractionEnabled:YES];
|
_MuneBar.delegate = self;
|
_MuneBar.center = CGPointMake(((KScreenW/3)-80)/2, 22);
|
[self.collectionView bringSubviewToFront:_MuneBar];
|
// [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
|
[self.collectionView reloadData];
|
|
}
|
}
|
//默认网络情况
|
- (void)NetWorkStuas{
|
|
switch ([YTHsharedManger startManger].NetworkStatus) {
|
case 0:{//当前网络不可用
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"message:@"当前网络不可用,是否使用连接网络?"preferredStyle:UIAlertControllerStyleAlert];
|
//取消
|
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
[self backToRootView];
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
//去连接网络
|
[alert addAction:[UIAlertAction actionWithTitle:@"连接网络" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] ];
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
[self presentViewController:alert animated:YES completion:^{
|
|
}];
|
}
|
break;
|
case 1:{//移动网络
|
static BOOL isFirst = YES;
|
if (!isFirst) {
|
return;
|
}else{
|
isFirst = NO;
|
}
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示"message:@"您目前没有连接WIFi,是否使用流量继续观看" preferredStyle:UIAlertControllerStyleAlert];
|
//继续观看
|
[alert addAction:[UIAlertAction actionWithTitle:@"继续" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
//去连接网络
|
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
}]];
|
[self presentViewController:alert animated:YES completion:^{
|
|
}];
|
}
|
break;
|
case 2://WIFI
|
|
break;
|
case 3:{//当前网络无法检测,需要用户自行判断网络
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"message:@"无法监测当前网络,请自行判断网络!"preferredStyle:UIAlertControllerStyleAlert];
|
//继续观看
|
[alert addAction:[UIAlertAction actionWithTitle:@"继续观看" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
//取消观看
|
[alert addAction:[UIAlertAction actionWithTitle:@"不看了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
[self backToRootView];
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
[self presentViewController:alert animated:YES completion:^{
|
|
}];
|
}
|
break;
|
}
|
}
|
|
-(void)resignResponder{
|
[_textField resignFirstResponder];
|
}
|
|
#pragma mark 重写方法,允许这个界面可以横屏
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
|
- (NSUInteger)supportedInterfaceOrientations
|
#else
|
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
|
#endif
|
{
|
// if(_isPPTVSuccess){ //如果是PPTV 播放 返回可旋转
|
// if(_pptvview.playoptions.isHalfScreen){
|
// return UIInterfaceOrientationMaskLandscape;
|
// }else{
|
// return UIInterfaceOrientationMaskPortrait;
|
// }
|
// }
|
if (self.YKloadSuccess==YES) { //如果加载了优酷播放器
|
return UIInterfaceOrientationMaskAllButUpsideDown;
|
}
|
return UIInterfaceOrientationMaskPortrait;
|
}
|
|
/**
|
* 把当前播放记录写入文件
|
*
|
* @param currentURLString 播放链接
|
*/
|
-(void)recordHistoryToFile:(NSString *)currentURLString{
|
NSMutableDictionary *historyDict = [NSMutableDictionary dictionary];
|
[historyDict setObject:[NSNumber numberWithInteger:self.DetailModel.Data.VideoDetailList.count] forKey:@"TotalNum"];//总共的集数
|
if(self.DetailModel.Data.Name){//存储视频的名称
|
[historyDict setObject:self.DetailModel.Data.Name forKey:@"Name"];
|
}else{
|
return;
|
}
|
if (self.DetailModel.Data.CanSave) {//存储视频是否可下载
|
[historyDict setObject:[NSNumber numberWithBool:self.DetailModel.Data.CanSave] forKey:@"CanSave"];
|
}
|
if(self.DetailModel.Data.Id){//存储当前视频的分集id
|
[historyDict setObject:self.DetailModel.Data.Id forKey:@"movieId"];
|
}
|
if(self.Model.Id){//存储当前视频的视频id
|
[historyDict setObject:self.Model.Id forKey:@"Id"];
|
}
|
if(self.Model.ThirdType){
|
[historyDict setObject:self.Model.ThirdType forKey:@"ThirdType"];
|
}
|
NSData *imagedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.DetailModel.Data.Hpicture]];//存储当前的图片
|
if (imagedata){
|
[historyDict setObject:imagedata forKey:@"Hpicturedata"];
|
}else{
|
return;
|
}
|
if (self.DetailModel.Data.Hpicture) {
|
[historyDict setObject:self.DetailModel.Data.Hpicture forKey:@"Hpicture"];
|
}
|
if(currentURLString){//当前播放链接
|
[historyDict setObject:currentURLString forKey:@"URLString"];
|
}else{
|
return;
|
}
|
Videodetaillist *videodetailList=self.DetailModel.Data.VideoDetailList[isCollectNum-1];
|
NSString *str=[videodetailList valueForKey:@"Tag"];
|
if(str!=nil){
|
[historyDict setObject:str forKey:@"Tag"];
|
}
|
NSMutableArray *movieInfoArray = [NSMutableArray arrayWithCapacity:0];
|
NSMutableArray *movieInfoArrayResult = [NSMutableArray arrayWithCapacity:0];
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
if (![fileManager fileExistsAtPath:HISTORYFILE]){
|
[fileManager createFileAtPath:HISTORYFILE contents:nil attributes:nil];
|
[movieInfoArrayResult addObject:historyDict];
|
[movieInfoArrayResult writeToFile:HISTORYFILE atomically:YES];
|
}else{
|
movieInfoArray = [NSMutableArray arrayWithContentsOfFile:HISTORYFILE];
|
if (movieInfoArray.count>=10) {
|
[movieInfoArray removeLastObject];
|
}
|
for (int i=0; i<movieInfoArray.count; i++){
|
if ([[[movieInfoArray objectAtIndex:i] valueForKey:@"Id"] isEqual:[historyDict objectForKey:@"Id"]]){
|
[movieInfoArray removeObjectAtIndex:i];
|
[movieInfoArrayResult addObject:historyDict];
|
[movieInfoArrayResult addObjectsFromArray:movieInfoArray];
|
[movieInfoArrayResult writeToFile:HISTORYFILE atomically:YES];
|
return;
|
}
|
}
|
[movieInfoArrayResult addObject:historyDict];
|
[movieInfoArrayResult addObjectsFromArray:movieInfoArray];
|
[movieInfoArrayResult writeToFile:HISTORYFILE atomically:YES];
|
}
|
}
|
|
/**
|
* 播放详情页面的分享按钮被触发
|
*/
|
- (void)clickShareButton:(UIButton *)sender{
|
// [Share shareAPP:self];
|
}
|
|
/**
|
* 点击关注或取消关注
|
*/
|
-(void)ClickAttentionButton:(UIButton *)sender{
|
if ([sender isSelected]) {//如果当前是选择中状态,用户将进行取消关注的操作
|
[sender setSelected:NO];//在用户取关请求之前将按钮设为取关状态,是为了提高界面的响应,避免用户觉得界面反应迟钝
|
//用户进行关注操作,说明用户已经登录,所以不需进行判断是否登录
|
[[YTHNetInterface startInterface] cancelAttentionWithUid:[YTHsharedManger startManger].Uid WithVideoId:self.Model.Id WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
[sender setSelected:NO];
|
}else{
|
//取关失败
|
[sender setSelected:YES];
|
[SVProgressHUD showErrorWithStatus:@"取关失败!"];
|
}
|
}];
|
|
}else{//用户进行关注操作
|
//首先需要判断用户是否登录
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
|
[sender setSelected:YES];
|
//已登录
|
[[YTHNetInterface startInterface] addAttentionWithUid:[YTHsharedManger startManger].Uid WithVideoId:self.Model.Id WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
[sender setSelected:YES];
|
}else{
|
//提示用户关注失败
|
[sender setSelected:NO];
|
[SVProgressHUD showErrorWithStatus:@"关注失败!\n请你检查网络是否流畅!"];
|
}
|
}];
|
}else{
|
//未登录,引导用户登录
|
LoggingViewController *loginVC=[[LoggingViewController alloc] init];
|
loginVC.modalPresentationStyle = 0;
|
loginVC.ispresent=YES;
|
[self presentViewController:loginVC animated:YES completion:^{
|
|
}];
|
}
|
}
|
}
|
|
/**
|
* 点击查看广告或更多的方法
|
*/
|
-(void)getMoreInformation:(UIButton *)sender{
|
if (sender.tag==521) {
|
NSLog(@"选集更多");
|
_gather++;
|
//刷新视图
|
// [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
|
[self.collectionView reloadData];
|
|
}else {//广点通广告
|
// GDTNativeAdData * info =nativeArray[sender.tag-523];
|
// [_nativeAd clickAd:info];
|
}
|
}
|
|
/**
|
* 视频的播放页面被触发,跳转到全屏,通过网页观看影片
|
*/
|
-(void)loadWebView:(UIButton *)sender{//这里还需要判断是否已经获取到播放页面的详细数据
|
NSDate *date = [NSDate date];
|
NSTimeInterval seconds = [date timeIntervalSinceDate:self.startTime];
|
NSLog(@"%f",seconds);
|
static BOOL bor = NO;
|
if (seconds < 1.5 && bor) {
|
bor = YES;
|
return;
|
}
|
self.startTime = date;
|
//取消textfield的第一响应
|
[_textField resignFirstResponder];
|
if(isCollectNum == 0){
|
isCollectNum = 1;
|
}
|
_gather = 1;
|
//先判断是否获取到视频的详情信息,否者会崩溃
|
if(self.VideoDetailList.count!=0){
|
//判断是否加载[优酷播放器
|
if([self.NewResource intValue]==15){
|
//使用优酷播放器
|
[self YKPlay:@"0"];
|
}else if([self.NewResource intValue]==16){
|
//PPTV播放器
|
[self PPTVplay:@"0" WithBoolInit:NO];
|
}else if([self.NewResource intValue]==18){
|
//乐视播放器
|
[self YKPlay:@"0"];
|
}else{
|
//其他 爱奇艺 和 搜狐 网页播放类型
|
[self startToPlay:[NSString stringWithFormat:@"0"]];
|
}
|
NSArray *arr = [_collectionView indexPathsForVisibleItems];
|
NSIndexPath * targetIndex=[NSIndexPath new];
|
for( int i = 0 ; i < arr.count ; ++i){
|
NSIndexPath * temp = arr[i];
|
if(isCollectNum-1 == temp.row ){
|
targetIndex = temp;
|
}
|
}
|
// [_collectionView reloadItemsAtIndexPaths:@[targetIndex]];
|
[_collectionView reloadData];
|
}
|
}
|
|
-(void)selfchose:(NSNotification*)notification{
|
NSDictionary* num = [notification userInfo];
|
isCollectNum = ((NSNumber*)[num objectForKey:@"index"]).intValue +1;
|
|
if([self.NewResource intValue]==16){ //PPTV播放器
|
[self PPTVplay:[NSString stringWithFormat:@"%d",isCollectNum-1] WithBoolInit:_isPPTVSuccess];
|
}else if([self.NewResource intValue]==18){ //乐视播放器
|
[self YKPlay:[NSString stringWithFormat:@"%d",isCollectNum-1]];
|
// [_collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
|
[self.collectionView reloadData];
|
|
}else{
|
[self startToPlay:[NSString stringWithFormat:@"%d",isCollectNum-1]];
|
}
|
|
}
|
|
//在已有的PPTV播放器进行播放
|
//-(void)playPPTVSecend:(NSString*)urlstring{
|
// [SVProgressHUD show];
|
// [_pptvview playvedio:urlstring];
|
// [_pptvview.playoptions.collection OtherChose:isCollectNum-1]; //播放器内部显示同步
|
//}
|
|
|
////PPTV退出亲清除
|
//-(void)PPTVclear{
|
// if(!_pptvview){
|
// return ;
|
// }
|
// [_pptvview clear];
|
//}
|
|
|
//PPTV获取数据
|
-(void)PPTVplay:(NSString *)IDS WithBoolInit:(BOOL)BL{
|
Videodetaillist *lst=self.VideoDetailList[[IDS intValue]];
|
NSString *eId=[_NewResource intValue]==16?[(NSDictionary *)lst objectForKey:@"Id"]:nil;
|
[[YTHNetInterface startInterface] getparseVideoUrlWithUid:[YTHsharedManger startManger].Uid WithId:[(NSDictionary *)lst objectForKey:@"Id"] WithVideoId:self.DetailModel.Data.Id WithSystem:@"1" WithType:[(NSDictionary *)lst objectForKey:@"Type"] WithResourceId:_NewResource WithEID:eId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSLog(@"获取视频播放链接成功");
|
NSDictionary *dictionaryDta = (NSDictionary *)result;
|
|
//视频播放地址
|
NSString *urlstring=[[[dictionaryDta objectForKey:@"Data"] objectForKey:@"Params"] objectForKey:@"playlink"];
|
_showurl = [[dictionaryDta objectForKey:@"Data"] objectForKey:@"Url"];
|
|
//存储当前播放记录
|
[self recordHistoryToFile:urlstring];
|
//隐藏playBtn
|
[_playBtn setHidden:YES];
|
[_backgroundButton setEnabled:YES];
|
|
//加载PPTV播放器
|
if(!BL){ //没有被初始化过
|
// [self playPPTV:urlstring];
|
}else{
|
// [self playPPTVSecend:urlstring];
|
}
|
}else{
|
NSLog(@"获取视频播放链接失败%@",error);
|
}
|
}];
|
}
|
|
/********************优酷**************************/
|
|
|
/**
|
* 获取播放地址,并添加网页播放视图
|
*
|
* @param IDS 播放的集
|
*/
|
-(void)startToPlay:(NSString *)IDS{
|
[SVProgressHUD showWithStatus:@"精彩,马上就来!"];
|
[_playBtn setEnabled:NO];
|
[_backgroundButton setEnabled:NO];
|
Videodetaillist *lst;
|
if ([IDS intValue] <= self.VideoDetailList.count) {
|
lst=self.VideoDetailList[[IDS intValue]];
|
}
|
[[YTHNetInterface startInterface] getparseVideoUrlWithUid:[YTHsharedManger startManger].Uid WithId:[(NSDictionary *)lst objectForKey:@"Id"] WithVideoId:self.DetailModel.Data.Id WithSystem:@"1" WithType:[(NSDictionary *)lst objectForKey:@"Type"] WithResourceId:_NewResource WithEID:nil withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSLog(@"获取视频播放链接成功");
|
[SVProgressHUD show];
|
NSDictionary *dictionaryDta = (NSDictionary *)result;
|
//视频播放地址
|
NSString *urlstring=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"Url"];
|
//判断是站内播放还是站外播放
|
NSNumber *playtype=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"PlayType"];
|
//存储当前播放记录
|
[self recordHistoryToFile:urlstring];
|
//加载网页视图
|
[self addWebViewWithType:playtype WithUrl:urlstring];
|
}else{
|
[SVProgressHUD showErrorWithStatus:@"网络不稳定\n请稍后再试!"];
|
[_playBtn setEnabled:YES];
|
[_backgroundButton setEnabled:YES];
|
}
|
}];
|
}
|
|
/**
|
* 优酷/乐视获取播放地址
|
*
|
* @param IDS 播放第几集
|
*/
|
-(void)YKPlay:(NSString *)IDS{
|
Videodetaillist *lst=self.VideoDetailList[[IDS intValue]];
|
NSString *eId;
|
if ([_NewResource intValue]==15||[_NewResource intValue]==18) {
|
eId=[(NSDictionary *)lst objectForKey:@"Id"];
|
}else{
|
eId=nil;
|
}
|
|
[[YTHNetInterface startInterface] getparseVideoUrlWithUid:[YTHsharedManger startManger].Uid WithId:[(NSDictionary *)lst objectForKey:@"Id"] WithVideoId:self.DetailModel.Data.Id WithSystem:@"1" WithType:[(NSDictionary *)lst objectForKey:@"Type"] WithResourceId:_NewResource WithEID:eId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSLog(@"获取视频播放链接成功");
|
NSDictionary *dictionaryDta = (NSDictionary *)result;
|
//判断是站内播放还是站外播放
|
NSNumber *playtype=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"PlayType"];
|
//判断是站外播放还是站内播放,如果是站外播放还是通过调用网页播放的方式,如果是站内播放就调用优酷播放器
|
if([playtype intValue]==2){//站内播放,乐视播放器已经被移除,所以,站内播放只有优酷
|
//视频播放地址
|
NSDictionary *tempDic=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"Params"];
|
NSString *urlstring=[tempDic objectForKey:@"vid"];
|
//存储当前播放记录
|
[self recordHistoryToFile:urlstring];
|
//隐藏playBtn
|
[_playBtn setHidden:YES];
|
[_backgroundButton setEnabled:YES];
|
if([_NewResource intValue]==15){
|
//加载优酷播放器
|
// [self loadYKPlayer:urlstring];
|
}
|
}else{//站外播放
|
NSString *urlstring=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"Url"];
|
//存储当前播放记录
|
[self recordHistoryToFile:urlstring];
|
[self addWebViewWithType:playtype WithUrl:urlstring];
|
}
|
}else{
|
NSLog(@"获取视频播放链接失败%@",error);
|
}
|
}];
|
}
|
|
|
/**
|
* 加载优酷播放
|
*
|
* @param urlstring 播放地址
|
*/
|
//-(void)loadYKPlayer:(NSString *)urlstring{
|
// if(_cloudPlayer==nil){
|
// [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
|
//
|
// _cloudPlayer = [[YYMediaPlayer alloc] init];
|
// _cloudPlayer.controller = self;
|
// _cloudPlayer.view.clipsToBounds = YES;
|
// _cloudPlayer.fullscreen = NO;
|
// _cloudPlayer.platform = @"youku";
|
//
|
// CGSize size = self.view.bounds.size;
|
//
|
// CGFloat width = 0.f;
|
// if (DEVICE_TYPE_IPAD) {
|
// width = 681.f;
|
// } else {
|
// width = KScreenWp;
|
// }
|
//
|
// CGFloat height = width * 9.0f / 16.0f;
|
// _cloudPlayer.view.frame = CGRectMake(0, 0, width, height);
|
//
|
// _playerFrame = CGRectMake(0, 20, size.width, size.height - 20);
|
// _cloudPlayerFrame = _cloudPlayer.view.frame;
|
//
|
// //竖屏时露出状态栏
|
// if ([[UIDevice currentDevice].systemVersion floatValue] >= 7){
|
// CGRect bounds = self.view.frame;
|
// self.view.bounds = bounds;
|
// }
|
//
|
// self.MarkToTop.constant=8.0f;
|
// [self.view addSubview:_cloudPlayer.view];
|
//
|
// [self initViews];
|
//
|
// [_cloudPlayer addEventsObserver:self];
|
//
|
// _cloudPlayer.clientId = YKCLIENTId;
|
// _cloudPlayer.clientSecret = YKCLIENTSECRET;
|
//
|
// // 初始化播放器界面管理器
|
// _viewManager = [[YTEngineOpenViewManager alloc] initWithPlayer:_cloudPlayer];
|
// [_cloudPlayer addEventsObserver:_viewManager];
|
// [self.view bringSubviewToFront:self.backBtn];
|
// self.YKloadSuccess=YES;
|
// }
|
// if (!islocal) {
|
// [_cloudPlayer playVid:urlstring quality:kYYVideoQualityFLV password:nil from:0];
|
// } else {
|
// if (self.videoItem) {
|
// [_cloudPlayer playVideo:(id<YYMediaPlayerItem>)self.videoItem quality:kYYVideoQualityFLV from:0 oldEncrypt:NO];
|
// }
|
// }
|
//}
|
|
- (void)layout:(BOOL)fullscreen{
|
CGFloat backHeight = _backButton.bounds.size.height;
|
CGFloat y = 0;
|
|
if (!fullscreen) {
|
// _cloudPlayer.view.frame = _cloudPlayerFrame;
|
y = (44 - backHeight) / 2;
|
_backButton.frame = CGRectMake(MARGIN, y , BACK_WIDTH, backHeight);
|
} else {
|
// _cloudPlayer.view.frame = self.view.frame;
|
y = (30 - backHeight) / 2 + 20;
|
_backButton.frame = CGRectMake(MARGIN, y, BACK_WIDTH, _backButton.bounds.size.height);
|
}
|
// _textView.frame = CGRectMake(_cloudPlayer.view.center.x - TEXTVIEW_WIDTH/2, _cloudPlayer.view.center.y - TEXTVIEW_HEIGHT/2, TEXTVIEW_WIDTH, TEXTVIEW_HEIGHT);
|
}
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orien{
|
if (DEVICE_TYPE_IPAD) {
|
if (orien == UIInterfaceOrientationPortrait || orien == UIInterfaceOrientationPortraitUpsideDown) {
|
return NO;
|
} else {
|
return [self rotatePlayer:orien];
|
}
|
} else {
|
if (orien == UIInterfaceOrientationPortraitUpsideDown) {
|
return NO;
|
} else {
|
return [self rotatePlayer:orien];
|
}
|
}
|
}
|
|
/**
|
* 优酷播放器方法
|
*/
|
- (void)initViews{
|
// 返回错误码
|
_textView = [[UITextView alloc] init];
|
_textView.backgroundColor = [UIColor clearColor];
|
_textView.textColor = [UIColor whiteColor];
|
_textView.font = [UIFont systemFontOfSize:TEXTVIEW_FONT];
|
_textView.editable = NO;
|
_textView.userInteractionEnabled = NO;
|
// _textView.frame = CGRectMake(_cloudPlayer.view.center.x - TEXTVIEW_WIDTH/2,_cloudPlayer.view.center.y - TEXTVIEW_HEIGHT/2, TEXTVIEW_WIDTH, TEXTVIEW_HEIGHT);
|
[_textView setTextAlignment:NSTextAlignmentCenter];
|
// [_cloudPlayer.view addSubview:_textView];
|
}
|
|
/**
|
* 优酷播放器方法
|
*/
|
- (BOOL)shouldAutorotate{
|
if(_isPPTVSuccess){ //如果是PPTV 播放 返回可旋转
|
return YES;
|
}
|
if([self.NewResource intValue]==15){//优酷的处理方法
|
if (abc==1) {
|
abc++;
|
}else{
|
UIInterfaceOrientation orien = [self interfaceOrientation:[UIDevice currentDevice].orientation];
|
return [self rotatePlayer:orien];
|
}
|
}
|
return YES;
|
}
|
|
/**
|
优酷
|
|
@param orien 方向
|
|
@return 是否旋转
|
*/
|
- (BOOL)rotatePlayer:(UIInterfaceOrientation)orien
|
{
|
if (!DEVICE_TYPE_IPAD) {
|
if (orien == UIInterfaceOrientationPortrait &&
|
self.interfaceOrientation != orien) {
|
// [_cloudPlayer setFullscreen:NO];
|
} else if (UIInterfaceOrientationIsLandscape(orien)) {
|
UIInterfaceOrientation corien = self.interfaceOrientation;
|
if (!UIInterfaceOrientationIsLandscape(corien)) {
|
// [_cloudPlayer setFullscreen:YES];
|
}
|
}
|
}
|
return YES;
|
}
|
|
/**
|
优酷
|
|
@param orien 设备方向
|
*/
|
- (NSInteger)interfaceOrientation:(UIDeviceOrientation)orien
|
{
|
if (DEVICE_TYPE_IPAD) {
|
switch (orien) {
|
case UIDeviceOrientationLandscapeLeft:
|
return UIInterfaceOrientationLandscapeRight;
|
case UIDeviceOrientationLandscapeRight:
|
return UIInterfaceOrientationLandscapeLeft;
|
default:
|
return -1;
|
}
|
} else {
|
switch (orien) {
|
case UIDeviceOrientationPortrait:
|
return UIInterfaceOrientationPortrait;
|
case UIDeviceOrientationLandscapeLeft:
|
return UIInterfaceOrientationLandscapeRight;
|
case UIDeviceOrientationLandscapeRight:
|
return UIInterfaceOrientationLandscapeLeft;
|
default:
|
return -1;
|
}
|
}
|
}
|
|
/**
|
* 优酷播放器方法
|
*/
|
//- (void)endPlayCode:(YYErrorCode)err{
|
// NSString *tip;
|
// switch (err) {
|
// case YYPlayCompleted:
|
// tip = @"该视频已播放完成,点击重新播放";
|
// _textView.text = tip;
|
// break;
|
// case YYPlayCanceled:
|
// break;
|
// case YYErrorClientFormat:
|
// tip = [NSString stringWithFormat:@"client参数格式错误,错误码:%ld", (long)err];
|
// _textView.text = tip;
|
// break;
|
// case YYErrorInvalidClient:
|
// tip = [NSString stringWithFormat:@"client无效或sdk版本过低,错误码:%ld", (long)err];
|
// _textView.text = tip;
|
// break;
|
// case YYErrorPermissionDeny:
|
// tip = [NSString stringWithFormat:@"视频无权限播放,错误码:%ld", (long)err];
|
// _textView.text = tip;
|
// break;
|
// case YYErrorInitOpenView:
|
// tip = [NSString stringWithFormat:@"初始化界面无效,错误码:%ld", (long)err];
|
// _textView.text = tip;
|
// break;
|
// case YYDataSourceError:
|
// tip = [NSString stringWithFormat:@"媒体文件错误,错误码:%ld", (long)err];
|
// _textView.text = tip;
|
// break;
|
// case YYNetworkError:
|
// tip = [NSString stringWithFormat:@"网络连接超时,错误码:%ld, 点击重试", (long)err];
|
// _textView.text = tip;
|
// break;
|
// default:
|
// tip = [NSString stringWithFormat:@"播放发生错误,错误码:%ld, 点击重试", (long)err];
|
// _textView.text = tip;
|
// break;
|
// }
|
//}
|
/**
|
* 优酷播放器方法
|
*/
|
//- (void)startPlay {
|
// if (_viewManager) {
|
// _textView.hidden = YES;
|
// }
|
//}
|
|
- (void)setNewOrientation:(BOOL)fullscreen
|
{
|
UIDeviceOrientation lastDeviceOrien = [UIDevice currentDevice].orientation;
|
UIDeviceOrientation deviceOiren = fullscreen ?
|
UIDeviceOrientationLandscapeLeft : UIDeviceOrientationPortrait;
|
|
if([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
|
NSNumber *oiren = [NSNumber numberWithInt:deviceOiren];
|
[[UIDevice currentDevice] setValue:oiren forKey:@"orientation"];
|
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
|
withObject:oiren];
|
}
|
if (lastDeviceOrien == deviceOiren) {
|
if ([[UIDevice currentDevice].systemVersion floatValue] >= 5.0) {
|
[UIViewController attemptRotationToDeviceOrientation];
|
}
|
}
|
}
|
|
/********************网页(包括爱奇艺。搜狐。腾讯,部分优酷)**************************/
|
|
/**
|
* 加载网页播放视频
|
*
|
* @param playtype 站内还是站外播放
|
* @param urlstring 播放地址
|
*/
|
-(void)addWebViewWithType:(NSNumber *)playtype WithUrl:(NSString *)urlstring{
|
WEBViewController *webVC=[[WEBViewController alloc] init];
|
webVC.url=urlstring;
|
if([_NewResource intValue]==18){
|
webVC.orMake=UIInterfaceOrientationMaskAll;
|
}else{
|
webVC.orMake=UIInterfaceOrientationMaskPortrait;
|
}
|
webVC.modalPresentationStyle = 0;
|
[self presentViewController:webVC animated:YES completion:^{
|
[_playBtn setEnabled:YES];
|
[_backgroundButton setEnabled:YES];
|
[SVProgressHUD dismiss];
|
}];
|
}
|
|
/**
|
* 退出详情页面的方法
|
*/
|
-(void)backToRootView{
|
// if(_isPPTVSuccess){
|
// if(_pptvview.playoptions.isHalfScreen){
|
// [_pptvview FullScreen];
|
// return;
|
// }
|
// [self PPTVclear];
|
// }
|
//
|
[SVProgressHUD dismiss];
|
self.collectionView.delegate = nil;
|
self.collectionView.dataSource = nil;
|
[self.collectionView removeFromSuperview];
|
self.collectionView = nil;
|
// _nativeAd.controller = nil;
|
// _nativeAd.delegate = nil;
|
// [self.player removeEventsObserver:_viewManager];
|
[self dismissViewControllerAnimated:YES completion:nil];
|
//显示状态栏
|
[[UIApplication sharedApplication] setStatusBarHidden:NO];
|
}
|
|
/**
|
* 加载新的基础数据,当用户点击推荐的内容时
|
*/
|
-(void)flashAllView{
|
//重新加载基础数据
|
[self loadData];
|
//加载新的,详细页面数据
|
[self getVideoDetailViewWithMovieId:self.Model.Id WithThirdType:self.Model.ThirdType WithResourceId:nil];
|
}
|
|
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
|
return UIInterfaceOrientationPortrait;
|
}
|
|
- (UIViewController *)fetchCurrentViewController {
|
UIViewController* currentViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
BOOL runLoopFind = YES;
|
while (runLoopFind) {
|
if (currentViewController.presentedViewController) {
|
currentViewController = currentViewController.presentedViewController;
|
} else if ([currentViewController isKindOfClass:[UINavigationController class]]) {
|
UINavigationController* navigationController = (UINavigationController* )currentViewController;
|
currentViewController = [navigationController.childViewControllers lastObject];
|
} else if ([currentViewController isKindOfClass:[UITabBarController class]]) {
|
UITabBarController* tabBarController = (UITabBarController* )currentViewController;
|
currentViewController = tabBarController.selectedViewController;
|
} else {
|
NSUInteger childViewControllerCount = currentViewController.childViewControllers.count;
|
if (childViewControllerCount > 0) {
|
currentViewController = currentViewController.childViewControllers.lastObject;
|
return currentViewController;
|
} else {
|
return currentViewController;
|
}
|
}
|
}
|
return currentViewController;
|
}
|
|
/***********(以下)数据网路加载**************/
|
/**
|
* 获取视频的详细信息并加载
|
*
|
* @param movieid 视频的id
|
* @param thirdtype 视频的来源
|
* @param resourceId 第几集
|
*/
|
-(void)getVideoDetailViewWithMovieId:(NSString *)movieid WithThirdType:(NSString *)thirdtype WithResourceId:(NSString *)resourceId{
|
NSLog(@"%@",self.Model);
|
//提示数据加载
|
[SVProgressHUD showWithStatus:@"加载中"];
|
[[YTHNetInterface startInterface] getVoideoDetailWithUid:[YTHsharedManger startManger].Uid withLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withId:movieid withThirdType:thirdtype withSystem:@"1" WithResourceId:resourceId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
NSLog(@"%@",result);
|
if (isSuccessful) {
|
//瀑布流滑动到顶部
|
[self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES];
|
NSDictionary *dictionaryDta = (NSDictionary *)result;
|
|
if ([dictionaryDta[@"Data"][@"pptv"] boolValue]) {
|
[SVProgressHUD dismiss];
|
// 拦截跳转界面
|
PPTVController *vc = [[PPTVController alloc] init];
|
vc.parms = dictionaryDta[@"Data"];
|
vc.hidesBottomBarWhenPushed = YES;
|
[[YTHsharedManger startManger].preController.navigationController pushViewController:vc animated:YES];
|
|
[self dismissViewControllerAnimated:NO completion:^{}];
|
return;
|
}
|
if ([YTHsharedManger startManger].ad[@"videoDetailFullVideo"] && [YTHsharedManger startManger].ad[@"videoDetailFullVideo"]!=[NSNull null] && [[YTHsharedManger startManger].ad[@"videoDetailFullVideo"][@"type"] isEqualToString:@"csj"]) {
|
[self loadFullscreenVideoAd];
|
}
|
|
_DetailModel = [XYRVideoDetailModel yy_modelWithDictionary:dictionaryDta];
|
//更新详情页的视频图片
|
[self.image setYthImageWithURL:_DetailModel.Data.PlayPicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
//在这里判断主演和主要内容是否为空,如果同时为空,就隐藏简介
|
if((_DetailModel.Data.MainActor.length>0)||(_DetailModel.Data.Introduction.length>0)){
|
displayInsIntroduction=YES;
|
}else{
|
displayInsIntroduction=NO;
|
}
|
dispatch_async(dispatch_get_main_queue(), ^{
|
[self.collectionView reloadData];
|
|
});
|
//判断Model是否已经加载了最上面图片
|
if(self.Model.Hpicture==nil){
|
[self.image setYthImageWithURL:self.DetailModel.Data.Hpicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
}
|
if (self.Model.Name==nil) {
|
//视频名称
|
self.detailTitle.text=self.DetailModel.Data.Name;
|
}
|
//给播放按钮添加点击事件
|
[self.playBtn addTarget:self action:@selector(loadWebView:) forControlEvents:UIControlEventTouchUpInside];
|
[self.backgroundButton addTarget:self action:@selector(loadWebView:) forControlEvents:UIControlEventTouchUpInside];
|
|
//评论与详情的切换视图
|
[self segmentView];
|
//获取视频详情信息
|
_VideoDetailList=self.DetailModel.Data.VideoDetailList;
|
//计算cell的大小
|
[self CalculateHeightWithArray:_VideoDetailList];
|
|
//加载广告
|
[self loadAd];
|
//加载相关视频
|
[self getRelativeVideosWithVideoId:movieid];
|
//加载猜你喜欢
|
[self getGuessLikeWithVideoId:movieid];
|
//加载大家都在看
|
[self getPeopleSeeVideowithVideoId:movieid];
|
//加载评论视图
|
[self reloadCommentView];
|
//加载视频源
|
[self loadResourceItem];
|
//数据加载成功
|
[SVProgressHUD dismiss];
|
}else{
|
NSLog(@"%@",error);
|
//提示用户错误
|
[SVProgressHUD dismiss];
|
|
// [SVProgressHUD showErrorWithStatus:@"加载失败!"];
|
|
}
|
}];
|
}
|
|
/**
|
* 视频源切换
|
*/
|
-(void)SourcesSwitching:(NSInteger)index{
|
[SVProgressHUD showWithStatus:@"视频源切换中"];
|
if(_isPPTVSuccess){
|
// [self PPTVclear];
|
}
|
[[YTHNetInterface startInterface] getVoideoDetailWithUid:[YTHsharedManger startManger].Uid withLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withId:self.Model.Id withThirdType:self.Model.ThirdType withSystem:@"1" WithResourceId:_NewResource withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSDictionary *dictionaryDta = (NSDictionary *)result;
|
self.DetailModel=[XYRVideoDetailModel yy_modelWithDictionary:dictionaryDta];
|
_VideoDetailList=self.DetailModel.Data.VideoDetailList;
|
//计算cell的大小
|
[self CalculateHeightWithArray:_VideoDetailList];
|
|
_gather=1;
|
|
//需要考虑到正在播放优酷视屏时,如果切换爱奇艺的情况
|
if([_NewResource intValue]!=15){
|
// [self.player.view removeFromSuperview];
|
// [self.player removeEventsObserver:_viewManager];
|
// [self.player stop];
|
// [self.player deinit];
|
|
//取消隐藏playBtn
|
[_playBtn setHidden:NO];
|
[_backgroundButton setEnabled:NO];
|
//取消隐藏返回按钮
|
[self.backBtn setHidden:NO];
|
//取消隐藏标题
|
_textView.hidden = NO;
|
//优酷加载为no;
|
self.YKloadSuccess=NO;
|
}
|
dispatch_async(dispatch_get_main_queue(), ^{
|
[_collectionView reloadData];
|
|
});
|
|
//提示视频源切换成功
|
[SVProgressHUD dismiss];
|
}else{
|
//提示用户资源切换失败,并把显示的资源显示为之前的
|
[SVProgressHUD showErrorWithStatus:@"切换失败!"];
|
}
|
}];
|
}
|
|
/**
|
* 联网检查是否收藏
|
*/
|
-(void)checkWhetherCollection{
|
// if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
|
[[YTHNetInterface startInterface] getIsCollectedWithUid:[YTHsharedManger startManger].Uid withId:self.Model.Id withThirdType:self.Model.ThirdType withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
UIButton *B1=[self.view viewWithTag:321];
|
if (isSuccessful) {
|
[B1 setSelected:YES];
|
}else{
|
[B1 setSelected:NO];
|
}
|
}];
|
// }
|
}
|
|
//用于计算选集cell的大小
|
-(void)CalculateHeightWithArray:(NSArray *)arr {
|
if (_VideoDetailList.count == 0) return;
|
|
NSString *MAXStr=_VideoDetailList[0][@"Tag"];
|
for (int i=1; i<arr.count; i++) {
|
NSString *tempStr = _VideoDetailList[i][@"Tag"];
|
if (MAXStr.length<tempStr.length) {
|
MAXStr=tempStr;
|
}
|
}
|
CGSize CellSize = [MAXStr boundingRectWithSize:CGSizeMake(KScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
|
|
float tempCellW;
|
if (CellSize.width+10<KScreenW/7) {
|
tempCellW=KScreenW/7;
|
}else{
|
tempCellW=KScreenW-70;
|
}
|
|
CELLSize=CGSizeMake(tempCellW, CellSize.height+12);
|
}
|
|
/**
|
* 加载广点通原生广告
|
*/
|
-(void)loadAd{
|
// _nativeAd = [[GDTNativeAd alloc] initWithAppkey:GDTADkey placementId:GDTYSADkey4];
|
// _nativeAd.controller = self;
|
// _nativeAd.delegate = self;
|
// [_nativeAd loadAd:4];
|
self.nativeExpressAd = [[GDTNativeExpressAd alloc] initWithPlacementId:GDTYSADkey4 adSize:CGSizeMake(KScreenW, (KScreenW-20)/16*9 + 10)];
|
|
self.nativeExpressAd.delegate = self;
|
// 配置视频播放属性
|
self.nativeExpressAd.videoAutoPlayOnWWAN = YES;
|
self.nativeExpressAd.videoMuted = NO;
|
[self.nativeExpressAd loadAd:4];
|
}
|
- (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd
|
*)nativeExpressAd views:(NSArray<__kindof
|
GDTNativeExpressAdView *> *)views
|
{
|
if(views&&views.count>=3)
|
{
|
self.expressAdViews = [NSArray arrayWithArray:views];
|
}
|
if (self.expressAdViews.count) {
|
[self.expressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
|
expressView.controller = self;
|
[expressView render];
|
}];
|
}
|
// 广告位 render 后刷新 tableView
|
[self.collectionView reloadData];
|
}
|
- (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error{
|
NSLog(@"%@",error);
|
}
|
/**
|
* 获取视频的相关视频信息
|
*
|
* @param MovieId 视频的id
|
*/
|
-(void)getRelativeVideosWithVideoId:(NSString *)MovieId{
|
[[YTHNetInterface startInterface] getRelativeVideosWithUid:[YTHsharedManger startManger].Uid withVideoId:MovieId withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
_RelativeVideos=[[(NSDictionary*)result objectForKey:@"Data"] objectForKey:@"data"];
|
//刷新瀑布流
|
// dispatch_sync(dispatch_get_main_queue(), ^{
|
// [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:3]];
|
[self.collectionView reloadData];
|
// });
|
}else{
|
|
}
|
}];
|
}
|
/**
|
* 获取视频的猜你会喜欢的视频信息
|
*
|
* @param MovieId 视频的id
|
*/
|
-(void)getGuessLikeWithVideoId:(NSString *)MovieId{
|
[[YTHNetInterface startInterface] getGuessLikeWithUid:[YTHsharedManger startManger].Uid withVideoId:MovieId withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
_GuessYoulike=[[(NSDictionary*)result objectForKey:@"Data"] objectForKey:@"data"];
|
//刷新瀑布流
|
// dispatch_sync(dispatch_get_main_queue(), ^{
|
// [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:4]];
|
[self.collectionView reloadData];
|
|
// });
|
}else{
|
|
}
|
}];
|
}
|
/**
|
* 获取大家都在看的视频信息
|
*
|
* @param MovieId 视频的id
|
*/
|
-(void)getPeopleSeeVideowithVideoId:(NSString *)MovieId{
|
[[YTHNetInterface startInterface] getPeopleSeeVideoWithUid:[YTHsharedManger startManger].Uid withVideoId:MovieId withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
_PeopleSeeVideo=[[(NSDictionary*)result objectForKey:@"Data"] objectForKey:@"data"];
|
//刷新瀑布流
|
// dispatch_sync(dispatch_get_main_queue(), ^{
|
// [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:5]];
|
[self.collectionView reloadData];
|
|
|
// });
|
}else{
|
}
|
}];
|
}
|
|
#pragma mark 点击发送评论
|
-(void)ClickSendComment{
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
|
//如果用户登录
|
if(sendButton.tag==888){
|
if(![_textField.text isEqualToString:@""]){
|
//评论视频
|
[[YTHNetInterface startInterface] getreplayCommentWithUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithVideoId:_Model.Id withThirdType:[NSString stringWithFormat:@"%ld",(long)_DetailModel.Data.ThirdType] WithContent:_textField.text WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
[_textField setText:@""];
|
[_textField resignFirstResponder];
|
[_commenttableview setContentOffset:CGPointMake(0, 0) animated:YES];
|
[self reloadCommentView];
|
|
[SVProgressHUD showSuccessWithStatus:@"评论成功"];
|
|
}else{
|
[SVProgressHUD showErrorWithStatus:@"发送失败!"];
|
}
|
}];
|
}else{
|
[SVProgressHUD showErrorWithStatus:@"评论不能为空!"];
|
}
|
}else{
|
//回复评论
|
if(![_textField.text isEqualToString:@""]){
|
[[YTHNetInterface startInterface] getreplayCommentWithUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithcommentReplayId:nil WithCommentId:[_commentDataArr[[_clickedStr intValue]] objectForKey:@"Id"] WithContent:_textField.text WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
[_textField setText:@""];
|
_textField.placeholder=@"我也来说两句...";
|
sendButton.tag=888;
|
[_textField resignFirstResponder];
|
[self reloadCommentView];
|
[_commenttableview setContentOffset:CGPointMake(0, 0) animated:YES];
|
}else{
|
[SVProgressHUD showErrorWithStatus:@"回复失败!"];
|
}
|
}];
|
}else{
|
//提示用户输入
|
[SVProgressHUD showErrorWithStatus:@"评论不能为空!"];
|
}
|
}
|
}else{
|
//如果用户未登录
|
LoggingViewController *loginVC=[[LoggingViewController alloc] init];
|
loginVC.modalPresentationStyle = 0;
|
loginVC.ispresent=YES;
|
[self presentViewController:loginVC animated:YES completion:nil];
|
}
|
}
|
|
#pragma mark 刷新评论视图
|
-(void)reloadCommentView{
|
//首先重新从服务器获取数据
|
[[YTHNetInterface startInterface] getVideoCommentListWithUid:[YTHsharedManger startManger].Uid WithVideoId:_Model.Id WithThirdType:_Model.ThirdType WithPage:[NSString stringWithFormat:@"%d",commentPage] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSDictionary *commentDic=(NSDictionary *)result;
|
if(commentPage==1){
|
//更新数据
|
_commentDataDic=[commentDic objectForKey:@"Data"];
|
_commentDataArr=[_commentDataDic objectForKey:@"data"];
|
if([[_commentDataDic objectForKey:@"count"] intValue]<9){
|
|
}else{
|
//只有数据大于9条时才出现下拉刷新,不然没有出现的意义
|
_commenttableview.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
|
++commentPage;
|
[self reloadCommentView];
|
}];
|
}
|
}else{
|
_commentDataDic=[commentDic objectForKey:@"Data"];
|
NSArray *tempArr=[_commentDataDic objectForKey:@"data"];
|
|
for (int a=0; a<tempArr.count; a++) {
|
[_commentDataArr addObject:[tempArr objectAtIndex:a]];
|
}
|
commentPage=commentPage+(tempArr.count)%30;
|
}
|
//刷新评论
|
dispatch_async(dispatch_get_main_queue(), ^{
|
[_commenttableview reloadData];
|
});
|
//刷新评论按钮上的评论数
|
// NSString *commentNub=[NSString stringWithFormat:@"评 论(%ld)",(long)_DetailModel.Data.CommentCount];
|
self.segmentedControl.sectionTitles = @[@"详 情"];
|
[_commenttableview.mj_header endRefreshing];
|
[_commenttableview.mj_footer endRefreshing];
|
}else{
|
[_commenttableview.mj_header endRefreshing];
|
[_commenttableview.mj_footer endRefreshing];
|
}
|
}];
|
}
|
#pragma mark 回复评论
|
-(void)replyMessage:(NSNotification *)notification{
|
//被点击的评论的位置
|
_clickedStr=notification.userInfo[@"replyMessage"];
|
//用户点击的是回复还是举报
|
NSString *type=notification.userInfo[@"replyType"];
|
|
if([type isEqualToString:@"回复"]){
|
[_textField becomeFirstResponder];
|
//评论者的网名
|
NSString *replyName=[[_commentDataArr[[_clickedStr intValue]] objectForKey:@"User"] objectForKey:@"Nickname"];
|
_textField.placeholder=[NSString stringWithFormat:@"回复 :%@",replyName];
|
sendButton.tag=889;
|
}
|
if ([type isEqualToString:@"举报"]) {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
|
[LGLAlertView showAlertViewWith:self title:@"举报" message:@"请选择举报理由" CallBackBlock:^(NSInteger btnIndex) {
|
NSLog(@"%ld————%ld", (long)btnIndex,(long)[_clickedStr intValue]);
|
if(btnIndex!=0){
|
[SVProgressHUD showSuccessWithStatus:@"感谢您的反馈!"];
|
}
|
} cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"营销诈骗", @"淫秽色情", @"地域攻击",@"其他理由",nil];
|
}else{
|
//如果用户未登录
|
LoggingViewController *loginVC=[[LoggingViewController alloc] init];
|
loginVC.modalPresentationStyle = 0;
|
loginVC.ispresent=YES;
|
[self presentViewController:loginVC animated:YES completion:nil];
|
}
|
}
|
}
|
|
/*************(以下)协议***************/
|
#pragma mark -CMuneBarDelegate
|
-(void)muneBarselected:(NSInteger)index{
|
NSLog(@"%@_____%@",self.NewResource,[_ResourceList[index] objectForKey:@"Id"]);
|
if(self.NewResource!=[_ResourceList[index] objectForKey:@"Id"]){
|
self.NewResource=[_ResourceList[index] objectForKey:@"Id"];
|
[self.MuneBar.mainButton setImage:[UIImage imageNamed:[_ResourceList[index] objectForKey:@"Name"]] forState:UIControlStateNormal];
|
//仅仅更新选集列表
|
[self SourcesSwitching:index];
|
}
|
[self.MuneBar hideItems];
|
}
|
|
#pragma mark - UIScrollViewDelegate
|
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
NSLog(@"%f",scrollView.contentOffset.x);
|
if (scrollView==self.scrollView) {
|
// NSInteger page = scrollView.contentOffset.x / KScreenW;
|
|
// [self.scrollView scrollRectToVisible:CGRectMake(KScreenW * page, KScreenW/48*27+35, KScreenW, KScreenH-(KScreenW/48*27)-35) animated:YES];
|
// [self.segmentedControl setSelectedSegmentIndex:page animated:YES];
|
//考虑到用户在输入的时候突然切换到详情,这个时候就需要取消评论框的第一响应
|
// if(page==0){
|
// [_textField resignFirstResponder];
|
// }
|
}
|
}
|
|
#pragma mark -UICollectionViewDelegate
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
if (indexPath.section==2) {
|
return NO;
|
}
|
return YES;
|
}
|
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
|
return YES;
|
}
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
if (indexPath.section==0) {//点击了广告
|
// GDTNativeAdData * info=nativeArray[3];
|
// [_nativeAd clickAd:info];
|
}else if (indexPath.section==1) {
|
//查找刷新视图
|
NSMutableArray * indexPatharr = [[NSMutableArray alloc]init];
|
[indexPatharr addObject:indexPath];
|
NSIndexPath * lastIndex;
|
if(_playBtn.hidden){
|
if(indexPath.row == isCollectNum -1){
|
return ;
|
}
|
|
NSArray *arr = [_collectionView indexPathsForVisibleItems];
|
|
for( int i = 0 ; i < arr.count ; ++i){
|
NSIndexPath * temp = arr[i];
|
if(isCollectNum -1 == temp.row){
|
lastIndex = temp;
|
break;
|
}
|
}
|
if(lastIndex){
|
[indexPatharr addObject:lastIndex];
|
}
|
}
|
isCollectNum=(int)indexPath.row +1;
|
if(lastIndex.row == 0 || indexPath.row == 0 || !lastIndex){ //在iphone6以上刷新row==0时无效的特殊处理
|
[_collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
|
// [self.collectionView reloadData];
|
|
}else{
|
[_collectionView reloadItemsAtIndexPaths:indexPatharr];
|
// [_collectionView reloadData];
|
|
}
|
|
//刷新播放器
|
if([self.NewResource intValue]==15){ //使用优酷播放器
|
[self YKPlay:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
|
}else if([self.NewResource intValue]==16){ //PPTV播放器
|
[self PPTVplay:[NSString stringWithFormat:@"%d",isCollectNum-1] WithBoolInit:_isPPTVSuccess];
|
}else if([self.NewResource intValue]==18){ //乐视播放器
|
[self YKPlay:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
|
}else{
|
[self startToPlay:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
|
}
|
|
}else{
|
if(_isPPTVSuccess){ //清空pptv进行转换
|
// [self PPTVclear];
|
_isPPTVSuccess = NO;
|
}
|
|
//考虑到正在播放优酷视频,切换到爱奇艺资源,所以要做一次移除优酷播放器的操作
|
// [self.player.view removeFromSuperview];
|
// [self.player removeEventsObserver:_viewManager];
|
// [self.player stop];
|
// [self.player deinit];
|
//取消隐藏playBtn
|
[_playBtn setHidden:NO];
|
[_backgroundButton setEnabled:NO];
|
//取消隐藏标题
|
_textView.hidden = NO;
|
|
if (indexPath.section==3) {
|
_Model=[XYRVideoInfoModel yy_modelWithDictionary:_RelativeVideos[indexPath.row]];
|
}else if(indexPath.section==4){
|
_Model=[XYRVideoInfoModel yy_modelWithDictionary:_GuessYoulike[indexPath.row]];
|
}else if(indexPath.section==5){
|
_Model=[XYRVideoInfoModel yy_modelWithDictionary:_PeopleSeeVideo[indexPath.row]];
|
}
|
//刷新视图
|
[self flashAllView];
|
}
|
}
|
|
#pragma mark -UICollectionViewDataSource
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
if (section==0) {
|
if(self.expressAdViews.count>3){
|
return 1;
|
}else{
|
return 0;
|
}
|
}else if(section==1){
|
if(_VideoDetailList!=nil){
|
if (self.DetailModel.Data.ShowType==1) {//是综艺
|
if (_VideoDetailList.count>6*_gather) {
|
return 6*_gather;
|
}else{
|
return _VideoDetailList.count;
|
}
|
}else{//不是综艺
|
if (_VideoDetailList.count>10*_gather) {
|
return 10*_gather;
|
}else{
|
return _VideoDetailList.count;
|
}
|
}
|
}else{
|
return 0;
|
}
|
}else if(section==2){
|
return 1;
|
}else if(section==3){
|
if (_RelativeVideos.count>0) {
|
return _RelativeVideos.count;
|
}else{
|
return 0;
|
}
|
}else if(section==4){
|
if (_GuessYoulike.count>0) {
|
return _GuessYoulike.count;
|
}else{
|
return 0;
|
}
|
}else if(section==5){
|
if (_PeopleSeeVideo.count>0) {
|
return _PeopleSeeVideo.count;
|
}else{
|
return 0;
|
}
|
}else{
|
return 0;
|
}
|
}
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
return 6;
|
}
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
XYRVideoInfoModel *VideosDataModel;
|
switch (indexPath.section) {
|
case 0:{
|
newADCollectionViewCell *cell;
|
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newADCollectionViewCell" forIndexPath:indexPath];
|
if (self.expressAdViews.count <= 3) {
|
return cell;
|
}
|
GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[3];
|
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
[cell.contentView addSubview:adView];
|
// GDTNativeAdData *info=nativeArray[3];
|
// cell.ADtitle.text=[info.properties objectForKey:GDTNativeAdDataKeyTitle];
|
// cell.ADtitle.backgroundColor=[UIColor clearColor];
|
// [cell.ADimage setYthImageWithURL:[info.properties objectForKey:GDTNativeAdDataKeyImgUrl] placeholderImage:nil];
|
// [_nativeAd attachAd:info toView:cell];
|
return cell;
|
}
|
break;
|
case 1:{
|
GroupCollectionViewCell *cell;
|
if (_VideoDetailList.count <= indexPath.row) {
|
return cell;
|
}
|
cell.tag=indexPath.row+2000;
|
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GroupCellID" forIndexPath:indexPath];
|
cell.selectCollect.titleLabel.lineBreakMode=NSLineBreakByTruncatingTail;
|
[cell.selectCollect setTitle:[_VideoDetailList[indexPath.row] objectForKey:@"Tag"] forState:UIControlStateNormal];
|
cell.selectCollect.titleLabel.numberOfLines=0;
|
//设置集数的字体颜色
|
[cell.selectCollect setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
[cell.selectCollect setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
|
//对cell的背景图片进行处理,让其从中间拉伸,反正图片变形
|
UIImage *deselectImage=[UIImage imageNamed:@"集数框-未选择"];
|
deselectImage=[deselectImage stretchableImageWithLeftCapWidth:floorf(deselectImage.size.width/2) topCapHeight:floorf(deselectImage.size.height/2)];
|
UIImage *selectImage=[UIImage imageNamed:@"集数框-选择"];
|
selectImage=[selectImage stretchableImageWithLeftCapWidth:floorf(selectImage.size.width/2) topCapHeight:floorf(selectImage.size.height/2)];
|
//设置cell选中和未选中的背景图片
|
[cell.selectCollect setBackgroundImage:deselectImage forState:UIControlStateNormal];
|
[cell.selectCollect setBackgroundImage:selectImage forState: UIControlStateSelected];
|
//关闭button的交互,否则collectionView的交互无法使用
|
cell.selectCollect.userInteractionEnabled=NO;
|
//默认设置第一集为选中状态
|
if(indexPath.row==isCollectNum-1){
|
[cell.selectCollect setSelected:YES];
|
}else{
|
[cell.selectCollect setSelected:NO];
|
}
|
return cell;
|
}
|
break;
|
case 2:{
|
IntroductionCollectionViewCell *cell;
|
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"IntroductionCollectionViewCell" forIndexPath:indexPath];
|
cell.backgroundColor = kGlobalBackgroundColor;
|
cell.area.text=[NSString stringWithFormat:@"%@",_DetailModel.Data.Area.length?_DetailModel.Data.Area:@"内地"];
|
cell.year.text=[NSString stringWithFormat:@"%@",_DetailModel.Data.Year!=nil?_DetailModel.Data.Year:@"2016"];
|
cell.type.text=[NSString stringWithFormat:@"%@",_DetailModel.Data.VideoType.Name!=nil?_DetailModel.Data.VideoType.Name:@" "];
|
NSString *actString=[NSString stringWithUTF8String:[_DetailModel.Data.MainActor?_DetailModel.Data.MainActor :@" " UTF8String]];
|
cell.act.text=[NSString stringWithFormat:@"%@",actString.length?actString:@" "];
|
NSString *mainContentString=[NSString stringWithUTF8String:[self.DetailModel.Data.Introduction?self.DetailModel.Data.Introduction:@"" UTF8String]];
|
cell.mainContent.text=[NSString stringWithFormat:@"%@",mainContentString.length?mainContentString:@" "];
|
return cell;
|
}
|
break;
|
default:{
|
|
GuessYouLikeCollectionViewCell *cell;
|
if (indexPath.section==3) {
|
//相关视频
|
if (indexPath.row >= _RelativeVideos.count) {
|
return cell;
|
}
|
VideosDataModel=[XYRVideoInfoModel yy_modelWithDictionary:_RelativeVideos[indexPath.row]];
|
}else if (indexPath.section==4){
|
if (indexPath.row >= _GuessYoulike.count) {
|
return cell;
|
}
|
//猜你喜欢
|
VideosDataModel=[XYRVideoInfoModel yy_modelWithDictionary:_GuessYoulike[indexPath.row]];
|
}else{
|
if (indexPath.row >= _PeopleSeeVideo.count) {
|
return cell;
|
}
|
//大家都在看
|
VideosDataModel=[XYRVideoInfoModel yy_modelWithDictionary:_PeopleSeeVideo[indexPath.row]];
|
}
|
cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"GuessYouLikeCollectionViewCell" forIndexPath:indexPath];
|
cell.backgroundColor=[UIColor whiteColor];
|
cell.MovieImage.clipsToBounds=YES;
|
cell.MovieImage.contentMode=UIViewContentModeScaleAspectFill;
|
[cell.MovieImage setYthImageWithURL:VideosDataModel.Hpicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
cell.name.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
|
cell.name.text=[NSString stringWithFormat:@"%@",VideosDataModel.Tag];
|
cell.Score.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
|
cell.Score.text=[NSString stringWithFormat:@"%@",VideosDataModel.Score];
|
cell.Title.text=[NSString stringWithFormat:@"%@",VideosDataModel.Name];
|
cell.commentVV.text=[NSString stringWithFormat:@"%@",VideosDataModel.WatchCount];
|
cell.CommentNub.text=[NSString stringWithFormat:@"%ld",(long)VideosDataModel.CommentCount];
|
|
cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
|
return cell;
|
}
|
break;
|
}
|
}
|
|
//定制collectionView的head和foot
|
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
|
switch (indexPath.section) {
|
case 0:{
|
if (kind == UICollectionElementKindSectionHeader) {
|
|
titleCollectionReusableView *titleCollectionReusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleCollectionReusableViewID" forIndexPath:indexPath];
|
|
//添加收藏的点击事件
|
[titleCollectionReusableView.collectionBtn addTarget:self action:@selector(ClickCollection:) forControlEvents:UIControlEventTouchUpInside];
|
_collectionbt = titleCollectionReusableView.collectionBtn;
|
//添加分享的点击事件
|
titleCollectionReusableView.shareBtn.hidden = YES;
|
titleCollectionReusableView.share.hidden = YES;
|
[titleCollectionReusableView.shareBtn addTarget:self action:@selector(clickShareButton:) forControlEvents:UIControlEventTouchUpInside];
|
//联网检查是否收藏
|
[self checkWhetherCollection];
|
//加载视频源视图
|
if (_MuneBar!=nil) {
|
[titleCollectionReusableView.resourceSelectionView addSubview:self.MuneBar];
|
}
|
|
return titleCollectionReusableView;
|
}else if(kind == UICollectionElementKindSectionFooter){
|
if(_DetailModel.Extra1.Attention.Name!=nil){
|
AttentionCollectionReusableView *attentionCollectionReusableView=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"AttentionCollectionReusableViewID" forIndexPath:indexPath];
|
|
Attention *attentionModel=_DetailModel.Extra1.Attention;
|
[attentionCollectionReusableView.AttentionImage setYthImageWithURL:attentionModel.Picture placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
|
attentionCollectionReusableView.AttentionName.text=attentionModel.Name;
|
attentionCollectionReusableView.AttentionData.text=[NSString stringWithFormat:@"%@",attentionModel.UpdateInfo];
|
[attentionCollectionReusableView.AttentionButton setSelected:attentionModel.IsAttention];
|
[attentionCollectionReusableView.AttentionButton addTarget:self action:@selector(ClickAttentionButton:) forControlEvents:UIControlEventTouchUpInside];
|
|
return attentionCollectionReusableView;
|
}else{
|
return nil;
|
}
|
}
|
}
|
break;
|
case 1:{
|
if(kind == UICollectionElementKindSectionFooter){
|
GroupfootSection *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"GroupfootSectionID" forIndexPath:indexPath];
|
groupfootSection.backgroundColor=kGlobalBackgroundColor;
|
[groupfootSection.getMore setTag:521];
|
if(self.DetailModel.Data.ShowType==1){
|
//是综艺
|
[groupfootSection.getMore setTitle:_VideoDetailList.count>6*_gather?@"查看更多":@"全部加载完成" forState:UIControlStateNormal];
|
if(_VideoDetailList.count>6){
|
[groupfootSection.getMore addTarget:self action:@selector(getMoreInformation:) forControlEvents:UIControlEventTouchUpInside];
|
}
|
}else{
|
//不是综艺
|
[groupfootSection.getMore setTitle:_VideoDetailList.count>10*_gather?@"查看更多":@"全部加载完成" forState:UIControlStateNormal];
|
if(_VideoDetailList.count>10){
|
[groupfootSection.getMore addTarget:self action:@selector(getMoreInformation:) forControlEvents:UIControlEventTouchUpInside];
|
}
|
}
|
return groupfootSection;
|
}else{
|
return nil;
|
}
|
}
|
break;
|
case 2:
|
if (kind == UICollectionElementKindSectionHeader){
|
GroupSection *groupSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"GroupSectionID" forIndexPath:indexPath];
|
groupSection.sectionTitle.text =@"简介";
|
groupSection.backgroundColor=kGlobalBackgroundColor;
|
groupSection.scoreTitle.text=[NSString stringWithFormat:@"评分:%@",self.DetailModel.Data.Score!=nil?self.DetailModel.Data.Score:@"无"];
|
//暂时隐藏掉评分
|
[groupSection.scoreTitle setHidden:YES];
|
return groupSection;
|
}else if(kind == UICollectionElementKindSectionFooter){
|
GroupfootSection *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"GroupfootSectionID" forIndexPath:indexPath];
|
groupfootSection.backgroundColor=[UIColor whiteColor];
|
[groupfootSection.getMore setTag:522];
|
[groupfootSection.getMore setTitle:@"" forState:UIControlStateNormal];
|
[groupfootSection.getMore addTarget:self action:@selector(getMoreInformation:) forControlEvents:UIControlEventTouchUpInside];
|
return groupfootSection;
|
}
|
break;
|
default:{
|
NSArray *headStr=@[@"相关视频",@"猜你喜欢",@"大家都爱看"];
|
if (kind == UICollectionElementKindSectionHeader){
|
GroupSmallSection *groupSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"GroupSmallSection" forIndexPath:indexPath];
|
groupSection.title.text=headStr[indexPath.section-3];
|
return groupSection;
|
}else if(kind == UICollectionElementKindSectionFooter){
|
//返回广告视图
|
if (indexPath.section>3) {
|
|
|
if(self.expressAdViews.count>0){
|
ADCollectionReusableView *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView" forIndexPath:indexPath];
|
|
//把button设为透明
|
groupfootSection.ADClickButton.backgroundColor=[UIColor clearColor];
|
[groupfootSection.ADClickButton setTag:520+indexPath.section];
|
[groupfootSection.ADClickButton addTarget:self action:@selector(getMoreInformation:) forControlEvents:UIControlEventTouchUpInside];
|
GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[indexPath.section-3];
|
[groupfootSection addSubview:adView];
|
return groupfootSection;
|
}else{
|
return nil;
|
}
|
}else{
|
return nil;
|
}
|
}
|
}
|
break;
|
}
|
return nil;
|
}
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
|
//宽度随便定,系统会自动取collectionView的宽度
|
//高度为分组头的高度
|
if(section==0){
|
return CGSizeMake(0, 90);
|
}else if(section==1){
|
return CGSizeMake(0, 0);
|
}else if(section==2){
|
if(displayInsIntroduction){
|
return CGSizeMake(0, 50);
|
}else{
|
return CGSizeMake(0, 0);
|
}
|
}else{
|
return CGSizeMake(0, 40);
|
}
|
}
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
|
if (section==0) {
|
//这里需要做个判断
|
if(_DetailModel.Extra1.Attention.Name!=nil){
|
return CGSizeMake(0, 75);
|
}else{
|
return CGSizeMake(0, 0);
|
}
|
}else if(section==1){
|
return CGSizeMake(0, 42);
|
}else if(section==2){
|
return CGSizeMake(0, 0);
|
}else{
|
if (section>3) {
|
if(self.expressAdViews.count>0){
|
GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[section-3];
|
return CGSizeMake(0, adView.bounds.size.height);
|
}else{
|
return CGSizeMake(0, 0);
|
}
|
}else{
|
return CGSizeMake(0, 0);
|
}
|
}
|
}
|
|
|
#pragma mark -UICollectionViewDelegateFlowLayout
|
//协议中的方法,用于返回单元格的大小
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
if (indexPath.section==0) {
|
// return CGSizeMake(KScreenW-20, (KScreenW-20)/16*9);
|
GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[indexPath.section];
|
return CGSizeMake(KScreenW, adView.bounds.size.height);
|
}else if (indexPath.section==1) {
|
return CELLSize;
|
}else if(indexPath.section==2){
|
if (displayInsIntroduction) {
|
NSString *mainContentString=[NSString stringWithUTF8String:[self.DetailModel.Data.Introduction?self.DetailModel.Data.Introduction:@" " UTF8String]];
|
NSString *IntroductionStr=[NSString stringWithFormat:@"%@",mainContentString.length?mainContentString:@" !"];
|
CGSize IntroSize = [IntroductionStr boundingRectWithSize:CGSizeMake(KScreenW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size;
|
CGSize titleSize=CGSizeMake(KScreenW, IntroSize.height+115);
|
return titleSize;
|
}else{
|
return CGSizeMake(0, 0);
|
}
|
|
}else{
|
return CGSizeMake((KScreenW-30)/2, (KScreenW-30)*9/32+65);
|
}
|
}
|
|
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
|
if(section==0){//上、左、下、右的边距
|
return UIEdgeInsetsMake(0, 10, 0, 10);
|
}else if(section==1){
|
return UIEdgeInsetsMake(5, 10, 10, 10);
|
}else{
|
return UIEdgeInsetsMake(0, 10, 10, 10);
|
}
|
}
|
|
#pragma mark -UITableViewDelegate
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
NSArray *replylist=[_commentDataArr[indexPath.section] objectForKey:@"ReplyList"];
|
//回复者的网名
|
NSString *replyName=[[replylist[indexPath.row] objectForKey:@"User"] objectForKey:@"Nickname"];
|
//回复者回复内容
|
NSString *replyContent=[replylist[indexPath.row] objectForKey:@"Content"];
|
//合成网名和内容
|
NSString *reply=[NSString stringWithFormat:@"%@ 回复:%@",replyName,replyContent];
|
|
CGSize replySize = [reply boundingRectWithSize:CGSizeMake(KScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
|
|
return replySize.height+30;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
NSDictionary *dic=_commentDataArr[section];
|
NSString *commentStr=[dic objectForKey:@"Content"];
|
|
CGSize commentSize = [commentStr boundingRectWithSize:CGSizeMake(KScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
|
|
return commentSize.height+60;
|
}
|
|
//取消高亮
|
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
|
return NO;
|
}
|
|
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
commentHeaderView *commentHeaderCell=[commentHeaderView headerViewWithTableView:tableView];
|
//该评论用户的信息
|
NSDictionary *dic=_commentDataArr[section];
|
NSDictionary *userInfo=[dic objectForKey:@"User"];
|
NSString *iconUrl;
|
if (![[userInfo objectForKey:@"Portrait"] isEqualToString:@""]&&[userInfo objectForKey:@"Portrait"]!=nil) {
|
if ([[[userInfo objectForKey:@"Portrait"] substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {
|
iconUrl=[userInfo objectForKey:@"Portrait"];
|
}else{
|
iconUrl=[NSString stringWithFormat:@"%@%@",iconImageUrl,[userInfo objectForKey:@"Portrait"]];
|
}
|
[commentHeaderCell.headerImageView setYthImageWithURL:iconUrl placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
|
}else{
|
[commentHeaderCell.headerImageView setImage:[UIImage imageNamed:@"关注默认头像"]];
|
}
|
commentHeaderCell.userNameLabel.text=[NSString stringWithFormat:@"%@",[userInfo objectForKey:@"Nickname"]];
|
//评论内容的高度和宽度
|
CGSize commentSize = [[dic objectForKey:@"Content"] boundingRectWithSize:CGSizeMake(KScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
|
//设置评论内容的高度
|
commentHeaderCell.commentContentLabel.frame=CGRectMake(50, 55, KScreenW-70, commentSize.height);
|
//设置评论的内容
|
commentHeaderCell.commentContentLabel.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"Content"]];
|
//设置评论日期的内容
|
commentHeaderCell.commentTimeLabel.text=[[YTHNetInterface startInterface] getDate:[dic objectForKey:@"Createtime"]];
|
//设置评论Button的位置
|
commentHeaderCell.replyButton.frame=CGRectMake(KScreenW-60, 20, 45, 20);
|
//传递cell的位置
|
commentHeaderCell.section=[NSString stringWithFormat:@"%d",(int)section];
|
//隐藏第一个section的分割线
|
if (section==0) {
|
[commentHeaderCell.Splitline setHidden:YES];
|
}else{
|
[commentHeaderCell.Splitline setHidden:NO];
|
}
|
return commentHeaderCell;
|
}
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
[tableView deselectRowAtIndexPath:indexPath animated:NO];
|
[_textView resignFirstResponder];
|
}
|
|
#pragma mark -UITableViewDataSource
|
//回复的数量
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
//获取该视频的评论
|
NSArray *replylist=[_commentDataArr[section] objectForKey:@"ReplyList"];
|
return replylist.count;
|
}
|
|
//评论的数量
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
return [_commentDataArr count];
|
}
|
|
//回复的cell
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
CommentTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"CommentCellId"];
|
NSArray *replylist=[_commentDataArr[indexPath.section] objectForKey:@"ReplyList"];
|
//回复者的网名
|
NSString *replyName=[[replylist[indexPath.row] objectForKey:@"User"] objectForKey:@"Nickname"];
|
//回复者回复内容
|
NSString *replyContent=[replylist[indexPath.row] objectForKey:@"Content"];
|
//合成网名和内容
|
NSString *reply=[NSString stringWithFormat:@"%@ 回复:%@",replyName,replyContent];
|
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:reply];
|
[str addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0,replyName.length)];
|
cell.replyView.attributedText=str;
|
//回复评论者的时间
|
cell.replyTime.text=[[YTHNetInterface startInterface] getDate:[replylist[indexPath.row] objectForKey:@"Createtime"]];
|
return cell;
|
}
|
|
#pragma mark -UITextFieldDelegate
|
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
|
[_scrollView setScrollEnabled:NO];
|
return YES;
|
}
|
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
|
[self.view endEditing:YES];
|
return YES;
|
}
|
- (void)textFieldDidEndEditing:(UITextField *)textField{
|
[_scrollView setScrollEnabled:YES];
|
sendButton.tag=888;
|
_textField.placeholder=@"我也来说两句...";
|
}
|
|
#pragma mark 键盘隐藏
|
-(void)keyboardWillHide:(NSNotification *)notification{
|
if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
|
_replyMessageView.frame=CGRectMake(KScreenW, _scrollView.frame.size.height-50, KScreenW, 50);
|
|
}else{
|
_replyMessageView.frame=CGRectMake(0, KScreenH-50, KScreenW, 50);
|
|
}
|
}
|
#pragma mark 键盘出现
|
-(void)keyboardWasShown:(NSNotification *)notification{
|
NSDictionary* info = [notification userInfo];
|
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//得到键盘的高度
|
if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
|
_replyMessageView.frame=CGRectMake(KScreenW, _scrollView.frame.size.height-50-kbSize.height, KScreenW, 50);
|
|
}else{
|
_replyMessageView.frame=CGRectMake(0, KScreenH-50-kbSize.height, KScreenW, 50);
|
[self.view bringSubviewToFront:_replyMessageView];
|
}
|
}
|
|
#pragma mark -YTHNetDelegateRecommend
|
/**
|
* 0 . 不可用 1. 移动网络 2.wifi 3.当前网络未知
|
*/
|
- (void)updateNet:(NSInteger )status{
|
|
switch (status) {
|
|
case 0:{//当前网络不可用
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示"message:@"当前网络不可用,是否连接网络?"preferredStyle:UIAlertControllerStyleAlert];
|
//取消
|
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
[alert dismissViewControllerAnimated:YES completion:^{
|
[self backToRootView];
|
}];
|
}]];
|
//去连接网络
|
[alert addAction:[UIAlertAction actionWithTitle:@"连接网络" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
if (IOS_VERSION < 8.0) {
|
|
}else{
|
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
|
}
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
[self presentViewController:alert animated:YES completion:^{
|
|
}];
|
}
|
break;
|
case 1:{//移动网络
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示"message:@"您目前没有连接WIFi,是否使用流量继续观看"preferredStyle:UIAlertControllerStyleAlert];
|
//继续观看
|
[alert addAction:[UIAlertAction actionWithTitle:@"继续" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
//去连接网络
|
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
}]];
|
[self presentViewController:alert animated:YES completion:^{
|
|
}];
|
}
|
break;
|
case 2://WIFI
|
|
break;
|
case 3:{//当前网络无法检测,需要用户自行判断网络
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示"message:@"无法监测当前网络,请自行判断网络!"preferredStyle:UIAlertControllerStyleAlert];
|
//继续观看
|
[alert addAction:[UIAlertAction actionWithTitle:@"继续观看" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
//取消观看
|
[alert addAction:[UIAlertAction actionWithTitle:@"不看了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
[self backToRootView];
|
[alert dismissViewControllerAnimated:YES completion:^{
|
|
}];
|
}]];
|
[self presentViewController:alert animated:YES completion:^{
|
|
}];
|
}
|
break;
|
}
|
}
|
|
#pragma mark -YTHBacktoApplicationsDelegate
|
|
//- (void)OutApplication{
|
// if (self.cloudPlayer) {
|
// [self.cloudPlayer pause];
|
// }
|
//}
|
//
|
//- (void)backApplication{
|
// if (self.cloudPlayer) {
|
// [self.cloudPlayer play];
|
// }
|
//}
|
|
- (UIViewController *)viewControllerForPresentingModalView{
|
return self;
|
}
|
|
#pragma mark -GDTNativeAdDelegate
|
/**
|
* 原生广告加载广告数据成功回调,返回为GDTNativeAdData对象的数组
|
*/
|
//-(void)nativeAdSuccessToLoad:(NSArray *)nativeAdDataArray{
|
// if (!nativeArray) {
|
// nativeArray =[[NSMutableArray alloc]initWithArray:nativeAdDataArray];
|
// }else{
|
// [nativeArray addObjectsFromArray:nativeAdDataArray];
|
// }
|
// dispatch_async(dispatch_get_main_queue(), ^{
|
// [self.collectionView reloadData];
|
// });
|
//}
|
|
/**
|
* 原生广告加载广告数据失败回调
|
*/
|
-(void)nativeAdFailToLoad:(NSError *)error{
|
NSLog(@"XYR_%@",error);
|
}
|
|
#pragma mark -HXEasyCustomShareViewDelegate
|
//- (void)easyCustomShareViewButtonAction:(HXEasyCustomShareView *)shareView title:(NSString *)title {
|
// if ([title isEqualToString:@"微信"]) {
|
// [self shareWebPageToPlatformType:UMSocialPlatformType_WechatSession];
|
// }else if ([title isEqualToString:@"朋友圈"]) {
|
// [self shareWebPageToPlatformType:UMSocialPlatformType_WechatTimeLine];
|
// }else if ([title isEqualToString:@"QQ"]) {
|
// [self shareWebPageToPlatformType:UMSocialPlatformType_QQ];
|
// }else if ([title isEqualToString:@"新浪微博"]) {
|
// [self shareWebPageToPlatformType:UMSocialPlatformType_Sina];
|
// }else if ([title isEqualToString:@"QQ空间"]) {
|
// [self shareWebPageToPlatformType:UMSocialPlatformType_Qzone];
|
// }else{
|
// //到这里就错了
|
// }
|
// [shareView tappedCancel];
|
//}
|
|
/**
|
分享
|
*/
|
//- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType{
|
// NSURL *imageurl;
|
// //判断分享的图片地址是否存在
|
// NSString *picUrl=_DetailModel.Data.Picture;
|
// if (picUrl .length>4) {
|
// //判断图片地址是否为http开头,是则为第三方图片
|
// if ([[picUrl substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {
|
// imageurl = [NSURL URLWithString:picUrl];
|
// }else{
|
// //否者为公司的图片,需要添加地址
|
// imageurl =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ImageUrl,picUrl]];
|
// }
|
// }
|
//
|
// //创建分享消息对象
|
// UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
|
//
|
// //创建网页内容对象
|
// UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"布丸影视大全" descr:[NSString stringWithFormat:@"我在布丸影视大全看了《%@》影片,非常不错,大家一起看看吧!%@",_DetailModel.Data.Name,[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareUrl"]] thumImage:[NSData dataWithContentsOfURL:imageurl]];
|
//
|
// //设置网页地址
|
// shareObject.webpageUrl =[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareUrl"];
|
//
|
// //分享消息对象设置分享内容对象
|
// messageObject.shareObject = shareObject;
|
//
|
// //调用分享接口
|
// [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
|
// if (error) {
|
// [SVProgressHUD showErrorWithStatus:@"分享失败!"];
|
// NSLog(@"************Share fail with error %@*********",error);
|
// }else{
|
// NSLog(@"response data is %@",data);
|
// }
|
// }];
|
//}
|
|
|
|
- (void)dealloc {
|
|
|
}
|
|
@end
|