|
//
// detailContentController.m
// ThePaperDemo
//
// Created by scar1900 on 14/11/3.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "detailContentController.h"
#import "CoreAnimationEffect.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 "relateNewCell.h"
#import "hitAnwerCell.h"
#import "MLNavigationController.h"
#import <MediaPlayer/MediaPlayer.h>
#import "detailContentHomeController.h"
#import "columnManagerController.h"
#import "askDetailController.h"
#import "TPImageScannerController.h"
#import "reTopicCell.h"
#import "AskIconBaseCell.h"
#import "AskContentBaseCell.h"
#import "AnswerContentBaseCell.h"
#import "AnswerIconBaseCell.h"
#import "TrackCell.h"
#import "loginHomeController.h"
#import "detailPageViewModel.h"
#import "shareContent.h"
#import "bannerCell.h"
#import "contHeadBannerCell.h"
#import "myDynamicController.h"
#import "topicContentController.h"
#import "Reachability.h"
#import "ImageShareController.h"
#define detalLabelTag 1800
#define TABBARTAG 4800
#define SHARECONTENTTAG 2500
#define NAVBAR_HEIGHT 63
//@interface tabBarButton : UIButton
//
//@end
//
//@implementation tabBarButton
//
//- (void)setHighlighted:(BOOL)highlighted {
// if (self.selected) {
// return;
// }
// [super setHighlighted:highlighted];
//}
//
//@end
typedef enum _tabBtnStyle {
TabBarSayType = 0,
TabBarFollowType = 1,
TabBarShareType = 2,
TabBarCollectType = 3,
TabBarOKType = 4
} tabBtnStyle;
@interface tabBarBtnView : UIView {
CGSize imageSize;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
@property(nonatomic, weak)id selectTarget;
@property(nonatomic, strong)NSString *text;
@property(nonatomic, assign)tabBtnStyle buttonType;
@property(nonatomic, strong)UIButton *button;
@property(nonatomic, strong)UILabel *label;
@property(nonatomic, strong)NSString *contentID;
@end
@implementation tabBarBtnView
@synthesize text = _text;
@synthesize contentID;
@synthesize selectTarget;
- (id)initWithFrame:(CGRect)frame withButtonType:(tabBtnStyle)buttonStyle target:(id)target{
self = [super initWithFrame:frame];
if (self) {
self.selectTarget = target;
self.buttonType = buttonStyle;
[self addSubview:self.button];
// self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return self;
}
- (UIButton *)button {
if (!_button) {
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.backgroundColor = [UIColor clearColor];
// _button.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
// _button.titleLabel.textColor = [UIColor colorWithHexString:TextGray];
_button.titleLabel.textAlignment = NSTextAlignmentCenter;
[_button setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal];
[self setButtonWithType:_button];
}
_button.titleLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
return _button;
}
- (UILabel*)label {
if (_label) {
}
return _label;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
if (self.button.selected) {
return;
}
[self.button setSelected:YES];
self.button.userInteractionEnabled = NO;
if (animated) {
CGRect nowRect = [self convertRect:self.bounds toView:KEY_WINDOW];
CGFloat x = nowRect.origin.x;
CGFloat y = nowRect.origin.y;
CGFloat w = nowRect.size.width;
CGFloat h = nowRect.size.height;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x+w/2-6, y+h/4-20, 20, 16)];
label.text = @"+1";
label.textColor = [UIColor colorWithHexString:BLUECOLOR];
label.font = appFont(16, NO);
[UIView animateWithDuration:0.2 animations:^{
self.layer.transform = CATransform3DMakeScale(1.1, 1.1, 1.1);
// self.transform = CGAffineTransformScale(self.transform, 1.1, 1.1);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 animations:^{
self.layer.transform = CATransform3DMakeScale(1.0/1.1, 1.0/1.1, 1.0/1.1);
// self.transform = CGAffineTransformScale(self.transform, 1.0/1.1, 1.0/1.1);
} completion:^(BOOL finished) {
[KEY_WINDOW addSubview:label];
CGRect rect = label.frame;
rect.origin.y -= 30;
[UIView animateWithDuration:0.5 animations:^{
label.frame = rect;
label.alpha = 0;
} completion:^(BOOL finished) {
[label removeFromSuperview];
}];
}];
}];
}
}
- (void)setText:(NSString *)str {
_text = str;
[self.button setTitle:str forState:UIControlStateNormal];
}
- (void)setButtonWithType:(UIButton*)btn {
if (self.buttonType == TabBarSayType) {
UIImage *btImage = Image(@"tabBarButton/askIcon_detail.png");
imageSize = btImage.size;
[btn setImage:btImage forState:UIControlStateNormal];
[btn setImage:Image(@"tabBarButton/askIcon_detail_s.png") forState:UIControlStateHighlighted];
[btn setImage:Image(@"tabBarButton/askIcon_detail_s.png") forState:UIControlStateSelected];
[btn setTitle:@"评论" forState:UIControlStateNormal];
}else if (self.buttonType == TabBarFollowType) {
UIImage *btImage = Image(@"tabBarButton/follow.png");
imageSize = btImage.size;
[btn setImage:btImage forState:UIControlStateNormal];
[btn setImage:Image(@"tabBarButton/follow_s.png") forState:UIControlStateHighlighted];
[btn setTitle:@"跟踪" forState:UIControlStateNormal];
[btn addTarget:self.selectTarget action:@selector(trackEvent:) forControlEvents:UIControlEventTouchUpInside];
}else if (self.buttonType == TabBarShareType) {
UIImage *btImage = Image(@"tabBarButton/share.png");
imageSize = btImage.size;
[btn setImage:btImage forState:UIControlStateNormal];
[btn setImage:Image(@"tabBarButton/share_s.png") forState:UIControlStateHighlighted];
[btn setImage:Image(@"tabBarButton/share_s.png") forState:UIControlStateSelected];
[btn setTitle:@"分享" forState:UIControlStateNormal];
[btn addTarget:self.selectTarget action:@selector(shareHandler:) forControlEvents:UIControlEventTouchUpInside];
}else if (self.buttonType == TabBarCollectType) {
UIImage *btImage = Image(@"tabBarButton/collect.png");
imageSize = btImage.size;
[btn setImage:btImage forState:UIControlStateNormal];
[btn setImage:Image(@"tabBarButton/collect_s.png") forState:UIControlStateHighlighted];
[btn setImage:Image(@"tabBarButton/collect_s.png") forState:UIControlStateSelected];
[btn setTitle:@"收藏" forState:UIControlStateNormal];
[btn addTarget:self.selectTarget action:@selector(collectEvent:) forControlEvents:UIControlEventTouchUpInside];
}else if (self.buttonType == TabBarOKType){
UIImage *btImage = Image(@"tabBarButton/OK.png");
imageSize = btImage.size;
[btn setImage:btImage forState:UIControlStateNormal];
[btn setImage:Image(@"tabBarButton/OK_s.png") forState:UIControlStateHighlighted];
[btn setImage:Image(@"tabBarButton/OK_s.png") forState:UIControlStateSelected];
[btn addTarget:self.selectTarget action:@selector(OKEvent:) forControlEvents:UIControlEventTouchUpInside];
}
}
- (void)layoutSubviews {
[super layoutSubviews];
self.button.frame = self.bounds;
self.button.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 20, 5);
// [self.button setTitleEdgeInsets:UIEdgeInsetsMake(25, 0, 0, 0)];
self.button.titleEdgeInsets = UIEdgeInsetsMake(25, -21, 0, 4);
}
@end
@interface detailContentController ()<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate,UIScrollViewDelegate,RemoteDelegate,videoCellDelegate,ALMoviePlayerControllerDelegate,UIGestureRecognizerDelegate,nodeInfoCellDelegate,hitAnswerDelegate,contentImageDelegate,imageScanerDelegate,TrackCellDelegate,detailPageViewModelDelegate,bannerCellDelgate,strongRelateCountsCellDeleGate,AskIconBaseDelegate,AskContentBaseDelegate,AnswerContentDelegate,AnswerIconBaseDelegate,TPMovieContentDelegate> {
CGFloat contentOffsetY;
CGFloat oldContentOffsetY;
CGFloat newContentOffsetY;
CGFloat lastContentOffsetY;
CGRect videoRect;
BOOL tableSelect;
BOOL isFirstLoad;
BOOL isLoadHeadAdSuccess;
BOOL isLoadAdSuccess;
NSMutableArray *contentHeightList;
NSMutableArray *contentCellList;
CGFloat contentPadding;
CGFloat TEMP_K;
BOOL shouldBack;
}
@property(nonatomic, strong)UIView *tabBar;
@property(nonatomic, strong)UIButton *askAndCommentBtn;
@property(nonatomic, strong)contentObjectBO *contentBO; //内容数据
@property(nonatomic, strong)NSMutableArray *contentDataList;
@property(nonatomic, strong)NSMutableArray *heightOfCellInEachSection; //cell高度数组
@property(nonatomic, strong)videoObjectBO *videoBO;
@property(nonatomic, strong)bannerCell *bannerCell;
@property(nonatomic, strong)contHeadBannerCell *headBannerCell;
@property(nonatomic, assign)BOOL nightTag;
@property(nonatomic, strong)sinaAndWeChatCell *shareCell;
@property(nonatomic, strong)nodeInfoViewCell *nodeInfoCell;
@property(nonatomic, strong)TrackCell *trackCell;
@property(nonatomic, strong)UILabel *backLabel;
@property(nonatomic, strong)UIImageView *backIcon;
@property(nonatomic, strong)UIView *fontShowView;
@property(nonatomic, strong)UILabel *fontShowT;
@property(nonatomic, strong)UILabel *fontShowFont;
@end
@implementation detailContentController
@synthesize detailContentBO = _detailContentBO;
@synthesize contentBO;
@synthesize contentDataList;
@synthesize videoBO;
//@synthesize moviePlayerController;
@synthesize heightOfCellInEachSection;
@synthesize delegate;
@synthesize viewModel;
@synthesize bannerCell;
@synthesize headBannerCell;
@synthesize shareCell;
@synthesize nodeInfoCell;
@synthesize refreshBO = _refreshBO;;
#define BUTTON_SPACE (rect_screen.size.width - 4*35)/5
static NSString *contHeadBannerCellID = @"contHeadBannerCell";
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";
static NSString *trackCellID = @"trackCell";
#pragma mark - load view
- (void)viewDidLoad {
[super viewDidLoad];
isFirstLoad = YES;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
UIPinchGestureRecognizer *zoomGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchHandler:)];
zoomGesture.delaysTouchesBegan = YES;
[self.tableView addGestureRecognizer:zoomGesture];
self.nightTag = NO;
isLoadHeadAdSuccess = NO;
isLoadAdSuccess = NO;
if (IS_IPHONE_6P) {
contentPadding = 15;
}else if (IS_IPHONE_6) {
contentPadding = 15;
}else {
contentPadding = 10;
}
TEMP_K = (rect_screen.size.width-2*contentPadding)/300;
self.viewModel = [detailPageViewModel new];
self.viewModel.delegate = self;
// self.tableView.decelerationRate = 0.3;
self.tableView.backgroundColor = [UIColor colorWithHexString:ContentDetailBack];
[self.tableView registerClass:[contHeadBannerCell class] forCellReuseIdentifier:contHeadBannerCellID];
[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:[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:[TrackCell class] forCellReuseIdentifier:trackCellID];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
int visitNum = [[TPUserDefault instance].visitTime intValue];
if ([TPUserDefault instance].visitTime) {
if ([[TPUserDefault instance].visitTime intValue] >= 0) {
visitNum++;
[TPUserDefault instance].visitTime = [NSString stringWithFormat:@"%d", visitNum];
}
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
}
- (void)addFooterView {
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect_screen.size.width, 50)];
footer.backgroundColor = [UIColor clearColor];
[footer addSubview:self.backLabel];
[footer addSubview:self.backIcon];
[self.backLabel makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(footer);
make.top.equalTo(footer).offset(55/2);
make.size.mas_equalTo(CGSizeMake(100, 20));
}];
[self.backIcon makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backLabel.left).offset(-10);
make.top.equalTo(footer).offset(55/2);
make.size.mas_equalTo(CGSizeMake(20, 20));
}];
footer.alpha = 0.0f;
self.tableView.tableFooterView = footer;
}
- (UIImageView *)backIcon {
if (_backIcon == nil) {
_backIcon = [[UIImageView alloc] initWithFrame:CGRectZero];
_backIcon.image = Image(@"detailPage/detailPageUp.png");
}
return _backIcon;
}
- (UILabel *)backLabel {
if (_backLabel == nil) {
_backLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_backLabel.textColor = [UIColor colorWithHexString:LiveSectionHeaderColor];
_backLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_backLabel.text = @"上拉关闭当前页";
}
return _backLabel;
}
-(UIView *)fontShowView{
if (!_fontShowView) {
_fontShowView = [UILabel new];
_fontShowView.backgroundColor = [UIColor colorWithHexString:@"0x262627"];
_fontShowView.alpha = 0;
}
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;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
tableSelect = NO;
}
- (void) reachabilityChanged:(NSNotification *)note
{
if (self.isOffline) {
return;
}
if (![Remote IsEableNetwork]) {
return;
}
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
[self setDetailContentBO:self.detailContentBO];
}
}
- (void)setRefreshBO:(contentObjectBO *)refresh {
_refreshBO = refresh;
tabBarBtnView *btnView = (tabBarBtnView *)[self.tabBar viewWithTag:TABBARTAG + 2];
if (!isBlankString(self.refreshBO.isFavorited) && [self.refreshBO.isFavorited intValue] == 1 && [TPUserDefault instance].userBO) {
btnView.button.selected = YES;
}else {
btnView.button.selected = NO;
}
tabBarBtnView *OKbtnView = (tabBarBtnView *)[self.tabBar viewWithTag:TABBARTAG + 3];
OKbtnView.text = self.refreshBO.praiseTimes?self.refreshBO.praiseTimes:@"0";
self.nodeInfoCell.nodeInfoBO = setJsonDicToDataModel(self.refreshBO.nodeInfo, [nodeObjectBO class]);
NSDictionary *dic = [[NSDictionary alloc] init];
dic = @{@"content":self.refreshBO.trackKeyword,@"isTrack":self.refreshBO.isTracked};
self.trackCell.dic = dic;
}
- (void)needrefreshNightMode:(id)sender{
self.tableView.backgroundColor = [UIColor colorWithHexString:ContentDetailBack];
self.tabBar.backgroundColor = [UIColor colorWithHexString:ContentDetailBack];
UILabel *commentLabel = (UILabel *)[_askAndCommentBtn viewWithTag:detalLabelTag];
commentLabel.textColor = [UIColor colorWithHexString:TextBlack];
self.nightTag = YES;
UIView *line = [self.tabBar viewWithTag:TABBARTAG + 10086];
line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
_backLabel.textColor = [UIColor colorWithHexString:LiveSectionHeaderColor];
[self setDetailContentBO:self.detailContentBO];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self stopAndRemoveVideo];
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
self.tableView = nil;
self.backLabel.text = @"上拉关闭当前页";
self.backIcon.image = Image(@"detailPage/detailPageUp.png");
shouldBack = NO;
}
- (void)askButtonClick:(UIButton *)btn {
[MobClick event:@"32"];
[self stopAndRemoveVideo];
tabBarBtnView *button = (tabBarBtnView *)[self.tabBar viewWithTag:TABBARTAG+1];
if (button.button.selected) {
[self shareHandler:button.button];
}
if ([self.delegate respondsToSelector:@selector(askButtonClick:)]) {
[self.delegate askButtonClick:btn];
}
}
- (void)setDetailContentBO:(contDetailPageVO *)detailBO {
[[UIApplication sharedApplication]beginIgnoringInteractionEvents];
if (detailBO) {
_detailContentBO = detailBO;
self.viewModel.detailContentBO = detailBO;
self.viewModel.isOffline = self.isOffline;
if (self.contentBO == nil) {
self.contentBO = setJsonDicToDataModel(detailBO.content, [contentObjectBO class]);
}
if (self.contentBO) {
tabBarBtnView *btnView = (tabBarBtnView *)[self.tabBar viewWithTag:TABBARTAG + 2];
if (!isBlankString(self.contentBO.isFavorited) && [self.contentBO.isFavorited intValue] == 1 && [TPUserDefault instance].userBO) {
btnView.button.selected = YES;
}else {
btnView.button.selected = NO;
}
tabBarBtnView *OKbtnView = (tabBarBtnView *)[self.tabBar viewWithTag:TABBARTAG + 3];
OKbtnView.text = self.contentBO.praiseTimes?self.contentBO.praiseTimes:@"0";
/**
* bug:5046(收藏,收藏一条新闻后,回到列表,再进入此新闻,收藏按钮状态是未收藏)
*/
UILabel *commentLabel = (UILabel*)[self.askAndCommentBtn viewWithTag:detalLabelTag];
CGFloat labelWidth = widthForString(contentBO.interactionNum, commentLabel.font, CGRectGetHeight(self.askAndCommentBtn.bounds), NSLineBreakByWordWrapping);
commentLabel.frame = CGRectMake(20, 0, labelWidth, CGRectGetHeight(self.askAndCommentBtn.bounds));
self.askAndCommentBtn.imageEdgeInsets = UIEdgeInsetsMake(CGRectGetHeight(self.askAndCommentBtn.bounds)/2-5, 5, CGRectGetHeight(self.askAndCommentBtn.bounds)/2-5, labelWidth+10);
commentLabel.text = contentBO.interactionNum;
commentLabel.backgroundColor = [UIColor clearColor];
self.contentDataList = [NSMutableArray array];
heightOfCellInEachSection = [NSMutableArray array];
/* 标题 作者 时间 强关系 视频 正文内容 分享 栏目信息 banner 一个section */
NSMutableArray *sectionOneArray = [NSMutableArray array];
NSMutableArray *sectionOneHeightArray = [NSMutableArray array];
contentHeightList = [NSMutableArray array];
contentCellList = [NSMutableArray array];
//banner
if (!self.isOffline) {
[sectionOneArray addObject:@"headBanner"];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
CGFloat headBannerHeight = rect_screen.size.width*120/640;
if (isLoadHeadAdSuccess) {
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",headBannerHeight]];
}else {
[sectionOneHeightArray addObject:@"0"];
}
}
NSAttributedString *attributedTitle = getLineSpaceAttributedString(self.contentBO.name?self.contentBO.name:@"",
[iphoneLineSpaceAndParaSpace returnLevel8LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel8FontSize], NO));
[sectionOneArray addObject:attributedTitle];//标题
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
// CGFloat titleHeight = heightForString(self.contentBO.name, appFont(20, NO),rect_screen.size.width-20 , NSLineBreakByWordWrapping);
// CGFloat titleHeight = heightForAttributeStringWithLabel(attributedTitle, rect_screen.size.width-2*contentPadding, appFont([iphoneLineSpaceAndParaSpace returnLevel8FontSize], NO));
//【需求】支持新闻标题复制(bug:6009)
CGFloat titleHeight = heightForAttributeString(attributedTitle, rect_screen.size.width-2*contentPadding, appFont([iphoneLineSpaceAndParaSpace returnLevel8FontSize], NO));
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",titleHeight+35]]; //标题高度
NSAttributedString *authorAttributedTitle = getLineSpaceAttributedString(self.contentBO.author?self.contentBO.author:@"",
5,
appFont([iphoneLineSpaceAndParaSpace returnLevel1plus5FontSize], NO));
[sectionOneArray addObject:authorAttributedTitle]; //作者
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
CGFloat authorHeight = heightForAttributeStringWithLabel(authorAttributedTitle, rect_screen.size.width-2*contentPadding, appFont([iphoneLineSpaceAndParaSpace returnLevel1plus5FontSize], NO))+5;
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",authorHeight]];
NSString *time = self.contentBO.pubTime?self.contentBO.pubTime:@"";
if (self.contentBO.pubTime) {
NSString *timeStr = self.contentBO.pubTime;
NSDate *date = DateFromString(timeStr, @"yyyy-MM-dd mm:ss");
NSString *timeTextStr = StringFromDate(date, @"YYYY-MM-dd mm:ss");
time = timeTextStr;
if (!isBlankString(timeStr) && isBlankString(timeTextStr)) {
time = timeStr;
}
/**
* bug:6169(离线缓存-新闻详情页:离线缓存的新闻详情页里面没有时间显示)
*/
}else time = @"";
NSAttributedString *pubTimeAttributedTitle = getLineSpaceAttributedString(time,
5,
appFont([iphoneLineSpaceAndParaSpace returnLevel1plus5FontSize], NO));
[sectionOneArray addObject:pubTimeAttributedTitle]; //发表时间
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
CGFloat pubHeight = heightForAttributeStringWithLabel(pubTimeAttributedTitle, rect_screen.size.width-2*contentPadding, appFont([iphoneLineSpaceAndParaSpace returnLevel1plus5FontSize], NO))+10;
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",pubHeight]];
//计算section数量
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]);
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (self.isOffline) {
readmode = imageMode;
}
if (readmode == imageMode) {
[sectionOneArray addObject:listBO];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
NSAttributedString *attriString = getLineSpaceAttributedString(listBO.name,
[iphoneLineSpaceAndParaSpace returnLevel3LineSpace_specialTopic],
appFont(TEXT_FOUR_LEVELSIZE, NO));
CGFloat hei = [self.viewModel returnContentExtendHeight:attriString];
// if ([listBO.watermark intValue] == 1) {
// [sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",150*TEMP_K+hei+20.f]];
// }else {
// [sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",125*TEMP_K+hei+20.f]];
// }
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",125*TEMP_K+hei]];
/**
* bug:5466( 新闻详情页:带有强关系的图片被上下拉长)
*/
}else{
if ([listBO.forwordType integerValue] == imageNewsForwardType) {
}else {
[sectionOneArray addObject:listBO];
NSAttributedString *attriString = getLineSpaceAttributedString(listBO.name,
[iphoneLineSpaceAndParaSpace returnLevel3LineSpace_specialTopic],
appFont(TEXT_FOUR_LEVELSIZE, NO));
CGFloat hei = [self.viewModel returnContentExtendHeight:attriString];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
// if ([listBO.watermark intValue] == 1) {
//
// [sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",150*TEMP_K+hei+20.f]];
// }else {
// [sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",120.f+hei+20.f]];
// }
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",120.f+hei]];
}
}
}];
}
if (!self.isOffline) {
/**
* bug:5135(离线阅读下载到现场直播新闻且点击查看必现闪退)
*/
__block BOOL isHaveVideo = NO;
NSArray *imageList = self.contentBO.images; //视频
__block CGFloat imageHeight = 0;
[imageList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
imageObjectBO *imgBO = setJsonDicToDataModel(obj, [imageObjectBO class]);
if ([imgBO.tags isEqualToString:@"www_video"]) {
[sectionOneArray addObject:imgBO];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
isHaveVideo = YES;
imageHeight = [imgBO.height floatValue]/2*(rect_screen.size.width-2*contentPadding)/([imgBO.width floatValue]/2);
/**
* bug:5278(“中国网民知多少?”这篇文章页面显示错乱)
*/
*stop = YES;
}
}];
NSArray *videoList = self.contentBO.videos;
[videoList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
videoObjectBO *video = setJsonDicToDataModel(obj, [videoObjectBO class]);
CGFloat videoHeight = imageHeight;
// CGFloat videoDescHeight = returnTextHeightWithRTLabel(video.name,
// rect_screen.size.width-20,
// appFont(TEXT_FOUR_LEVELSIZE, NO),
// 5);
NSAttributedString *attriString = getLineSpaceAttributedString(video.name,
[iphoneLineSpaceAndParaSpace returnLevel3LineSpace_specialTopic],
appFont(TEXT_FOUR_LEVELSIZE, NO));
CGFloat videoDescHeight = [self.viewModel returnContentExtendHeight:attriString];
videoHeight = videoHeight + videoDescHeight;
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (self.isOffline) {
readmode = imageMode;
}
if (readmode == imageMode) {
}else{
videoHeight = 120.f + videoDescHeight;
}
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",videoHeight]];
self.videoBO = video;
}];
if (videoList.count == 0 && isHaveVideo) {
[sectionOneHeightArray addObject:@"0"];
/**
* bug:5423(新闻详情页:进入某新闻后,出现提示后卡死)
*/
}
}
NSArray *contentList = self.contentBO.content; //文章详情
NSMutableArray *analysisedContentList = analysisContent(contentList);
[analysisedContentList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[imageObjectBO class]]) {
[sectionOneArray addObject:obj];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
imageObjectBO *imageBO = obj;
NSAttributedString *attriString = getLineSpaceAttributedString(imageBO.desc,
[iphoneLineSpaceAndParaSpace returnLevel3LineSpace_specialTopic],
appFont(TEXT_FOUR_LEVELSIZE, NO));
CGFloat imageExtHeight = [self.viewModel returnContentExtendHeight:attriString];
CGFloat cellHeight = ([imageBO.height floatValue]/2)*rect_screen.size.width/320+imageExtHeight;
if (idx == analysisedContentList.count - 1) {
cellHeight = cellHeight + 15;
/**
* bug:5171(详情页底部的图片和话题卡片重叠)
*/
}
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (self.isOffline) {
readmode = imageMode;
}
if (readmode == imageMode) {
}else{
if (![imageBO.isTap isEqualToString:@"1"]) {
cellHeight = 130.f+imageExtHeight;
}
}
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",cellHeight]];
}else {
NSString *str = obj;
NSMutableAttributedString *attributeStr = [self.viewModel returnContentTextString:str];
CGFloat strHeight = heightForAttributeString(attributeStr, rect_screen.size.width-2*contentPadding+10,appFont([TPUserDefault instance].contFontSize, NO));
CGFloat cellHeight = strHeight+[iphoneLineSpaceAndParaSpace newsColumSpace];
[sectionOneArray addObject:attributeStr];
[contentHeightList addObject:[NSString stringWithFormat:@"%f",strHeight]];
NSInteger count = contentCellList.count;
NSString *textCellID = [NSString stringWithFormat:@"contentTextCell_%ld",(long)count];
[self.tableView registerClass:[contentTextCell class] forCellReuseIdentifier:textCellID];
contentTextCell *cell = (contentTextCell*)[self.tableView dequeueReusableCellWithIdentifier:textCellID];
if (nil == cell) {
cell = [[contentTextCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:contentTextCellID];
}
cell.textHeight = [[NSString stringWithFormat:@"%f",strHeight] floatValue];
// cell.text = attributeStr;
[contentCellList addObject:cell];
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",cellHeight]];
}
}];
if (!self.isOffline) {
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];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
if (idx != reTopics.count -1) {
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",225*(rect_screen.size.width-2*contentPadding)/300 + 20]];
}else{
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",225*(rect_screen.size.width-2*contentPadding)/300 + 35]];
}
}];
}
//分享
self.shareCell = (sinaAndWeChatCell*)[self.tableView dequeueReusableCellWithIdentifier:ShareBtnCellID];
self.shareCell.contentBO = self.contentBO;
[sectionOneArray addObject:@"shareCell"];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
[sectionOneHeightArray addObject:@"50"];
if (!self.isOffline) {
//栏目信息
self.nodeInfoCell = (nodeInfoViewCell*)[self.tableView dequeueReusableCellWithIdentifier:nodeInfoViewCellID];
nodeObjectBO *nodeInfo = setJsonDicToDataModel(self.contentBO.nodeInfo, [nodeObjectBO class]);
self.nodeInfoCell.nodeInfoBO = nodeInfo;
self.nodeInfoCell.delegate = self;
[sectionOneArray addObject:nodeInfo];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
[sectionOneHeightArray addObject:@"40"];
//跟踪
self.trackCell = (TrackCell*)[self.tableView dequeueReusableCellWithIdentifier:trackCellID];
NSDictionary *dic = [[NSDictionary alloc] init];
dic = @{@"content":self.contentBO.trackKeyword,@"isTrack":self.contentBO.isTracked};
[sectionOneArray addObject:dic];
self.trackCell.dic = dic;
self.trackCell.delegate = self;
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
[sectionOneHeightArray addObject:@"70"];
//banner
[sectionOneArray addObject:@"banner"];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
CGFloat bannerHeight = (rect_screen.size.width-2*contentPadding)*100/300+30;
if (isLoadAdSuccess) {
[sectionOneHeightArray addObject:[NSString stringWithFormat:@"%f",bannerHeight]];
}else {
[sectionOneHeightArray addObject:@"0"];
}
//secion1结束
[self.contentDataList addObject:sectionOneArray];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
[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;
}
commentBO.type = @"24";
[qaHeightArray addObject:@"50"];
[qaList addObject:commentBO];
commentObjectVO *comment = setJsonDicToDataModel(dic, [commentObjectVO class]);
comment.type = @"2";
CGFloat askHeight = 15;
int LabelHeigth = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20 Text:comment.content LineSpace:10 ParagraphSpacing:0];
comment.labelHeight = LabelHeigth;
[qaList addObject:comment];
askHeight += LabelHeigth;
[qaHeightArray addObject:[NSString stringWithFormat:@"%f",askHeight]];
// CGFloat titleHeight = 65+returnTextHeightWithRTLabel(commentBO.content,rect_screen.size.width - 20, appFont(15, NO),10); //(姓名+内容高度)
// [qaHeightArray addObject:[NSString stringWithFormat:@"%f", titleHeight]];
if (commentBO.answerList && commentBO.answerList.count > 0) {
commentObjectVO *answerBO = setJsonDicToDataModel(commentBO.answerList[0], [commentObjectVO class]);
answerBO.type = @"34";
[qaHeightArray addObject:@"50"];
[qaList addObject:answerBO];
commentObjectVO *answer = setJsonDicToDataModel(comment.answerList[0], [commentObjectVO class]);
answer.type = @"3";
answer.askCommentBO = comment;
CGFloat anserHeight = 10;
int anserH = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20 Text:answer.content LineSpace:10 ParagraphSpacing:0];
answer.labelHeight = anserH;
[qaList addObject:answer];
if (anserH > getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE)) {
anserH = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE);
anserHeight += 25;
}
anserHeight += anserH;
[qaHeightArray addObject:[NSString stringWithFormat:@"%f",anserHeight]];
// [qaList addObject:answer]; //answerCommentBO
}
}];
if (qaList.count > 0) {
[qaList addObject:@"1"];
[qaHeightArray addObject:@"15"];
[self.contentDataList addObject:qaList];
[heightOfCellInEachSection addObject:qaHeightArray];
}
//相关新闻
NSMutableArray* relateList = [NSMutableArray array];
NSMutableArray* relateHeightArray = [NSMutableArray array];
__block CGFloat relateHeight = 0;
NSArray *relateConts = detailBO.relateConts?detailBO.relateConts:[NSArray array]; //关联文章数据源
[relateConts enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) {
listContObjectVO *listBO = setJsonDicToDataModel(dic, [listContObjectVO class]);
[relateList addObject:listBO];
NSString *name = listBO.name;
CGFloat hei = returnTextHeightWithRTLabel(name, rect_screen.size.width-2*contentPadding, appFont(33.2/2, NO),7)+35;
relateHeight = relateHeight + hei;
[relateHeightArray addObject:[NSString stringWithFormat:@"%f", hei]];
}];
if (relateList.count > 0) {
[self.contentDataList addObject:relateList];
[heightOfCellInEachSection addObject:relateHeightArray];
}
}else {
//secion1结束
[self.contentDataList addObject:sectionOneArray];
[contentHeightList addObject:@"0"];
[contentCellList addObject:@""];
[heightOfCellInEachSection addObject:sectionOneHeightArray];
}
if (!self.isOffline) {
self.bannerCell = (bannerCell*)[self.tableView dequeueReusableCellWithIdentifier:BannerCellID];
self.bannerCell.delegate = self;
self.bannerCell.isHeadCell = NO;
CGFloat scale = (CGFloat)1/3;
self.bannerCell.imageScale = scale;
self.bannerCell.adUrl = self.detailContentBO.adUrl;
self.headBannerCell = (contHeadBannerCell*)[self.tableView dequeueReusableCellWithIdentifier:contHeadBannerCellID];
self.headBannerCell.delegate = self;
self.headBannerCell.isHeadCell = YES;
CGFloat headScale = (CGFloat)120/640;
self.headBannerCell.imageScale = headScale;
self.headBannerCell.adUrl = self.detailContentBO.adUrl2;
}
if (isFirstLoad) {
[self.view addSubview:self.tabBar];
[self addFooterView];
self.tabBar.backgroundColor = [UIColor colorWithHexString:ContentDetailBack];
// [self.naviBar addSubview:self.askAndCommentBtn];
[self.view insertSubview:self.tableView belowSubview:self.tabBar];
[CoreAnimationEffect animationEaseOut:self.view];
isFirstLoad = NO;
}
[self.tableView reloadData];
// if (!self.nightTag) {
// [self.tableView setContentOffset:CGPointZero animated:YES];
// }
/**
* bug:5602( 离线缓存:进入过一篇新闻,返回再进入,会移到顶部)
*/
}
}else {
TPLOG(@"返回数据有误!");
}
[[UIApplication sharedApplication]endIgnoringInteractionEvents];
}
- (UIView*)tabBar {
if (!_tabBar) {
_tabBar = [[UIView alloc]initWithFrame:CGRectMake(0, rect_screen.size.height-45, rect_screen.size.width, 50)];
UIView* lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _tabBar.frame.size.width, 1)];
lineView.tag = TABBARTAG + 10086;
lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[_tabBar addSubview:lineView];
for (int i=0;i<4;i++) {
tabBarBtnView *tabBtnView= (tabBarBtnView*)[_tabBar viewWithTag:TABBARTAG+i];
tabBtnView.contentID = self.contentBO.contId;
if (!tabBtnView) {
switch (i) {
case 0: //发言
tabBtnView = [[tabBarBtnView alloc]initWithFrame:CGRectMake(BUTTON_SPACE+i*(35+BUTTON_SPACE), 1, 35, CGRectGetHeight(_tabBar.bounds)-1)
withButtonType:0 target:self];
[tabBtnView.button addTarget:self action:@selector(askButtonClick:) forControlEvents:UIControlEventTouchUpInside];
break;
case 1: //分享
tabBtnView = [[tabBarBtnView alloc]initWithFrame:CGRectMake(BUTTON_SPACE+i*(35+BUTTON_SPACE), 1, 35, CGRectGetHeight(_tabBar.bounds)-1)
withButtonType:2 target:self];
break;
case 2: //收藏
tabBtnView = [[tabBarBtnView alloc]initWithFrame:CGRectMake(BUTTON_SPACE+i*(35+BUTTON_SPACE), 1, 35, CGRectGetHeight(_tabBar.bounds)-1)
withButtonType:3 target:self];
break;
case 3: //点赞
tabBtnView = [[tabBarBtnView alloc]initWithFrame:CGRectMake(BUTTON_SPACE+i*(35+BUTTON_SPACE), 1, 35, CGRectGetHeight(_tabBar.bounds)-1)
withButtonType:4 target:self];
tabBtnView.text = self.contentBO.praiseTimes?self.contentBO.praiseTimes:@"0";
break;
default:
break;
}
tabBtnView.tag = TABBARTAG + i;
[_tabBar addSubview:tabBtnView];
CGFloat leftPadding = BUTTON_SPACE+i*(35+BUTTON_SPACE);
[tabBtnView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_tabBar.left).offset(leftPadding);
make.top.equalTo(_tabBar.top).offset(1);
make.width.equalTo(@35);
make.bottom.equalTo(_tabBar.bottom);
}];
}
}
}
return _tabBar;
}
- (UIButton *)askAndCommentBtn {
UILabel *commentLabel = (UILabel *)[_askAndCommentBtn viewWithTag:detalLabelTag];
if (!_askAndCommentBtn) {
_askAndCommentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// if (isIOS7) {
// _askAndCommentBtn.frame = CGRectMake(CGRectGetWidth(self.tabBar.bounds)-60, 18, 60, self.barHeight-18);
// }else {
// _askAndCommentBtn.frame = CGRectMake(CGRectGetWidth(self.tabBar.bounds)-60, 0, 60, self.barHeight);
// }
_askAndCommentBtn.backgroundColor = [UIColor clearColor];
[_askAndCommentBtn setImage:Image(@"frontPage/comment_img.png") forState:UIControlStateNormal];
[_askAndCommentBtn addTarget:self action:@selector(pushToCommentHandler:) forControlEvents:UIControlEventTouchUpInside];
if (!commentLabel) {
commentLabel = [[UILabel alloc]initWithFrame:CGRectZero];
commentLabel.textColor = [UIColor colorWithHexString:TextBlack];
commentLabel.textAlignment = NSTextAlignmentCenter;
commentLabel.tag = detalLabelTag;
[_askAndCommentBtn addSubview:commentLabel];
}
}
commentLabel.font = appFont(11, NO);
return _askAndCommentBtn;
}
#pragma mark - pinchhandler
- (void)pinchHandler:(UIPinchGestureRecognizer*)zoom {
[self.view addSubview:self.fontShowView];
[self.fontShowView addSubview:self.fontShowT];
[self.fontShowView addSubview:self.fontShowFont];
[self.fontShowView makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view.centerX);
make.width.mas_equalTo(364/2);
make.centerY.equalTo(self.view.centerY);
make.height.mas_equalTo(205/2);
}];
[self.fontShowT makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.fontShowView.left);
make.width.mas_equalTo(364/2);
make.top.equalTo(self.fontShowView.top).offset(24);
make.height.mas_equalTo(22);
}];
[self.fontShowFont makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.fontShowView.left);
make.width.mas_equalTo(364/2);
make.top.equalTo(self.fontShowView.top).offset(68);
make.height.mas_equalTo(17);
}];
[self.view bringSubviewToFront:self.fontShowView];
UIGestureRecognizerState state = zoom.state;
if (state == UIGestureRecognizerStateBegan) {
}else if (state == UIGestureRecognizerStateChanged) {
// TPLOG(@"%f",zoom.scale);
}else if (state == UIGestureRecognizerStateEnded) {
// TPLOG(@"end scale:%f",zoom.scale);
CGFloat fontSize = [iphoneLineSpaceAndParaSpace resizeDifDeviceFontToStandardFont:[TPUserDefault instance].contFontSize];
fontSize = round(fontSize);
if (zoom.scale > 1) { //放大
if (fontSize ==fontSizeExBig ) {
[self showFont:@"超大号字体" completion:nil];
// [TPUserDefault instance].contFontSize = fontSizeExBig;
return;
}
if (fontSize == fontSizeExSmall) {
[self showFont:@"小号字体" completion:nil];
[TPUserDefault instance].contFontSize = fontSizeSmall;
}else if (fontSize == fontSizeSmall) {
[self showFont:@"标准字体" completion:nil];
[TPUserDefault instance].contFontSize = fontSizeMiddle;
}else if (fontSize == round(fontSizeMiddle)) {
[self showFont:@"大号字体" completion:nil];
[TPUserDefault instance].contFontSize = fontSizeBig;
}else if (fontSize == fontSizeBig) {
[self showFont:@"超大号字体" completion:nil];
[TPUserDefault instance].contFontSize = fontSizeExBig;
}
// [self reloadTableWithFontChange];
}else if (zoom.scale<1){
if (fontSize == fontSizeExSmall) {
[self showFont:@"超小号字体" completion:nil];
// [TPUserDefault instance].contFontSize = fontSizeExSmall;
return;
}
if (fontSize == fontSizeExBig) {
[self showFont:@"大号字体" completion:nil];
[TPUserDefault instance].contFontSize = fontSizeBig;
}else if (fontSize == fontSizeBig) {
[self showFont:@"标准字体" completion:nil];
[TPUserDefault instance].contFontSize = fontSizeMiddle;
}else if (fontSize == round(fontSizeMiddle)) {
[self showFont:@"小号字体" completion:nil];
[TPUserDefault instance].contFontSize = fontSizeSmall;
}else if (fontSize == fontSizeSmall) {
[self showFont:@"超小号字体" completion:nil];
[TPUserDefault instance].contFontSize = fontSizeExSmall;
}
// [self reloadTableWithFontChange];
}
}
}
-(void) showFont:(NSString*)fontSize completion:(void (^ __nullable)(BOOL finished))completion{
dispatch_async(dispatch_get_main_queue(), ^{
self.fontShowFont.text = fontSize;
//【倒退】新闻详情页:新闻详情页中手势切换字体异常,特别是在夜间模式下非常明显(bug:6166)
[self reloadTableWithFontChange];
[UIView animateWithDuration:0.6 animations:^{
[self.fontShowView setAlpha:1];
CGAffineTransform newTRansform = CGAffineTransformMakeScale(1.2, 1.2);
[self.fontShowView setTransform:newTRansform];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 animations:^{
[self.fontShowView setAlpha:0];
CGAffineTransform newTRansform = CGAffineTransformMakeScale(1, 1);
[self.fontShowView setTransform:newTRansform];
[self.fontShowView removeFromSuperview];
} completion:^(BOOL finished) {
if (completion) {
completion(YES);
}
}];
}];
});
}
#pragma mark - fontSize
- (void)reloadTableWithFontChange {
[self setDetailContentBO:self.detailContentBO];
}
#pragma mark - button handler
- (void)pushToCommentHandler:(UIButton*)btn {
if ([delegate conformsToProtocol:@protocol(detailContentDelegate)] &&
[delegate respondsToSelector:@selector(askButtonHandler)]) {
[delegate askButtonHandler];
}
}
- (void)shareHandler:(UIButton*)btn {
[self stopAndRemoveVideo];
if ([self.delegate respondsToSelector:@selector(shareBtnHandler:WithButton:)]) {
[self.delegate shareBtnHandler:self.contentBO WithButton:btn];
}
}
- (void)tapNaviBar:(id)sender {
[self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
}
- (void)backHandler {
if ([delegate conformsToProtocol:@protocol(detailContentDelegate)] &&
[delegate respondsToSelector:@selector(popBackButtonHandler)]) {
[delegate popBackButtonHandler];
}
}
- (void)OKEvent:(UIButton*)btn {
if (btn.selected) {
return;
}
[MobClick event:@"13"];
tabBarBtnView *tabBtnView= (tabBarBtnView*)[_tabBar viewWithTag:TABBARTAG+3];
NSString *str = tabBtnView.text;
if (![str isMatchedByRegex:@"k"]) {
tabBtnView.text = [NSString stringWithFormat:@"%ld",(long)[str intValue]+1];
}
[tabBtnView setSelected:YES animated:YES];
[tabBtnView.button setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal];
[self.viewModel praiseHandler:btn completion:^(BOOL success, NSString *message, id responseData) {
TPLOG(@"点赞成功");
// btn.selected = YES;
}];
}
- (void)collectEvent:(UIButton*)btn {
if (!btn.selected) {
if (![TPUserDefault instance].userBO) {
loginHomeController *vc = loginHomeController.new;
[self stopAndRemoveVideo];
[self.navigationController pushViewController:vc animated:YES];
}else {
[self.viewModel collectContent:^{
btn.selected = YES;
[MobClick event:@"52"];
}];
}
}else {
[self.viewModel cancelCollect:^{
btn.selected = NO;
}];
}
}
- (void)trackEvent:(UIButton*)btn {
if (!btn.selected) {
if (![TPUserDefault instance].userBO) {
loginHomeController *vc = loginHomeController.new;
[self stopAndRemoveVideo];
[self.navigationController pushViewController:vc animated:YES];
}else {
[self.viewModel trackContent:^{
btn.selected = YES;
}];
}
}else {
[self.viewModel cancelTrackContent:^{
btn.selected = NO;
}];
}
}
#pragma mark - trackDelegate
- (void)trackButtonClick:(UIButton *)button {
if (!button.selected) {
if (![TPUserDefault instance].userBO) {
loginHomeController *vc = loginHomeController.new;
[self stopAndRemoveVideo];
[self.navigationController pushViewController:vc animated:YES];
return;
}
[self.viewModel trackContent:^{
button.selected = YES;
self.contentBO.isTracked = @"1";
[MobClick event:@"11"];
}];
}else {
if (![TPUserDefault instance].userBO) {
loginHomeController *vc = loginHomeController.new;
[self stopAndRemoveVideo];
[self.navigationController pushViewController:vc animated:YES];
return;
}
[self.viewModel cancelTrackContent:^{
button.selected = NO;
self.contentBO.isTracked = @"0";
}];
}
}
- (void)orderClick:(UIButton *)btn nodeInfo:(nodeObjectBO *)nodeInfo{
if (btn.selected) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"n":nodeInfo.nodeId,@"oType":@"2"}];
[Remote doJsonActionWithBlock:1 requestUrl:orderNodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
btn.selected = NO;
nodeObjectBO *nodeInfo = setJsonDicToDataModel(self.contentBO.nodeInfo, [nodeObjectBO class]);
nodeInfo.isOrder = @"0";
NSDictionary *dic = setDataModelToDic(nodeInfo, [nodeObjectBO class]);
self.contentBO.nodeInfo = dic;
ShowMessage(@"取消订阅", YES);
[[NSNotificationCenter defaultCenter] postNotificationName:NEEDREFRESHORDER object:nil];
}
}];
}else {
if ([TPUserDefault instance].userBO) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"n":nodeInfo.nodeId,@"oType":@"1"}];
[Remote doJsonActionWithBlock:1 requestUrl:orderNodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
btn.selected = YES;
ShowMessage(@"订阅成功", YES);
nodeObjectBO *nodeInfo = setJsonDicToDataModel(self.contentBO.nodeInfo, [nodeObjectBO class]);
nodeInfo.isOrder = @"1";
NSDictionary *dic = setDataModelToDic(nodeInfo, [nodeObjectBO class]);
self.contentBO.nodeInfo = dic;
[[NSNotificationCenter defaultCenter] postNotificationName:NEEDREFRESHORDER object:nil];
}
}];
}else {
loginHomeController *vc = loginHomeController.new;
[self stopAndRemoveVideo];
[self.navigationController pushViewController:vc animated:YES];
}
}
}
#pragma mark - tableView delegate and dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.contentDataList?self.contentDataList.count:0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.contentDataList.count > 0) {
NSArray *sectionArray = self.contentDataList[section];
return sectionArray.count;
}else return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *heightArray = heightOfCellInEachSection[indexPath.section];
return [heightArray[indexPath.row] floatValue];
}
- (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) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, rect_screen.size.width, 30)];
view.backgroundColor = [UIColor colorWithHexString:CONTENTCELLBACKCOLOR];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(contentPadding, 0, rect_screen.size.width-2*contentPadding, 30)];
label.font = appFont(TEXT_THREE_LEVELSIZE, NO);
label.textColor = [UIColor colorWithHexString:TextGray];
label.backgroundColor = [UIColor colorWithHexString:CONTENTCELLBACKCOLOR];
[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) { //详情内容
NSInteger index = 0;
if (!self.isOffline) {
index = index + 1;
}
if (indexPath.row == index) { //标题
return [self getTitleAndAuthorCell:table cellForRowAtIndexPath:indexPath];
}else if (indexPath.row == index + 1) { //作者
return [self getAurhorCell:table cellForRowAtIndexPath:indexPath];
}else if (indexPath.row == index + 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"]) { //文章视频
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 if ([obj isEqualToString:@"headBanner"]) { //banner
return [self getHeadBannerCell:table cellForRowAtIndexPath:indexPath];
}
}else if([obj isKindOfClass:[NSAttributedString class]]){//文章文字内容
return [self getContentTextCell:table cellForRowAtIndexPath:indexPath];
}else if([obj isKindOfClass:[TopicInfoBO class]]){//【需求】新闻支持强关系话题显示(bug:4324)
return [self getTopicCell:table cellForRowAtIndexPath:indexPath];
}else if([obj isKindOfClass:[nodeObjectBO class]]){ //栏目信息
return [self getNodeInfoViewCell:table cellForRowAtIndexPath:indexPath];
}else if ([obj isKindOfClass:[NSDictionary class]]) {
return [self TrackCell:table cellForRowAtIndexPath:indexPath];
}
}
}else {
NSArray *otherSectionArray = self.contentDataList[indexPath.section];
id obj = otherSectionArray[indexPath.row];
if ([obj isKindOfClass:[commentObjectVO class]]) { //热追问
commentObjectVO *commentBO = obj;
switch ([commentBO.type integerValue]) {
case 2://提问
return [self returnAskContentTable:table cellForRowAtIndexPath:indexPath];
break;
case 3://回答
return [self returnAnswerContentTableTable:table cellForRowAtIndexPath:indexPath];
break;
case 24://提问头像
return [self returnAskIconTable:table cellForRowAtIndexPath:indexPath];
break;
case 34://回答头像
return [self returnAnswerIconTable:table cellForRowAtIndexPath:indexPath];
break;
// case 5://图片
// return [self returnAnswerPicTable:tableView cellForRowAtIndexPath:indexPath];
// break;
default:
break;
}
}else if ([obj isKindOfClass:[NSString class]] && [obj isEqualToString:@"1"]) { //foot
return [self getSectionFoot:table cellForRowAtIndexPath:indexPath];
}else { //继续阅读
return [self getRelateNewCell:table cellForRowAtIndexPath:indexPath];
}
} return nil;
}
- (titleAndAuthorCell*)getTitleAndAuthorCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
titleAndAuthorCell *cell = (titleAndAuthorCell*)[tableView dequeueReusableCellWithIdentifier:titleAndAuthorCellID];
if (nil == cell) {
cell = [[titleAndAuthorCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:titleAndAuthorCellID];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
// CGFloat titleHeight = heightForAttributeStringWithLabel(contentSectionList[indexPath.row], rect_screen.size.width-2*contentPadding, appFont([iphoneLineSpaceAndParaSpace returnLevel8FontSize], NO));
//【需求】支持新闻标题复制(bug:6009)
CGFloat titleHeight = heightForAttributeString(contentSectionList[indexPath.row], rect_screen.size.width-2*contentPadding, appFont([iphoneLineSpaceAndParaSpace returnLevel8FontSize], NO));
cell.titleLabelHeight = titleHeight;
cell.contentTitle = contentSectionList[indexPath.row];
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;
}
- (authorAndTimeCell*)getAurhorCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// static NSString *cellID = @"AurhorCell";
authorAndTimeCell *cell = (authorAndTimeCell*)[tableView dequeueReusableCellWithIdentifier:authorAndTimeCellID];
if (nil == cell) {
cell = [[authorAndTimeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:authorAndTimeCellID];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
cell.text = contentSectionList[indexPath.row];
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];
}
NSArray *contentSectionList = self.contentDataList[indexPath.section];
cell.text = contentSectionList[indexPath.row];
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;
cell.delegate = self;
cell.indexPath = indexPath;
return cell;
}
- (void)clickLoadImageWithListCont:(listContObjectVO *)imageBo Cell:(strongRelateCountsCell *)cell {
CGFloat backY = [cell.noImageButton convertRect:cell.noImageButton.bounds toView:KEY_WINDOW].origin.y-64;
NSMutableArray *contentSectionList = self.contentDataList[cell.indexPath.section];
imageBo.isTap = @"1";
cell.listdataBO = imageBo;
CGFloat cellHeight = 0;
NSMutableArray *heightarray = self.heightOfCellInEachSection[cell.indexPath.section];
CGFloat hei = returnTextHeightWithRTLabel(imageBo.name, rect_screen.size.width-2*contentPadding, appFont(TEXT_FOUR_LEVELSIZE, NO), 5);
cellHeight = 125*TEMP_K+20.f+hei;
[heightarray replaceObjectAtIndex:cell.indexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
[contentSectionList replaceObjectAtIndex:cell.indexPath.row withObject:imageBo];
[self.contentDataList replaceObjectAtIndex:cell.indexPath.section withObject:contentSectionList];
[self.heightOfCellInEachSection replaceObjectAtIndex:cell.indexPath.section withObject:heightarray];
NSArray *array = @[cell.indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
if (backY < 0) {
[self.tableView beginUpdates];
[self.tableView scrollToRowAtIndexPath:cell.indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
[self.tableView endUpdates];
}
});
}
- (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;
cell.indexPath = indexPath;
return cell;
}
- (void)clickLoadImageWith:(imageObjectBO *)imageBo Cell:(cntentImageCell *)cell {
NSMutableArray *contentSectionList = self.contentDataList[cell.indexPath.section];
imageBo.isTap = @"1";
cell.imageBO = imageBo;
CGFloat backY = [cell.noImageButton convertRect:cell.noImageButton.bounds toView:KEY_WINDOW].origin.y-64;
NSMutableArray *heightarray = self.heightOfCellInEachSection[cell.indexPath.section];
CGFloat cellHeight = [imageBo.height floatValue]*.5*rect_screen.size.width/320+10;
NSAttributedString *attriString = getLineSpaceAttributedString(imageBo.desc,
[iphoneLineSpaceAndParaSpace returnLevel3LineSpace_specialTopic],
appFont(TEXT_FOUR_LEVELSIZE, NO));
CGFloat imageExtHeight = [self.viewModel returnContentExtendHeight:attriString];
cellHeight = cellHeight + imageExtHeight;
[heightarray replaceObjectAtIndex:cell.indexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
[contentSectionList replaceObjectAtIndex:cell.indexPath.row withObject:imageBo];
[self.contentDataList replaceObjectAtIndex:cell.indexPath.section withObject:contentSectionList];
[self.heightOfCellInEachSection replaceObjectAtIndex:cell.indexPath.section withObject:heightarray];
NSArray *array = @[cell.indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
if (backY < 0) {
[self.tableView beginUpdates];
[self.tableView scrollToRowAtIndexPath:cell.indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
[self.tableView endUpdates];
}
});
}
- (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;
}
- (void)clickLoadVideoWith:(videoObjectBO *)imageBo Cell:(videoCell *)cell {
CGFloat backY = [cell.noImageButton convertRect:cell.noImageButton.bounds toView:KEY_WINDOW].origin.y-64;
NSMutableArray *contentSectionList = self.contentDataList[cell.indexPath.section];
videoObjectBO *video = imageBo;
videoBO.isTap = @"1";
imageObjectBO *image = cell.imageBO;
image.isTap = @"1";
cell.imageBO = image;
self.videoBO = video;
cell.videoBO = video;
/**
* bug:5074(视频的无图模式点击后应该先出来一个视频图)
*/
CGFloat imageHeight = [image.height floatValue]/2*(rect_screen.size.width-2*contentPadding)/([image.width floatValue]/2);
CGFloat videoHeight = imageHeight;
NSAttributedString *attriString = getLineSpaceAttributedString(video.name,
[iphoneLineSpaceAndParaSpace returnLevel3LineSpace_specialTopic],
appFont(TEXT_FOUR_LEVELSIZE, NO));
CGFloat videoDescHeight = [self.viewModel returnContentExtendHeight:attriString];
videoHeight = videoHeight + videoDescHeight;
NSMutableArray *heightarray = self.heightOfCellInEachSection[cell.indexPath.section];
[heightarray replaceObjectAtIndex:cell.indexPath.row withObject:[NSString stringWithFormat:@"%f",videoHeight]];
[contentSectionList replaceObjectAtIndex:cell.indexPath.row withObject:image];
[self.contentDataList replaceObjectAtIndex:cell.indexPath.section withObject:contentSectionList];
[self.heightOfCellInEachSection replaceObjectAtIndex:cell.indexPath.section withObject:heightarray];
NSArray *array = @[cell.indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
if (backY < 0) {
[self.tableView beginUpdates];
[self.tableView scrollToRowAtIndexPath:cell.indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
[self.tableView endUpdates];
}
});
}
- (contentTextCell*)getContentTextCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
contentTextCell *cell = contentCellList[indexPath.row];
NSArray *contentSectionList = self.contentDataList[indexPath.section];
id obj = contentSectionList[indexPath.row];
cell.text = obj;
return cell;
}
- (sinaAndWeChatCell*)getShareBtnCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.shareCell;
}
- (bannerCell*)getBannerCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
self.bannerCell.indexPath = indexPath;
return self.bannerCell;
}
- (contHeadBannerCell*)getHeadBannerCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
self.headBannerCell.indexPath = indexPath;
return self.headBannerCell;
}
- (nodeInfoViewCell*)getNodeInfoViewCell:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.nodeInfoCell;
}
- (TrackCell *)TrackCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.trackCell;
}
- (relateNewCell*)getRelateNewCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
relateNewCell *cell = (relateNewCell*)[tableView dequeueReusableCellWithIdentifier:relateNewCellID];
if (nil == cell) {
cell = [[relateNewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:relateNewCellID];
}
NSArray *otherSectionArray = self.contentDataList[indexPath.section];
id obj = otherSectionArray[indexPath.row];
cell.listBO = obj;
return cell;
}
//回答详情
- (UITableViewCell*)getSectionFoot:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"sectionFoot";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (nil == cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSArray *otherSectionArray = self.contentDataList[indexPath.section];
id obj = otherSectionArray[indexPath.row];
if (indexPath.section != 0) {
if ([obj isKindOfClass:[listContObjectVO class]]) {
[MobClick event:@"49"];
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
// if (self.moviePlayerController) {
// [self stopAndRemoveVideo];
// }
if ([self.delegate respondsToSelector:@selector(didEndPlayVedio)]) {
[self.delegate didEndPlayVedio];
}
if (self.isOffline) {
readmode = imageMode;
}
tableSelect = YES;
pushContentWithListContentObject(self.navigationController, obj);
}
}else {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[strongRelateCountsCell class]]) {
// if (self.moviePlayerController) {
// [self stopAndRemoveVideo];
// }
if ([self.delegate respondsToSelector:@selector(didEndPlayVedio)]) {
[self.delegate didEndPlayVedio];
}
pushContentWithListContentObject(self.navigationController, obj);
}else if ([cell isKindOfClass:[reTopicCell class]]) {
[MobClick event:@"61"];
topicContentController *topic = [topicContentController new];
topic.preTopicInfo = obj;
// if (self.moviePlayerController) {
// [self stopAndRemoveVideo];
// }
if ([self.delegate respondsToSelector:@selector(didEndPlayVedio)]) {
[self.delegate didEndPlayVedio];
}
[self.navigationController pushViewController:topic animated:YES];
}
}
});
}
#pragma mark - cell delegate
- (void)goToNodeListPage:(nodeObjectBO *)nodeBO {
columnManagerController *vc = columnManagerController.new;
[self.navigationController pushViewController:vc animated:YES];
vc.nodeBO = nodeBO;
[self stopAndRemoveVideo];
}
- (void)praiseHandlerWithIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *index = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:indexPath.section];
AnswerIconBaseCell *cell = (AnswerIconBaseCell *)[self.tableView cellForRowAtIndexPath:index];
[cell commentOK:cell.OkButton];
if (cell == nil) {
NSMutableArray *otherSectionArray = self.contentDataList[index.section];
commentObjectVO *obj = otherSectionArray[index.row];
NSDictionary *dic = @{@"commentId":obj.commentId};
if (obj.isPraised.intValue == 1) {
return;
}
[Remote doJsonActionWithBlock:2000 requestUrl:commentPraiseURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
[MobClick event:@"24"];
if ([responseData[@"praiseTimes"] integerValue] < 1001) {
NSString *praseNum = [NSString stringWithFormat:@"%@",responseData[@"praiseTimes"]];
obj.praiseTimes = praseNum;
TPLOG(@"点赞成功");
}
obj.isPraised = @"1";
TPLOG(@"点赞成功");
}else {
TPLOG(@"点赞失败");
}
}];
}
// [otherSectionArray replaceObjectAtIndex:indexPath.row withObject:comment];
}
- (void)tapNodeSporWithNodeInfo:(nodeObjectBO *)node {
[self stopAndRemoveVideo];
sponsorBO *sponsor = setJsonDicToDataModel(node.sponsor, [sponsorBO class]);
if (isBlankString(sponsor.link)) {
return;
}
TPWebViewContoller *webVC = [[TPWebViewContoller alloc]init];
[self stopAndRemoveVideo];
[self.navigationController pushViewController:webVC animated:YES];
webVC.url = sponsor.link;
/**
* bug:5299(新闻详情页点击跟踪栏中的栏目冠名无效)
*/
}
- (void)clickImage:(imageObjectBO *)imageBO withImageView:(UIImageView *)imageView {
[self stopAndRemoveVideo];
/**
* bug:5097( 新闻中点击播放视频,再点击其他图片,新闻...视频仍在继续播放)
*/
((MLNavigationController *)self.navigationController).canDragBack = NO;
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:imageBO.url]) {
currentIndex = idx;
}
}];
TPImageScannerController *imageScanner = [[TPImageScannerController alloc]init];
[self.navigationController pushViewController:imageScanner animated:NO];
[UIView transitionWithView:self.navigationController.view duration:0.35f options:UIViewAnimationOptionTransitionFlipFromLeft animations:nil completion:^(BOOL finished) {
imageScanner.currentIndex = currentIndex;
imageScanner.imageBOList = imageBOArray;
imageScanner.type = contentImageScannerType;
imageScanner.delegate = self;
}];
// [CoreAnimationEffect animationEaseIn:self.navigationController.view];
}
- (AskContentBaseCell *)returnAskContentTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AskContentBaseCellId";
AskContentBaseCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AskContentBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSArray *otherSectionArray = self.contentDataList[index.section];
id obj = otherSectionArray[index.row];
cell.commentBO = obj;
cell.delegate = self;
return cell;
}
- (AskIconBaseCell *)returnAskIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AskIconBaseCellId";
AskIconBaseCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AskIconBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSArray *otherSectionArray = self.contentDataList[index.section];
id obj = otherSectionArray[index.row];
cell.commentBO = obj;
cell.delegate = self;
return cell;
}
- (AnswerIconBaseCell *)returnAnswerIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AnswerIconBaseCellId";
AnswerIconBaseCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AnswerIconBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSArray *otherSectionArray = self.contentDataList[index.section];
id obj = otherSectionArray[index.row];
cell.commentBO = obj;
cell.delegate = self;
return cell;
}
- (AnswerContentBaseCell *)returnAnswerContentTableTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AnswerContentBaseCellId";
AnswerContentBaseCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AnswerContentBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSArray *otherSectionArray = self.contentDataList[index.section];
id obj = otherSectionArray[index.row];
cell.shouldNoHiddenLine = @"1";
cell.commentBO = obj;
cell.indexPath = index;
cell.delegate = self;
__block NSIndexPath *IndexPath = index;
__weak typeof(self) Self = self;
[cell expandCell:^(BOOL isExpand, CGFloat cellHeight) {
CGFloat backY = [cell.aswerContentLabel convertRect:cell.aswerContentLabel.bounds toView:KEY_WINDOW].origin.y-64;
if (isExpand) {
cellHeight = cellHeight+25 + 10;
NSMutableArray *heightarray = Self.heightOfCellInEachSection[IndexPath.section];
[heightarray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
[Self.heightOfCellInEachSection replaceObjectAtIndex:IndexPath.section withObject:heightarray];
NSArray *array = @[IndexPath];
[Self.tableView beginUpdates];
[Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[Self.tableView endUpdates];
}else {
cellHeight = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE)+25+10;
NSMutableArray *heightarray = Self.heightOfCellInEachSection[IndexPath.section];
[heightarray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
[Self.heightOfCellInEachSection replaceObjectAtIndex:IndexPath.section withObject:heightarray];
NSArray *array = @[IndexPath];
[Self.tableView beginUpdates];
[Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[Self.tableView endUpdates];
if (backY < 0) {
[Self.tableView beginUpdates];
[Self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
[Self.tableView endUpdates];
}
}
}];
return cell;
}
- (CGRect)getRectFromScrollView:(UIImage *)img {
CGSize imgSize= img.size;
CGSize scaledSize = imgSize;
if (imgSize.width > imgSize.height) {
scaledSize.width = self.view.bounds.size.width;
CGFloat scale = imgSize.width/imgSize.height;
scaledSize.height = self.view.bounds.size.width/scale;
if (scaledSize.height>self.view.bounds.size.height) {
scaledSize.height = self.view.bounds.size.height;
scaledSize.width = self.view.bounds.size.height*scale;
}
}else {
scaledSize.height = self.view.bounds.size.height;
CGFloat scale = imgSize.height/imgSize.width;
scaledSize.width = self.view.bounds.size.height/scale;
if (scaledSize.width>self.view.bounds.size.width) {
scaledSize.width = self.view.bounds.size.width;
scaledSize.height = self.view.bounds.size.width*scale;
}
}
return CGRectMake((self.view.frame.size.width - scaledSize.width)/2, (self.view.frame.size.height - scaledSize.height)/2, scaledSize.width, scaledSize.height);
}
- (void)imageContentClick:(imageObjectBO*)imageBO {
[MobClick event:@"10"];
((MLNavigationController *)self.navigationController).canDragBack = YES;
[self.navigationController popViewControllerAnimated:NO];
[UIView transitionWithView:self.navigationController.view duration:0.35f options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:nil];
}
- (void)goToAskDetailPage:(commentObjectVO *)commentBO {
askDetailController *vc = askDetailController.new;
vc.commentBO = commentBO;
[self stopAndRemoveVideo];
[self.navigationController pushViewController:vc animated:YES];
[self stopAndRemoveVideo];
}
- (void)loadAdFailed:(NSIndexPath *)indexPath isHeadCell:(BOOL)isHeadCell{
}
- (void)loadAdSuccess:(NSIndexPath *)indexPath isHeadCell:(BOOL)isHeadCell{
dispatch_async(dispatch_get_main_queue(), ^{
if (isHeadCell) {
isLoadHeadAdSuccess = YES;
CGFloat headBannerHeight = rect_screen.size.width*120/640;
NSMutableArray *list = self.heightOfCellInEachSection[0];
[list replaceObjectAtIndex:0 withObject:[NSString stringWithFormat:@"%f",headBannerHeight]];
[self.heightOfCellInEachSection replaceObjectAtIndex:0 withObject:list];
[self.tableView reloadData];
}else {
isLoadAdSuccess = YES;
NSMutableArray *list = self.heightOfCellInEachSection[0];
[list removeLastObject];
CGFloat bannerHeight = (rect_screen.size.width-2*contentPadding)*100/300+30;
[list addObject:[NSString stringWithFormat:@"%f",bannerHeight]];
[self.heightOfCellInEachSection replaceObjectAtIndex:0 withObject:list];
[self.tableView reloadData];
}
});
}
- (void)clickAdd:(remotePushBO *)pushBO indexPath:(NSIndexPath *)indexPath{
[TPUserDefault instance].pushBO = pushBO;
}
#pragma mark - scrollerView delegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
contentOffsetY = scrollView.contentOffset.y;
self.tableView.tableFooterView.alpha = 1.f;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (tableSelect) {
return;
}
scrollView.contentInset = UIEdgeInsetsZero;
scrollView.scrollIndicatorInsets = UIEdgeInsetsZero;
newContentOffsetY = scrollView.contentOffset.y;
if (newContentOffsetY > scrollView.contentSize.height-rect_screen.size.height + 150 && scrollView.contentSize.height >0 ) {
self.backLabel.text = @"释放关闭当前页";
self.backIcon.image = Image(@"detailPage/detailPageBack.png");
shouldBack = YES;
}else {
self.backLabel.text = @"上拉关闭当前页";
self.backIcon.image = Image(@"detailPage/detailPageUp.png");
shouldBack = NO;
}
CGRect frame = scrollView.frame;
//根据触摸相对位置做判断
if (newContentOffsetY > lastContentOffsetY && scrollView.dragging) { // 向上滚动
if (newContentOffsetY >0)
{
[UIView animateWithDuration:0.2 animations:^{
CGRect tabFrame = self.tabBar.frame;
if (tabFrame.origin.y != CGRectGetHeight(self.view.bounds)) {
tabFrame.origin.y = CGRectGetHeight(self.view.bounds);
}
self.tabBar.frame = tabFrame;
} completion:^(BOOL finished) {
}];
}
} else if (newContentOffsetY < lastContentOffsetY && scrollView.dragging) { // 向下滚动
if (newContentOffsetY >= scrollView.contentSize.height - frame.size.height)
{
}else {
[UIView animateWithDuration:0.2 animations:^{
CGRect tabFrame = self.tabBar.frame;
if (tabFrame.origin.y != CGRectGetHeight(self.view.bounds)-45) {
tabFrame.origin.y = CGRectGetHeight(self.view.bounds)-45;
}
self.tabBar.frame = tabFrame;
} completion:^(BOOL finished) {
}];
}
if (self.isOffline) {
if (newContentOffsetY<0 && lastContentOffsetY <= 0) {
[UIView animateWithDuration:0.2 animations:^{
CGRect tabFrame = self.tabBar.frame;
if (tabFrame.origin.y != CGRectGetHeight(self.view.bounds)-45) {
tabFrame.origin.y = CGRectGetHeight(self.view.bounds)-45;
}
self.tabBar.frame = tabFrame;
} completion:^(BOOL finished) {
}];
/**
* bug:5428(离线缓存新闻:离线缓存中只有一页内容的新闻,上拉后下方按钮消失)
*/
}
}
}
lastContentOffsetY = scrollView.contentOffset.y;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
oldContentOffsetY = scrollView.contentOffset.y;
self.view.center = KEY_WINDOW.center;
if (shouldBack) {
if ([self.delegate respondsToSelector:@selector(dismissSelfView)]) {
[self.delegate dismissSelfView];
}
}
}
#pragma mark - video play
- (void)clickToPlayVideo:(CGRect)videoFrame indexPath:(NSIndexPath *)indexPath imageSize:(CGSize)imageSize{
if (self.moviePlayerController) {
return;
}
[MobClick event:@"9"];
if ([self.delegate respondsToSelector:@selector(didPlayVedio)]) {
[self.delegate didPlayVedio];
}
((MLNavigationController *)self.navigationController).canDragBack = NO;
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:0.3 animations:^{
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
CGFloat offset = videoFrame.size.height - imageSize.height;
CGPoint contentOffset = self.tableView.contentOffset;
contentOffset.y = contentOffset.y - offset;
[self.tableView setContentOffset:contentOffset animated:NO];
} completion:^(BOOL finished) {
CGFloat videoHeight = videoFrame.size.height;
videoRect = CGRectMake(0, NAVBAR_HEIGHT, CGRectGetWidth(self.view.bounds), videoHeight);
// self.moviePlayerController = [[TPMovieContent alloc] initWithFrame:videoRect contentUrl:[NSURL URLWithString:self.videoBO.url]];
NSMutableDictionary *urlDic = [NSMutableDictionary dictionary];
[urlDic setObject:@"http://video.thepaper.cn/video/0/9/139.mp4" forKey:@"standard"];
[urlDic setObject:@"http://video.thepaper.cn/video/0/9/140.mp4" forKey:@"high"];
self.moviePlayerController = [[TPMovieContent alloc] initWithFrame:videoRect contentUrlDic:urlDic];
self.moviePlayerController.delegate = self;
[KEY_WINDOW addSubview:self.moviePlayerController.view];
[self.moviePlayerController relayoutSubViewForScreen:videoRect fullScreen:NO];
}];
}
- (void)playFinish {
UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (currentOrientation != UIInterfaceOrientationPortrait) {
[[UIApplication sharedApplication]
setStatusBarOrientation:UIInterfaceOrientationPortrait
animated:NO];
[[UIDevice currentDevice]
setValue:[NSNumber
numberWithInteger:UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
[self stopAndRemoveVideo];
if ([self.delegate respondsToSelector:@selector(didEndPlayVedio)]) {
[self.delegate didEndPlayVedio];
}
[(TPWindow*)KEY_WINDOW enabelEmbeddedVideoGesture:NO withVideoController:nil embeddedRect:CGRectZero];
}
- (void)turnMovieViewToPortrait {
[self.moviePlayerController relayoutSubViewForScreen:self.moviePlayerController.originRect fullScreen:NO];
}
- (void)stopAndRemoveVideo {
[self.moviePlayerController.view removeFromSuperview];
[self.moviePlayerController selfDealloc];
self.moviePlayerController = nil;
self.moviePlayerController.view = nil;
((MLNavigationController *)self.navigationController).canDragBack = YES;
if ([self.delegate respondsToSelector:@selector(didEndPlayVedio)]) {
[self.delegate didEndPlayVedio];
}
}
- (void)moviePlayerWillMoveFromWindow {
// if (![self.view.subviews containsObject:self.moviePlayerController.view]) {
// UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
// if (currentOrientation != UIInterfaceOrientationPortrait) {
// [[UIApplication sharedApplication]
// setStatusBarOrientation:UIInterfaceOrientationPortrait
// animated:NO];
//
// [[UIDevice currentDevice]
// setValue:[NSNumber
// numberWithInteger:UIInterfaceOrientationPortrait]
// forKey:@"orientation"];
// }
// [self.view addSubview:self.moviePlayerController.view];
// [self.moviePlayerController setFrame:videoRect];
// self.moviePlayerController.controls.cutPhotoBtn.hidden = YES;
// self.moviePlayerController.controls.fullscreenButton.selected = NO;
// }
}
- (void)turnToright {
[[UIApplication sharedApplication]
setStatusBarOrientation:UIInterfaceOrientationLandscapeRight
animated:NO];
[[UIDevice currentDevice]
setValue:[NSNumber
numberWithInteger:UIInterfaceOrientationLandscapeRight]
forKey:@"orientation"];
}
- (void)turnToPortrait {
[[UIApplication sharedApplication]
setStatusBarOrientation:UIInterfaceOrientationPortrait
animated:NO];
[[UIDevice currentDevice]
setValue:[NSNumber
numberWithInteger:UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
- (void)enterFullScreen:(BOOL)isEnter {
if (isEnter) {
[self turnToPortrait];
}else {
[self turnToright];
}
if ([delegate conformsToProtocol:@protocol(detailContentDelegate)] &&
[delegate respondsToSelector:@selector(videoEnterFullScreen:)]) {
[delegate videoEnterFullScreen:!isEnter];
}
}
- (void)movieTimedOut {
// [self stopAndRemoveVideo];
}
#pragma mark - anserDelegate
- (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)askIconBaseGotoUserInfo:(commentObjectVO *)comment {
[self gotoUserInfo:comment];
}
- (void)askIconBaseGotoHotAsk:(commentObjectVO *)comment {
[self gotoHotAsk:comment];
}
- (void)gotoHotAskWithCommentVO:(commentObjectVO *)comment {
[self gotoHotAsk:comment];
}
#pragma mark - askDelegate
-(void)gotoUserInfo:(commentObjectVO *)comment{
if (![comment.userInfo[@"userId"] isEqualToString:[TPUserDefault instance].userBO.userId]) {
myDynamicController *dynamicVC = [myDynamicController new];
dynamicVC.comment = comment;
[self stopAndRemoveVideo];
if ([self.delegate respondsToSelector:@selector(didEndPlayVedio)]) {
[self.delegate didEndPlayVedio];
}
[self.navigationController pushViewController:dynamicVC animated:YES];
}else{
}
}
- (void)gotoHotAsk:(commentObjectVO *)comment {
askDetailController *hotAskVC = [[askDetailController alloc]init];
hotAskVC.commentBO = comment;
[self stopAndRemoveVideo];
[self.navigationController pushViewController:hotAskVC animated:YES];
}
#pragma mark --------- gotoshare
-(void)gotoShare:(commentObjectVO *)comment index:(NSIndexPath *)index{
ImageShareController *imageShareController = [ImageShareController new];
imageShareController.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
NSString *topTitle;
if ([comment.objectType intValue] == 3) {
topTitle = [NSString stringWithFormat:@"话题:%@",comment.askCommentBO.contName];
}else{
topTitle = [NSString stringWithFormat:@"原新闻:%@",comment.askCommentBO.contName];
}
CGFloat topicHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 3, appFont(TEXT_SIX_LEVELSIZE, NO)), 160, appFont(TEXT_SIX_LEVELSIZE, NO));
int askHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FIVE_LEVELSIZE, NO) Width:170 Text:comment.askCommentBO.content LineSpace:6 ParagraphSpacing:0];
CGFloat answerHieght = heightForAttributeStringWithLabel(getLineSpaceAttributedString(comment.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO));
imageShareController.frame = CGRectMake(0, 0, 240, 340+topicHeight+askHeight+answerHieght);
[imageShareController setAskData:comment.askCommentBO answerData:comment hostId:nil topStr:comment.askCommentBO.contName topHeight:topicHeight askStr:comment.askCommentBO.content askHeight:askHeight answerStr:comment.content answerHeight:answerHieght];
UIImage* img = [self capture:imageShareController];
if (!img) {
ShowTextMessage(@"图片未完成");
return;
}
// UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
contentObjectBO *detailBO = [contentObjectBO new];
detailBO.name = comment.askCommentBO.contName;
detailBO.summary = comment.content;
detailBO.shareUrl = comment.askCommentBO.objInfo[@"shareUrl"];
if ([self.delegate respondsToSelector:@selector(detailToShare:contentBO:)]) {
[self.delegate detailToShare:img contentBO:detailBO];
}
// }
}
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
NSString *msg = nil ;
ShowTextMessage(msg);
}
- (UIImage *)capture:(ImageShareController*)view
{
if ([view isKindOfClass:[UIImageView class]]) {
return ((UIImageView*)view).image;
}
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (void)closeHandler {
UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (currentOrientation != UIInterfaceOrientationPortrait) {
[[UIApplication sharedApplication]
setStatusBarOrientation:UIInterfaceOrientationPortrait
animated:NO];
[[UIDevice currentDevice]
setValue:[NSNumber
numberWithInteger:UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
if (self.moviePlayerController.isEmbedded) {
if ([self.delegate respondsToSelector:@selector(videoClosedWithEmbeddedFullScrrenn)]) {
[self.delegate videoClosedWithEmbeddedFullScrrenn];
}
}
[self stopAndRemoveVideo];
[(TPWindow*)KEY_WINDOW enabelEmbeddedVideoGesture:NO withVideoController:nil embeddedRect:CGRectZero];
}
- (void)refreshPage {
if ([self.delegate respondsToSelector:@selector(needRefreshPage)]) {
[self.delegate needRefreshPage];
}
}
//- (void)dealloc {
// self.tableView = nil;
//}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
|