|
//
// detailContentController.m
// ThePaperHD
//
// Created by scar1900 on 15/1/14.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "detailContentController.h"
#import "detailContentHomeController.h"
#import "titleAndAuthorCell.h"
#import "authorAndTimeCell.h"
#import "strongRelateCountsCell.h"
#import "videoCell.h"
#import "cntentImageCell.h"
#import "contentTextCell.h"
#import "sinaAndWeChatCell.h"
#import "nodeInfoViewCell.h"
#import "detailContentMoreInfoCell.h"
#import "bannerCell.h"
#import "askContentCell.h"
#import "answerContentCell.h"
#import "hotAskListHomeController.h"
#import "columnListController.h"
#import "topicHomeController.h"
#import "loginPopUpController.h"
#import "customFlowLayout.h"
#import "TPImageScannerController.h"
#import "ImageContentController.h"
#import "TPcontentWebController.h"
#import "TPLiveHomeController.h"
#import "otherPersonHomepageController.h"
#import "reTopicCell.h"
#import "topicContentController.h"
#import "detailPageViewModel.h"
@interface detailContentController ()<videoCellDelegate,nodeInfoCellDelegate,ALMoviePlayerControllerDelegate,nodeInfoCellDelegate,detailContentMoreInfoDelegate,
hotAskListHomeDelegate,contentImageDelegate,answerContentCellDelegate,askContentCellDelgate,imageScanerDelegate,bannerCellDelgate,detailPageViewModelDelegate> {
CGRect videoRect;
BOOL isLoadAdSuccess;
}
@property(nonatomic, strong)NSMutableArray *contentDataList;
@property(nonatomic, strong)NSMutableArray *heightOfCellInEachSection; //cell高度数组
@property(nonatomic, strong)videoObjectBO *videoBO;
@property(nonatomic, strong)detailContentMoreInfoCell *relateCell;
@property(nonatomic, strong)bannerCell *bannerCell;
@property(nonatomic, strong)hotAskListHomeController *hotAskVC;
@property(nonatomic, strong)detailPageViewModel *detailModel;
@property(nonatomic, strong)UIView *fontShowView;
@property(nonatomic, strong)UILabel *fontShowT;
@property(nonatomic, strong)UILabel *fontShowFont;
@end
@implementation detailContentController
@synthesize detailContentBO = _detailContentBO;
@synthesize contentBO = _contentBO;
@synthesize contentDataList,heightOfCellInEachSection;
@synthesize videoBO;
@synthesize moviePlayerController;
@synthesize detailDelegate;
@synthesize isVideoPlaying;
@synthesize relateCell;
@synthesize bannerCell;
@synthesize detailModel;
static NSString *titleAndAuthorCellID = @"titleAndAuthorCell";
static NSString *authorAndTimeCellID = @"authorAndTimeCell";
static NSString *StrongRelateCountsCellID = @"StrongRelateCountsCell";
static NSString *videoCellID = @"videoCell";
static NSString *cntentImageCellID = @"cntentImageCell";
static NSString *contentTextCellID = @"contentTextCell";
static NSString *reTopicCellID = @"reTopicCell";
static NSString *ShareBtnCellID = @"ShareBtnCell";
static NSString *BannerCellID = @"BannerCell";
static NSString *nodeInfoViewCellID = @"nodeInfoViewCell";
static NSString *relateNewCellID = @"relateNewCell";
static NSString *sectionFootID = @"sectionFoot";
static NSString *askContentCellID = @"askContentCell";
static NSString *answerContentCellID = @"answerContentCell";
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.clipsToBounds = YES;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.contentInset = UIEdgeInsetsZero;
isLoadAdSuccess = YES;
[self.tableView registerClass:[titleAndAuthorCell class] forCellReuseIdentifier:titleAndAuthorCellID];
[self.tableView registerClass:[authorAndTimeCell class] forCellReuseIdentifier:authorAndTimeCellID];
[self.tableView registerClass:[strongRelateCountsCell class] forCellReuseIdentifier:StrongRelateCountsCellID];
[self.tableView registerClass:[videoCell class] forCellReuseIdentifier:videoCellID];
[self.tableView registerClass:[cntentImageCell class] forCellReuseIdentifier:cntentImageCellID];
[self.tableView registerClass:[contentTextCell class] forCellReuseIdentifier:contentTextCellID];
[self.tableView registerClass:[reTopicCell class] forCellReuseIdentifier:reTopicCellID];
[self.tableView registerClass:[sinaAndWeChatCell class] forCellReuseIdentifier:ShareBtnCellID];
[self.tableView registerClass:[bannerCell class] forCellReuseIdentifier:BannerCellID];
[self.tableView registerClass:[nodeInfoViewCell class] forCellReuseIdentifier:nodeInfoViewCellID];
[self.tableView registerClass:[detailContentMoreInfoCell class] forCellReuseIdentifier:relateNewCellID];
[self.tableView registerClass:[askContentCell class] forCellReuseIdentifier:askContentCellID];
[self.tableView registerClass:[answerContentCell class] forCellReuseIdentifier:answerContentCellID];
self.isVideoPlaying = NO;
UIPinchGestureRecognizer *zoomGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchHandler:)];
zoomGesture.delaysTouchesBegan = YES;
[self.tableView addGestureRecognizer:zoomGesture];
self.detailModel = [detailPageViewModel new];
self.detailModel.delegate = self;
}
-(void)viewWillAppear:(BOOL)animated{
//【适配性】ios7,新闻详情页:滑动手指缩放字号,弹出tips未居中(bug:6088)
self.fontShowView.frame = CGRectMake(CGRectGetMinX(self.tableView.bounds)+ CGRectGetWidth(self.tableView.bounds)/2-364/2, CGRectGetHeight(self.view.bounds)/2-205/2, 364/2, 205/2);
self.fontShowView.center = self.tableView.center;
__weak typeof(self) Self = self;
if (self.hotAskVC && self.hotAskVC.isNeedHold) {
[self presentController:self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{
} dismiss:^{
if (!Self.hotAskVC.isNeedHold) {
Self.hotAskVC = nil;
}
}];
}
}
-(UIView *)fontShowView{
if (!_fontShowView) {
_fontShowView = [[UILabel alloc] initWithFrame:CGRectMake((rect_screen.size.width-125)/2-364/4, rect_screen.size.height/2-205/4, 364/2, 205/2)];
_fontShowView.backgroundColor = [UIColor colorWithHexString:@"0x262627"];
}
return _fontShowView;
}
-(UILabel *)fontShowT{
if (!_fontShowT) {
_fontShowT = [UILabel new];
_fontShowT.backgroundColor = [UIColor clearColor];
_fontShowT.text = @"T";
_fontShowT.font = appFont(22, NO);
_fontShowT.textColor = [UIColor whiteColor];
_fontShowT.textAlignment = NSTextAlignmentCenter;
}
return _fontShowT;
}
-(UILabel *)fontShowFont{
if (!_fontShowFont) {
_fontShowFont = [UILabel new];
_fontShowFont.backgroundColor = [UIColor clearColor];
_fontShowFont.textColor = [UIColor whiteColor];
_fontShowFont.font = appFont(TEXT_THREE_LEVELSIZE, NO);
_fontShowFont.textAlignment = NSTextAlignmentCenter;
}
return _fontShowFont;
}
#pragma mark -- set DATA
- (void)setDetailContentBO:(contDetailPageVO *)detailBO {
if (detailBO) {
_detailContentBO = detailBO;
self.contentBO = setJsonDicToDataModel(detailBO.content, [contentObjectBO class]);
}
}
- (void)setContentBO:(contentObjectBO *)contentData {
if (!contentData) {
TPLOG(@"返回数据有误!");
return;
}
_contentBO = contentData;
self.contentDataList = [NSMutableArray array];
heightOfCellInEachSection = [NSMutableArray array];
/* 标题 作者 时间 强关系 视频 正文内容 分享 栏目信息 banner 一个section */
NSMutableArray *sectionOneArray = [NSMutableArray array];
NSMutableArray *sectionOneHeightArray = [NSMutableArray array];
[sectionOneArray addObject:self.contentBO.name?self.contentBO.name:@""];//标题
// CGFloat titleHeight = heightForString(contentData.name, appFont(76/2, NO),1320/2 , NSLineBreakByWordWrapping);
CGFloat titleHeight = heightForAttributeString(getLineSpaceAttributedString(contentData.name, 10, appFont(76/2, NO)), 1320/2, appFont(76/2, NO));
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",titleHeight+30]]; //标题高度
[sectionOneArray addObject:contentData.author?self.contentBO.author:@""]; //作者
[sectionOneHeightArray addObject:@"25"];
[sectionOneArray addObject:contentData.pubTime?self.contentBO.pubTime:@""]; //发表时间
// [sectionOneHeightArray addObject:@"25"];
[sectionOneHeightArray addObject:@"50"];
NSArray *strongRelateArray = self.detailContentBO.strongRelateConts; //强相关新闻数据源
if (strongRelateArray.count > 0) {
[strongRelateArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSDictionary *dic = obj;
listContObjectVO *listBO = setJsonDicToDataModel(dic, [listContObjectVO class]);
[sectionOneArray addObject:listBO];
CGFloat descHeight = returnTextHeightWithRTLabel(listBO.name, 1320/2, appFont(imageDescFontSize, NO), 5);
CGFloat strongHeight = 250*1.1 + 5 +descHeight+40;
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",strongHeight]];//bug:5467
// if ([listBO.watermark intValue] == 1) {
// [sectionOneHeightArray addObject:@"439"];
// }else {
// [sectionOneHeightArray addObject:@"351"];
// }
}];
}
NSArray *imageList = self.contentBO.images; //视频
NSArray *videoList = self.contentBO.videos;
if (videoList.count > 0) {
[imageList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
imageObjectBO *imgBO = setJsonDicToDataModel(obj, [imageObjectBO class]);
if ([imgBO.tags isEqualToString:@"www_video"]
|| [imgBO.tags isEqualToString:@"www_big"]) {
[sectionOneArray addObject:imgBO];
*stop = YES;
}
}];
[videoList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
videoObjectBO *video = setJsonDicToDataModel(obj, [videoObjectBO class]);
CGFloat videoHeight = 338*1.1;
CGFloat videoDescHeight = heightForString(video.name, appFont(imageDescFontSize, NO), 1320/2, NSLineBreakByWordWrapping);
videoHeight = videoHeight + videoDescHeight +40+5;
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",videoHeight]];
self.videoBO = video;
}];
}
NSArray *contentList = self.contentBO.content; //文章详情
// NSMutableArray *analysisedContentList = [self.detailModel analysisContent:contentList];
//【倒退】iPad新闻详情页:有几篇新闻显示异常(bug:5649)
NSMutableArray *analysisedContentList = analysisContent(contentList);
[analysisedContentList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[imageObjectBO class]]) {
imageObjectBO *imageBO = obj;
[sectionOneArray addObject:obj];
CGFloat imageExtHeight = [self.detailModel returnContentExtendHeight:imageBO.desc];
CGSize imageSize = CGSizeMake([imageBO.width floatValue], [imageBO.height floatValue]);
CGSize size = CGSizeZero;
if (imageSize.width > 660) {
size = CGSizeMake(660, imageSize.height*660/imageSize.width);
}else {
size = CGSizeMake([imageBO.width floatValue]*1.1, [imageBO.height floatValue]*1.1);
}
CGFloat cellHeight = size.height+imageExtHeight;
if (idx == analysisedContentList.count - 1) {
cellHeight = cellHeight + 15;
/**
* bug:5171(详情页底部的图片和话题卡片重叠)
*/
}
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",cellHeight]];
}else {
NSString *str = obj;
NSMutableAttributedString *attributeStr = [self.detailModel returnContentTextString:str];
CGFloat strHeight = heightForAttributeString(attributeStr, 1320/2,appFont([TPUserDefault instance].contFontSize, NO));
CGFloat cellHeight = strHeight+[ipadLineAndParaSpace newsColumSpace];//(bug:5663)
[sectionOneArray addObject:attributeStr];
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",cellHeight]];
}
}];
//【需求】新闻支持强关系话题显示(bug:4324)
//强相关话题
NSArray *reTopics = self.detailContentBO.relateTopics?self.detailContentBO.relateTopics:[NSArray array];//强关联话题数据源
[reTopics enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) {
TopicInfoBO *topic = setJsonDicToDataModel(dic, [TopicInfoBO class]);
[sectionOneArray addObject:topic];
if (idx != reTopics.count -1) {
[sectionOneHeightArray addObject:@"260"];
}else{
[sectionOneHeightArray addObject:@"275"];
}
}];
//分享
[sectionOneArray addObject:@"shareCell"];
[sectionOneHeightArray addObject:@"70"];
//栏目信息
nodeObjectBO *nodeInfo = setJsonDicToDataModel(self.contentBO.nodeInfo, [nodeObjectBO class]);
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if ([nodeInfo.isOrder intValue] > 0 && ![array containsObject:nodeInfo.nodeId]) {
[array addObject:nodeInfo.nodeId];
[TPUserDefault instance].orderEventTempList = array;
}
[sectionOneArray addObject:nodeInfo];
[sectionOneHeightArray addObject:@"70"];
//banner
[sectionOneArray addObject:@"banner"];
[sectionOneHeightArray addObject:@"280"];
//secion1结束
[self.contentDataList addObject:sectionOneArray];
[heightOfCellInEachSection addObject:sectionOneHeightArray];
//热追问
NSMutableArray *qaList = [NSMutableArray array];
NSArray *tempQaList = self.detailContentBO.qaList; //热追问数据源
NSMutableArray *qaHeightArray = [NSMutableArray array];
[tempQaList enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) {
commentObjectVO *commentBO = setJsonDicToDataModel(dic, [commentObjectVO class]);
NSString *newNums = dic[@"newNums"];
if (newNums) {
commentBO.unNums = newNums;
}
[qaList addObject:commentBO];
CGFloat askHeight = 126/2;
CGFloat askCotentHeight = returnTextHeightWithRTLabel(commentBO.content, 1170/2, appFont(interactionFontSize, NO),10);
askHeight = askHeight + askCotentHeight + 13;
[qaHeightArray addObject:[NSString stringWithFormat:@"%f", askHeight]];
if (commentBO.answerList && commentBO.answerList.count > 0) {
commentObjectVO *answerBO = setJsonDicToDataModel(commentBO.answerList[0], [commentObjectVO class]);
[qaList addObject:answerBO];
CGFloat hei = 130/2;
CGFloat answerContent = returnTextHeightWithRTLabel(answerBO.content, 1170/2, appFont(interactionFontSize, NO),11)>interaction4LinesSpace?interaction4LinesSpace+30:returnTextHeightWithRTLabel(answerBO.content, 1170/2, appFont(interactionFontSize, NO),10);
hei = hei+answerContent+10;
[qaHeightArray addObject:[NSString stringWithFormat:@"%f", hei]];
}
}];
if (qaList.count > 0) {
[qaList addObject:@"1"];
[qaHeightArray addObject:@"25"];
[self.contentDataList addObject:qaList];
[heightOfCellInEachSection addObject:qaHeightArray];
}
//相关新闻
NSMutableArray* relateList = [NSMutableArray array];
NSArray *relateConts = self.detailContentBO.relateConts?self.detailContentBO.relateConts:[NSArray array]; //关联文章数据源
[relateConts enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) {
listContObjectVO *listBO = setJsonDicToDataModel(dic, [listContObjectVO class]);
[relateList addObject:listBO];
}];
if (relateList.count > 0) {
[self.contentDataList addObject:relateList];
[heightOfCellInEachSection addObject:@"260"];
self.relateCell = (detailContentMoreInfoCell*)[self.tableView dequeueReusableCellWithIdentifier:relateNewCellID];
self.relateCell.dataList = relateList;
self.relateCell.delegate = self;
}
self.bannerCell = (bannerCell*)[self.tableView dequeueReusableCellWithIdentifier:BannerCellID];
self.bannerCell.delegate = self;
self.bannerCell.adUrl = self.detailContentBO.adUrl3;
[self.tableView reloadData];
[CoreAnimationEffect animationEaseOut:self.view];
}
- (void)reloadTableWhenFontChange {
self.contentBO = self.contentBO;
}
#pragma mark UITableViewDelegate and UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.contentDataList?self.contentDataList.count:0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.contentDataList && self.contentDataList.count > 0) {
if (self.contentDataList.count != 3) {
if (section == 0) {
NSArray *sectionArray = self.contentDataList[section];
return sectionArray.count;
}else return 1;
}else {
if (section != 2) {
NSArray *sectionArray = self.contentDataList[section];
return sectionArray.count;
}else return 1;
}
}else return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (heightOfCellInEachSection && heightOfCellInEachSection.count > 0) {
if (self.contentDataList.count != 3) {
if (indexPath.section == 0) {
NSArray *heightArray = heightOfCellInEachSection[indexPath.section];
return [heightArray[indexPath.row] floatValue];
}else {
return [heightOfCellInEachSection[indexPath.section] floatValue];
}
}else {
if (indexPath.section != 2) {
NSArray *heightArray = heightOfCellInEachSection[indexPath.section];
return [heightArray[indexPath.row] floatValue];
}else {
return [heightOfCellInEachSection[indexPath.section] floatValue];
}
}
}else return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0) {
return 0;
}else {
return 30;
}
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section != 0) {
CGFloat padding = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
padding = 125;
}
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.tableView.frame), 30)];
view.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
UIView *colorView = [[UIView alloc]initWithFrame:CGRectMake(padding, 5, 5, 20)];
colorView.backgroundColor = [UIColor colorWithHexString:BLUECOLOR];
[view addSubview:colorView];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(colorView.frame)+10, 0, CGRectGetWidth(self.tableView.frame)-padding, 30)];
label.font = appFont(20, NO);
label.textColor = [UIColor colorWithHexString:TextBlack];
label.backgroundColor = [UIColor clearColor];
[view addSubview:label];
NSArray *sectionArray = self.contentDataList[section];
id obj = sectionArray[0];
if ([obj isKindOfClass:[commentObjectVO class]]) {
label.text = @"热追问";
}else {
label.text = @"继续阅读";
}
return view;
}else return nil;
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) { //详情内容
if (indexPath.row == 0) { //标题
return [self getTitleAndAuthorCell:table cellForRowAtIndexPath:indexPath];
}else if (indexPath.row == 1) { //作者
return [self getAurhorCell:table cellForRowAtIndexPath:indexPath];
}else if (indexPath.row == 2) { //发布时间
return [self getPubTimeCell:table cellForRowAtIndexPath:indexPath];
}else {
NSArray *contentSectionList = self.contentDataList[indexPath.section];
id obj = contentSectionList[indexPath.row];
if ([obj isKindOfClass:[listContObjectVO class]]) { //强相关新闻
return [self getStrongRelateCountsCell:table cellForRowAtIndexPath:indexPath];
}else if ([obj isKindOfClass:[imageObjectBO class]]) {
imageObjectBO *imageBO = obj;
if ([imageBO.tags isEqualToString:@"www_video"] || [imageBO.tags isEqualToString:@"www_big"]) { //文章视频
return [self getVideoCell:table cellForRowAtIndexPath:indexPath];
}else { //普通图片
return [self getCntentImageCell:table cellForRowAtIndexPath:indexPath];
}
}else if ([obj isKindOfClass:[NSString class]]){
if ([obj isEqualToString:@"shareCell"]) { //分享
return [self getShareBtnCell:table cellForRowAtIndexPath:indexPath];
}else if ([obj isEqualToString:@"banner"]) { //banner
return [self getBannerCell:table cellForRowAtIndexPath:indexPath];
}else {//文章文字内容
return [self getContentTextCell:table cellForRowAtIndexPath:indexPath];
}
}else if ([obj isKindOfClass:[NSMutableAttributedString class]]){
return [self getContentTextCell:table cellForRowAtIndexPath:indexPath];
}else if([obj isKindOfClass:[TopicInfoBO class]]){//【需求】新闻支持强关系话题显示(bug:4324)
return [self getTopicCell:table cellForRowAtIndexPath:indexPath];
}else { //栏目信息
return [self getNodeInfoViewCell:table cellForRowAtIndexPath:indexPath];
}
}
}else {
NSArray *otherSectionArray = self.contentDataList[indexPath.section];
id obj = otherSectionArray[indexPath.row];
if ([obj isKindOfClass:[commentObjectVO class]]) { //热追问
commentObjectVO *comment = obj;
if ([comment.type intValue] == 2) {
return [self getHotAskContentCell:table cellForRowAtIndexPath:indexPath];
}else return [self getHotAnswerContentCell:table cellForRowAtIndexPath:indexPath];
}else if ([obj isKindOfClass:[NSString class]] && [obj isEqualToString:@"1"]) { //foot
return [self getSectionFoot:table cellForRowAtIndexPath:indexPath];
}else { //继续阅读
return [self getRelateNewCell:table cellForRowAtIndexPath:indexPath];
}
}
}
- (titleAndAuthorCell*)getTitleAndAuthorCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
titleAndAuthorCell *cell = (titleAndAuthorCell*)[tableView dequeueReusableCellWithIdentifier:titleAndAuthorCellID];
if (nil == cell) {
cell = [[titleAndAuthorCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:titleAndAuthorCellID];
}
cell.contentTitle = self.contentBO.name?self.contentBO.name:@"";
return cell;
}
- (authorAndTimeCell*)getAurhorCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
authorAndTimeCell *cell = (authorAndTimeCell*)[tableView dequeueReusableCellWithIdentifier:authorAndTimeCellID];
if (nil == cell) {
cell = [[authorAndTimeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:authorAndTimeCellID];
}
cell.text = self.contentBO.author?self.contentBO.author:@"";
return cell;
}
- (authorAndTimeCell*)getPubTimeCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
authorAndTimeCell *cell = (authorAndTimeCell*)[tableView dequeueReusableCellWithIdentifier:authorAndTimeCellID];
if (nil == cell) {
cell = [[authorAndTimeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:authorAndTimeCellID];
}
if (self.contentBO.pubTime) {
NSString *timeStr = self.contentBO.pubTime;
cell.text = timeStr;
}else cell.text = @"";
return cell;
}
- (strongRelateCountsCell*)getStrongRelateCountsCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
strongRelateCountsCell *cell = (strongRelateCountsCell*)[tableView dequeueReusableCellWithIdentifier:StrongRelateCountsCellID];
if (nil == cell) {
cell = [[strongRelateCountsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:StrongRelateCountsCellID];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
id obj = contentSectionList[indexPath.row];
cell.listdataBO = obj;
return cell;
}
- (videoCell*)getVideoCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
videoCell *cell = (videoCell*)[tableView dequeueReusableCellWithIdentifier:videoCellID];
if (nil == cell) {
cell = [[videoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:videoCellID];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
id obj = contentSectionList[indexPath.row];
cell.imageBO = obj;
cell.videoBO = self.videoBO;
cell.delegate = self;
cell.indexPath = indexPath;
return cell;
}
- (cntentImageCell*)getCntentImageCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cntentImageCell *cell = (cntentImageCell*)[tableView dequeueReusableCellWithIdentifier:cntentImageCellID];
if (nil == cell) {
cell = [[cntentImageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cntentImageCellID];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
id obj = contentSectionList[indexPath.row];
cell.imageBO = obj;
cell.delegate = self;
return cell;
}
- (contentTextCell*)getContentTextCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
contentTextCell *cell = (contentTextCell*)[tableView dequeueReusableCellWithIdentifier:contentTextCellID];
if (nil == cell) {
cell = [[contentTextCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:contentTextCellID];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
id obj = contentSectionList[indexPath.row];
cell.text = obj;
return cell;
}
- (reTopicCell*)getTopicCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {//【需求】新闻支持强关系话题显示(bug:4324)
reTopicCell *cell = (reTopicCell*)[tableView dequeueReusableCellWithIdentifier:reTopicCellID];
if (nil == cell) {
cell = [[reTopicCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reTopicCellID];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
TopicInfoBO *obj = contentSectionList[indexPath.row];
cell.topic = obj;
return cell;
}
- (sinaAndWeChatCell*)getShareBtnCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
sinaAndWeChatCell *cell = (sinaAndWeChatCell*)[tableView dequeueReusableCellWithIdentifier:ShareBtnCellID];
if (nil == cell) {
cell = [[sinaAndWeChatCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ShareBtnCellID];
}
cell.contentBO = self.contentBO;
return cell;
}
- (bannerCell*)getBannerCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// self.bannerCell.adUrl = self.detailContentBO.adUrl3;
return self.bannerCell;
}
- (nodeInfoViewCell*)getNodeInfoViewCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
nodeInfoViewCell *cell = (nodeInfoViewCell*)[tableView dequeueReusableCellWithIdentifier:nodeInfoViewCellID];
if (nil == cell) {
cell = [[nodeInfoViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nodeInfoViewCellID];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
id obj = contentSectionList[indexPath.row];
cell.indexPath = indexPath;
cell.nodeInfoBO = obj;
cell.delegate = self;
return cell;
}
- (detailContentMoreInfoCell*)getRelateNewCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.relateCell;
}
- (UITableViewCell*)getSectionFoot:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sectionFootID];
if (nil == cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionFootID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return cell;
}
- (askContentCell*)getHotAskContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
askContentCell *cell = (askContentCell*)[tableView dequeueReusableCellWithIdentifier:askContentCellID];
if (nil == cell) {
cell = [[askContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:askContentCellID];
}
NSArray *otherSectionArray = self.contentDataList[indexPath.section];
id obj = otherSectionArray[indexPath.row];
cell.commentBO = obj;
cell.askContentDelegate = self;
return cell;
}
- (answerContentCell*)getHotAnswerContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
answerContentCell *cell = (answerContentCell*)[tableView dequeueReusableCellWithIdentifier:answerContentCellID];
if (nil == cell) {
cell = [[answerContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:answerContentCellID];
}
NSArray *otherSectionArray = self.contentDataList[indexPath.section];
id obj = otherSectionArray[indexPath.row];
cell.commentBO = obj;
cell.delegate = self;
cell.indexPath = indexPath;
__block NSIndexPath* IndexPath = indexPath;
__weak typeof(self) Self = self;
[cell expandCell:^(BOOL isExpand, CGFloat labelHeight) {
if (isExpand) {
CGFloat offset = labelHeight - interaction4LinesSpace;
NSMutableArray *qaHeightList = Self.heightOfCellInEachSection[indexPath.section];
NSString *qaAllHeightStr = qaHeightList[IndexPath.row];
CGFloat qaAllHeight = [qaAllHeightStr floatValue]+offset;
[qaHeightList replaceObjectAtIndex:indexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]];
[Self.heightOfCellInEachSection replaceObjectAtIndex:IndexPath.section withObject:qaHeightList];
NSArray *array = @[IndexPath];
[Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];
}else {
CGFloat offset = labelHeight - interaction4LinesSpace;
NSMutableArray *qaHeightList = Self.heightOfCellInEachSection[indexPath.section];
NSString *qaAllHeightStr = qaHeightList[IndexPath.row];
CGFloat qaAllHeight = [qaAllHeightStr floatValue]-offset;
[qaHeightList replaceObjectAtIndex:indexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]];
[Self.heightOfCellInEachSection replaceObjectAtIndex:IndexPath.section withObject:qaHeightList];
NSArray *array = @[IndexPath];
dispatch_async(dispatch_get_main_queue(), ^{
[Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];
[Self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
});
}
}];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self stopAndRemoveVideo];//视频: 打开一个视频新闻,播放视频后,继续阅读再打开一个视频新闻后APP会闪退(bug:4826)
NSArray *otherSectionArray = self.contentDataList[indexPath.section];
id obj = otherSectionArray[indexPath.row];
__weak typeof(self) Self = self;
if ([obj isKindOfClass:[commentObjectVO class]]) {
commentObjectVO *item = obj;
if ([item.type intValue] == 2) {
if (!Self.hotAskVC) {
Self.hotAskVC = [[hotAskListHomeController alloc]init];
Self.hotAskVC.commentBO = item;
Self.hotAskVC.delegate = self;
}
[self presentController:Self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{
}dismiss:^{
if (!Self.hotAskVC.isNeedHold) {
Self.hotAskVC = nil;
}
}tapHandler:^{
if (Self.hotAskVC.writeVC) {
[Self.hotAskVC.writeVC closeKeyBoard];
}
}];
}
}else if([obj isKindOfClass:[TopicInfoBO class]]){
[MobClick event:@"49"];
TopicInfoBO *topic = (TopicInfoBO*)obj;
topicContentController *vc = [[topicContentController alloc]init];
vc.preTopicInfo = topic;
userBO *user = setJsonDicToDataModel(topic.userInfo, [userBO class]);
vc.creatUser = user;
[self.navigationController pushViewController:vc animated:YES];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}else {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[strongRelateCountsCell class]]) {
listContObjectVO *listBO = obj;
pushContentWithListContentObject(self.navigationController, listBO);
}
}
}
#pragma mark - cell delegate
- (void)goToNodeListPage:(nodeObjectBO *)nodeBO {
[self stopAndRemoveVideo];//视频: 打开一个视频新闻,播放视频后,继续阅读再打开一个视频新闻后APP会闪退(bug:4826)
customFlowLayout *layout = nil;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGSize itemSize = CGSizeZero;
layout= [[customFlowLayout alloc]init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.minimumLineSpacing = 35;
layout.minimumInteritemSpacing = 35;
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
CGFloat width = (self.view.bounds.size.width-35*3)/2;
itemSize = CGSizeMake(width, 470/2);
}else {
CGFloat width = (self.view.bounds.size.width-35*4)/3;
itemSize = CGSizeMake(width, 446/2);
}
layout.itemSize = itemSize;
columnListController *vc = [[columnListController alloc]initWithCollectionViewLayout:layout];
vc.nodeObj = nodeBO;
[self.navigationController pushViewController:vc animated:YES];
layout = nil;
}
- (void)pushToDetailPage:(listContObjectVO *)listBO {
[MobClick event:@"26"];
[self stopAndRemoveVideo];//视频: 打开一个视频新闻,播放视频后,继续阅读再打开一个视频新闻后APP会闪退(bug:4826)
pushContentWithListContentObject(self.navigationController, listBO);
}
- (void)pushToColumnPage:(listContObjectVO *)listBO {
[self stopAndRemoveVideo];
customFlowLayout *layout = nil;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGSize itemSize = CGSizeZero;
layout= [[customFlowLayout alloc]init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.minimumLineSpacing = 35;
layout.minimumInteritemSpacing = 35;
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
CGFloat width = (self.view.bounds.size.width-35*3)/2;
itemSize = CGSizeMake(width, 470/2);
}else {
CGFloat width = (self.view.bounds.size.width-35*4)/3;
itemSize = CGSizeMake(width, 446/2);
}
layout.itemSize = itemSize;
columnListController *vc = [[columnListController alloc]initWithCollectionViewLayout:layout];
vc.listBO = listBO;
[self.navigationController pushViewController:vc animated:YES];
layout = nil;
}
-(void)gotoUserInfo:(commentObjectVO *)comment{
[self stopAndRemoveVideo];//视频: 打开一个视频新闻,播放视频后,继续阅读再打开一个视频新闻后APP会闪退(bug:4826)
otherPersonHomepageController *otherVC = [otherPersonHomepageController new];
otherVC.commentBo = comment;
[self.navigationController pushViewController:otherVC animated:YES];
}
-(void)gotoPersonInfo:(commentObjectVO *)comment{
[self stopAndRemoveVideo];//视频: 打开一个视频新闻,播放视频后,继续阅读再打开一个视频新闻后APP会闪退(bug:4826)
[self dismissControllerAnimated:YES completion:^{
otherPersonHomepageController *otherVC = [otherPersonHomepageController new];
otherVC.commentBo = comment;
[self.navigationController pushViewController:otherVC animated:YES];
}];
}
- (void)clickImage:(imageObjectBO *)imgBO {
[self stopAndRemoveVideo];//视频: 打开一个视频新闻,播放视频后,继续阅读再打开一个视频新闻后APP会闪退(bug:4826)
TPLOG(@"click Image:%@",imgBO);
NSMutableArray *imageBOArray = [NSMutableArray array];
[self.contentDataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[NSArray class]]) {
NSArray *array = obj;
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[imageObjectBO class]]) {
imageObjectBO *imageBO = obj;
if (!isBlankString(imageBO.tags) && ![imageBO.tags isEqualToString:@"www_video"] && ![imageBO.tags isEqualToString:@"www_big"]) {
[imageBOArray addObject:imageBO];
}
}
}];
}
}];
__block NSInteger currentIndex;
[imageBOArray enumerateObjectsUsingBlock:^(imageObjectBO* obj, NSUInteger idx, BOOL *stop) {
if ([obj.url isEqualToString:imgBO.url]) {
currentIndex = idx;
}
}];
TPImageScannerController *imageScanner = [[TPImageScannerController alloc]init];
imageScanner.type = contentImageScannerType;
imageScanner.currentIndex = currentIndex;
imageScanner.imageBOList = imageBOArray;
imageScanner.type = contentImageScannerType;
imageScanner.delegate = self;
[self.navigationController pushViewController:imageScanner animated:NO];
[CoreAnimationEffect animationEaseIn:self.navigationController.view];
if (isNotIOS8) {
imageScanner.currentIndex = currentIndex;
}
}
- (void)hasPraisedAnswer:(NSIndexPath *)indexPath withCommentBO:(commentObjectVO *)commentBO{
NSArray *otherSectionArray = self.contentDataList[indexPath.section];
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:otherSectionArray];
[tempArray replaceObjectAtIndex:indexPath.row withObject:commentBO];
[self.contentDataList replaceObjectAtIndex:indexPath.section withObject:tempArray];
}
- (void)clickOrder:(NSString *)nodeID isOrder:(BOOL)isOrder orderBtn:(UIButton *)btn indexPath:(NSIndexPath *)indexPath{
if ([TPUserDefault instance].userBO) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"n":nodeID,@"oType":@"1"}];
if (!isOrder) {
[dic setValue:@"2" forKey:@"oType"];
}
__weak typeof(self) Self = self;
[Remote doJsonActionWithBlock:1 requestUrl:orderNodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
NSMutableArray *contentSectionList = [NSMutableArray arrayWithArray:Self.contentDataList[indexPath.section]];
nodeObjectBO *obj = (nodeObjectBO*)contentSectionList[indexPath.row];
if (isOrder) {
btn.selected = YES;
btn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-28/2);
ShowMessage(@"订阅成功", YES);
[btn setImage:Image(@"detailPage/orderedIcon.png") forState:UIControlStateNormal];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateNormal];
[btn setTitle:@"已订阅" forState:UIControlStateNormal];
obj.isOrder = @"1";
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if (![array containsObject:nodeID]) {
[array addObject:nodeID];
[TPUserDefault instance].orderEventTempList = array;
}
}else {
btn.selected = NO;
btn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-15/2);
ShowMessage(@"取消订阅", YES);
[btn setImage:Image(@"detailPage/addPic.png") forState:UIControlStateNormal];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
[btn setTitle:@"订阅" forState:UIControlStateNormal];
obj.isOrder = @"0";
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if ([array containsObject:nodeID]) {
[array removeObject:nodeID];
[TPUserDefault instance].orderEventTempList = array;
}
}
[contentSectionList replaceObjectAtIndex:indexPath.row withObject:obj];
[Self.contentDataList replaceObjectAtIndex:indexPath.section withObject:contentSectionList];
contDetailPageVO *data = self.detailContentBO;
contentObjectBO *contentBO = setJsonDicToDataModel(data.content, [contentObjectBO class]);
NSMutableDictionary *nodeInfoDic = setDataModelToDic(obj, [nodeObjectBO class]);
contentBO.nodeInfo = nodeInfoDic;
data.content = setDataModelToDic(contentBO, [contentObjectBO class]);
if ([self.detailDelegate respondsToSelector:@selector(orderDelegate:)]) {
[self.detailDelegate orderDelegate:data];
}
//新闻详情页:切换字号,没有更新订阅状态(bug:5823)
self.contentBO.nodeInfo = nodeInfoDic;
}
}];
}else {
loginPopUpController *loginVC = loginPopUpController.new;
__weak typeof(self) Self = self;
[self presentController:loginVC animated:YES presentSize:loginPopUpSize completion:^{
} dismiss:^{
if ([TPUserDefault instance].userBO) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"n":nodeID,@"oType":@"1"}];
if (!isOrder) {
[dic setValue:@"2" forKey:@"oType"];
}
[Remote doJsonActionWithBlock:1 requestUrl:orderNodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
NSMutableArray *contentSectionList = [NSMutableArray arrayWithArray:Self.contentDataList[indexPath.section]];
nodeObjectBO *obj = (nodeObjectBO*)contentSectionList[indexPath.row];
if (isOrder) {
btn.selected = YES;
btn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-28/2);
ShowMessage(@"订阅成功", YES);
[btn setImage:Image(@"detailPage/orderedIcon.png") forState:UIControlStateNormal];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateNormal];
[btn setTitle:@"已订阅" forState:UIControlStateNormal];
obj.isOrder = @"1";
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if (![array containsObject:nodeID]) {
[array addObject:nodeID];
[TPUserDefault instance].orderEventTempList = array;
}
}else {
btn.selected = NO;
btn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-15/2);
ShowMessage(@"取消订阅", YES);
[btn setImage:Image(@"detailPage/addPic.png") forState:UIControlStateNormal];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
[btn setTitle:@"订阅" forState:UIControlStateNormal];
obj.isOrder = @"0";
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if ([array containsObject:nodeID]) {
[array removeObject:nodeID];
[TPUserDefault instance].orderEventTempList = array;
}
}
[contentSectionList replaceObjectAtIndex:indexPath.row withObject:obj];
[Self.contentDataList replaceObjectAtIndex:indexPath.section withObject:contentSectionList];
}
}];
}
}];
}
}
- (void)loadAdFailed {
isLoadAdSuccess = NO;
NSMutableArray *list = self.heightOfCellInEachSection[0];
[list removeLastObject];
[list addObject:@"0"];
[self.heightOfCellInEachSection replaceObjectAtIndex:0 withObject:list];
[self.tableView reloadData];
// NSArray *array = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:self.heightOfCellInEachSection.count-1 inSection:0]];
// [self.tableView beginUpdates];
// [self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
// [self.tableView endUpdates];
}
- (void)clickAdd:(remotePushBO *)pushBO {
[TPUserDefault instance].pushBO = pushBO;
// pushToContentAfterPushOrClickAd(self.navigationController);
}
#pragma mark - hot ask list delegate
- (void)goToOriginContent:(objInfoBO *)commentBO presentedController:(TPHttpController *)presentedController{
[self stopAndRemoveVideo];//视频: 打开一个视频新闻,播放视频后,继续阅读再打开一个视频新闻后APP会闪退(bug:4826)
__weak typeof(self) Self = self;
[presentedController dismissControllerAnimated:YES completion:^{
pushContentWithObjInfo(Self.navigationController, commentBO);
}];
}
- (void)clickSponsor:(NSString *)url {
[self stopAndRemoveVideo];//视频: 打开一个视频新闻,播放视频后,继续阅读再打开一个视频新闻后APP会闪退(bug:4826)
if (isBlankString(url)) {
return;
}
TPWebViewContoller *webVC = [[TPWebViewContoller alloc]init];
[self.navigationController pushViewController:webVC animated:YES];
webVC.url = url;
}
- (void)statusBarOrientationChange:(NSNotification *)notification{
if (self.moviePlayerController && !self.moviePlayerController.movieFullscreen) {
CGFloat padding = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
padding = 125;
}
videoRect = CGRectMake(padding, 0, videoRect.size.width, videoRect.size.height);
[self.moviePlayerController setFrame:videoRect];
}
// self.fontShowView.frame = CGRectMake((rect_screen.size.width-125)/2-364/4, rect_screen.size.height/2-205/4, 364/2, 205/2);
//【适配性】ios7,新闻详情页:滑动手指缩放字号,弹出tips未居中(bug:6088)
self.fontShowView.frame = CGRectMake(CGRectGetWidth(self.tableView.bounds)/2-364/2, CGRectGetHeight(self.tableView.bounds)/2-205/2, 364/2, 205/2);
self.fontShowView.center = self.tableView.center;
}
#pragma mark - video play
- (void)clickToPlayVideo:(CGRect)videoFrame indexPath:(NSIndexPath *)indexPath{
if (self.moviePlayerController) {
return;
}
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:0.3 animations:^{
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
} completion:^(BOOL finished) {
CGFloat padding = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
padding = 125;
}
videoRect = CGRectMake(padding, 0, videoFrame.size.width, videoFrame.size.height);
CGRect videoOrigRect = CGRectMake(CGRectGetMinX(self.tableView.frame)+padding, 0, videoFrame.size.width, videoFrame.size.height);
NSLog(@"%@",self.videoBO.url2);
self.moviePlayerController = nil;
self.moviePlayerController = [[ALMoviePlayerController alloc] initWithFrame:videoOrigRect];
self.moviePlayerController.view.backgroundColor = [UIColor blackColor];
ALMoviePlayerControls *movieControls = [[ALMoviePlayerControls alloc] initWithMoviePlayer:self.moviePlayerController style:ALMoviePlayerControlsStyleEmbedded];
[movieControls setBarHeight:40.f];
self.moviePlayerController.delegate = self;
self.moviePlayerController.controls = movieControls;
[self.view addSubview:self.moviePlayerController.view];
[self.moviePlayerController setContentURL:[NSURL URLWithString:self.videoBO.url2]];
[self.moviePlayerController setFullscreen:NO];
[self.moviePlayerController shouldAutoplay];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[UIView animateWithDuration:0.3 animations:^{
[self.moviePlayerController setFrame:videoRect];
if (isBlankString(self.videoBO.duration)) {
[self.moviePlayerController videoIsLiving];
}
self.isVideoPlaying = YES;
} completion:^(BOOL finished) {
}];
}];
}
- (void)playFinish:(NSNotification*)notification {
[self stopAndRemoveVideo];
self.isVideoPlaying = NO;
}
- (void)stopAndRemoveVideo {
if ([self.moviePlayerController isFullscreen]) {
[self.moviePlayerController setFullscreen:NO animated:YES];
}
[self.moviePlayerController stop];
[self.moviePlayerController.view removeFromSuperview];
self.moviePlayerController = nil;
[CoreAnimationEffect animationEaseOut:self.view];
}
- (void)moviePlayerWillMoveFromWindow {
if (![self.view.subviews containsObject:self.moviePlayerController.view]) {
[self.view addSubview:self.moviePlayerController.view];
[self.moviePlayerController setFrame:videoRect];
}
}
- (void)enterFullScreen:(BOOL)isEnter {
if ([self.detailDelegate conformsToProtocol:@protocol(detailContentDelegate)] &&
[self.detailDelegate respondsToSelector:@selector(videoEnterFullScreen:)]) {
[self.detailDelegate videoEnterFullScreen:isEnter];
}
if (!isEnter) {
CGFloat padding = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
padding = 125;
}
videoRect = CGRectMake(padding, 0, videoRect.size.width, videoRect.size.height);
[self.moviePlayerController setFrame:videoRect];
}
//视频:直播页和详情页播放视频,全屏播放视频,点击右上角的叉,会点到状态栏,导致底部页面弹回头部(bug:5748)
if ([self.detailDelegate respondsToSelector:@selector(detailStatusBarHidden:)]) {
[self.detailDelegate detailStatusBarHidden:isEnter];
}
}
- (void)dealloc {
[self stopAndRemoveVideo];
self.bannerCell = nil;
}
- (void)closeHandler {
[self stopAndRemoveVideo];
}
#pragma mark - image scanner delegate
- (void)imageContentClick:(imageObjectBO *)imageBO {
[self.navigationController popViewControllerAnimated:NO];
[CoreAnimationEffect animationEaseOut:self.navigationController.view];
}
#pragma mark - pinchhandler
- (void)pinchHandler:(UIPinchGestureRecognizer*)zoom {
[self.fontShowView removeFromSuperview];
[self.view addSubview:self.fontShowView];
[self.fontShowView addSubview:self.fontShowT];
[self.fontShowView addSubview:self.fontShowFont];
self.fontShowT.frame = CGRectMake(0, 24, 364/2, 22);
self.fontShowFont.frame = CGRectMake(0, 68, 364/2, 17);
UIGestureRecognizerState state = zoom.state;
if (state == UIGestureRecognizerStateBegan) {
}else if (state == UIGestureRecognizerStateChanged) {
}else if (state == UIGestureRecognizerStateEnded) {
if (zoom.scale > 1) { //放大
if ([TPUserDefault instance].contFontSize == fontSizeExBig) {
[self showFont:@"超大号字体" completion:nil];
return;
}
if ([TPUserDefault instance].contFontSize == fontSizeExSmall) {
[self showFont:@"小号字体" completion:^(BOOL finished) {
[TPUserDefault instance].contFontSize = fontSizeSmall;
[self reloadTableWhenFontChange];
}];
}else if ([TPUserDefault instance].contFontSize == fontSizeSmall) {
[self showFont:@"标准字体" completion:^(BOOL finished) {
[TPUserDefault instance].contFontSize = fontSizeMiddle;
[self reloadTableWhenFontChange];
}];
}else if ([TPUserDefault instance].contFontSize == fontSizeMiddle) {
[self showFont:@"大号字体" completion:^(BOOL finished) {
[TPUserDefault instance].contFontSize = fontSizeBig;
[self reloadTableWhenFontChange];
}];
}else if([TPUserDefault instance].contFontSize == fontSizeBig){
[self showFont:@"超大号字体" completion:^(BOOL finished) {
[TPUserDefault instance].contFontSize = fontSizeExBig;
[self reloadTableWhenFontChange];
}];
}
}else if (zoom.scale<1){
if ([TPUserDefault instance].contFontSize == fontSizeExSmall) {
[self showFont:@"超小号字体" completion:nil];
return;
}
if ([TPUserDefault instance].contFontSize == fontSizeExBig) {
[self showFont:@"大号字体" completion:^(BOOL finished) {
[TPUserDefault instance].contFontSize = fontSizeBig;
[self reloadTableWhenFontChange];
}];
}else if ([TPUserDefault instance].contFontSize == fontSizeBig) {
[self showFont:@"标准字体" completion:^(BOOL finished) {
[TPUserDefault instance].contFontSize = fontSizeMiddle;
[self reloadTableWhenFontChange];
}];
}else if ([TPUserDefault instance].contFontSize == fontSizeMiddle) {
[self showFont:@"小号字体" completion:^(BOOL finished) {
[TPUserDefault instance].contFontSize = fontSizeSmall;
[self reloadTableWhenFontChange];
}];
}else if([TPUserDefault instance].contFontSize == fontSizeSmall){
[self showFont:@"超小号字体" completion:^(BOOL finished) {
[TPUserDefault instance].contFontSize = fontSizeExSmall;
[self reloadTableWhenFontChange];
}];
}
}
}
}
-(void) showFont:(NSString*)fontSize completion:(void (^ __nullable)(BOOL finished))completion{
dispatch_async(dispatch_get_main_queue(), ^{
self.fontShowFont.text = fontSize;
[UIView animateWithDuration:0.45 animations:^{
[self.fontShowView setAlpha:1];
CGAffineTransform newTRansform = CGAffineTransformMakeScale(1.2, 1.2);
[self.fontShowView setTransform:newTRansform];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.15 animations:^{
[self.fontShowView setAlpha:0];
CGAffineTransform newTRansform = CGAffineTransformMakeScale(1, 1);
[self.fontShowView setTransform:newTRansform];
} completion:^(BOOL finished) {
[self.fontShowView removeFromSuperview];
if (completion) {
completion(YES);
}
}];
}];
});
}
- (void)refreshPage {
if ([self.detailDelegate respondsToSelector:@selector(needRefreshPage)]) {
[self.detailDelegate needRefreshPage];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
|