|
//
// specialTopicTableController.m
// ThePaperDemo
//
// Created by zhousan on 15/7/15.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "specialTopicTableController.h"
#import "topicCoverFlowCell.h"
#import "specialTopicHeadCell.h"
#import "sepicalLiveCell.h"
#import "AskIconBaseCell.h"
#import "AskContentBaseCell.h"
#import "AnswerContentBaseCell.h"
#import "AnswerIconBaseCell.h"
#import "TPLiveHomeController.h"
#import "specialContentCell.h"
#import "TPImageBaseView.h"
#import "topicMoreInfoController.h"
#import "askDetailController.h"
#import "ImageSpecialCell.h"
#import "VedioSpecialCell.h"
#import "myDynamicController.h"
#import "Reachability.h"
#import "UIScrollView+PullScale.h"
#import "ImageShareController.h"
#import "SDWebImageManager.h"
#define IMAGE_SIZE_HEIGHT 125*(rect_screen.size.width-20)/300
#define MOREBUTTONTAG 1300
#define kPullHeightSpacial 85*rect_screen.size.width/320
#define tableSectionHeaderId @"tableSectionHeaderId"
@interface HeaderView : UITableViewHeaderFooterView
@end
@implementation HeaderView
@end
@interface specialTopicTableController () <AskIconBaseDelegate,AskContentBaseDelegate,AnswerContentDelegate,AnswerIconBaseDelegate,topicCoverFlowDelegate> {
NSMutableArray *heightListOfCellInSections;
specialObjectBO *specialBo;
}
@property(nonatomic, strong)NSMutableArray *dataSourceList;
@end
@implementation specialTopicTableController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.clipsToBounds = YES;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// self.tableView.contentInset = UIEdgeInsetsZero;
self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
int readmode = [[TPUserDefault instance].readModeStr intValue];
[self.tableView registerClass:[HeaderView class] forHeaderFooterViewReuseIdentifier:tableSectionHeaderId];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
[self.tableView addPullScaleFuncInVC:self imageUrl:specialBo.pic originalHeight:kPullHeightSpacial hasNavBar:NO];
[self.tableView setHeaderViewInsets:UIEdgeInsetsMake(-kPullHeightSpacial, 0, 0, 0)];
}else {
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
}
- (void)needrefreshNightMode:(id)sender{
self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self.tableView reloadData];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
topicCoverFlowCell *cell = [self.tableView viewWithTag:10086];
[cell selfDealloc];
}
- (void) reachabilityChanged:(NSNotification *)note
{
[self setDataList:self.dataList];
}
- (void)setImageV {
SDWebImageManager *loader = [[SDWebImageManager alloc] init];
[loader downloadImageWithURL:[NSURL URLWithString:specialBo.pic]
options:SDWebImageLowPriority
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
} completed:^(UIImage *img, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
// UIImage *roundImage = [UIImage circleImage:img withParam:28];
dispatch_async(dispatch_get_main_queue(), ^{
self.tableView.imageV.imageView.image = img;
});
}];
[self viewWillLayoutSubviews];
}
-(void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
[self.tableView resetPullScaleFrame:CGRectMake(0,
-kPullHeightSpacial,
rect_screen.size.width,
kPullHeightSpacial)];
}
#pragma mark - coverFlow Delegate
- (void)pushToCoverFlowDetail:(listContObjectVO *)listBO {
pushContentWithListContentObject(self.navigationController, listBO);
}
- (void)setDataList:(NSMutableArray *)list {
heightListOfCellInSections = [NSMutableArray array];
self.dataSourceList = [NSMutableArray array];
// if (list.count == 0) {
// dispatch_async(dispatch_get_main_queue(), ^{
// [self.tableView setContentOffset:CGPointZero animated:YES];
// [self.tableView reloadData];
// });
// return;
// }
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
[list enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[specialObjectBO class]]) { //专题图片和导读
specialObjectBO *specialBO = obj;
specialBo = specialBO;
[self.dataSourceList addObject:specialBO];
NSString *descStr = @"<font color='#00a5eb'>导读 | </font>";
descStr = [descStr stringByAppendingString:specialBO.desc];
CGFloat topicHeadHeight = 0;
CGFloat topicDescWidth = 0;
/*计算高度图片高度和导读*/
topicDescWidth = rect_screen.size.width-20;
CGFloat descHeight = returnTextHeightWithRTLabel(descStr,
topicDescWidth,
appFont(TEXT_FIVE_LEVELSIZE, NO),
10);
topicHeadHeight = 15+descHeight+15;
if (readmode == imageMode) {
}else {
topicHeadHeight = 15+descHeight+15;
}
[heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",topicHeadHeight]];
}else {
nodeObjectBO *nodeBO = obj;
if ([nodeBO.dataType intValue] != 4) {
if ([nodeBO.dataType intValue]== 5) { //幻灯栏口
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
[heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",IMAGE_SIZE_HEIGHT+40]];
}else {
[heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",80.f]];
}
[self.dataSourceList addObject:nodeBO];
}else if ([nodeBO.dataType intValue] == 6) { //直播栏口
[heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",80.f]];
[self.dataSourceList addObject:nodeBO];
}else if ([nodeBO.dataType intValue] == 2) { //图集栏口
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
[heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",IMAGE_SIZE_HEIGHT+40]];
[self.dataSourceList addObject:nodeBO];
}else {
}
} else if ([nodeBO.dataType intValue] == 3) { //视屏栏口
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
[heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",IMAGE_SIZE_HEIGHT+40]];
[self.dataSourceList addObject:nodeBO];
}else {
}
}else { //卡片文章列表
[heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",80.f]];
[self.dataSourceList addObject:nodeBO];
}
}else { //热追问
NSMutableArray *qaList = [NSMutableArray array];
NSArray *tempQaList = nodeBO.contList; //热追问数据源
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 = 10;
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.askCommentBO = comment;
answer.type = @"3";
CGFloat anserHeight = 0;
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];
CGFloat four = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE);
if (anserH > four) {
anserH = four;
anserHeight += 25;
}
anserHeight += anserH;
[qaHeightArray addObject:[NSString stringWithFormat:@"%f",anserHeight]];
// [qaList addObject:answer]; //answerCommentBO
}
}];
if (qaList.count > 0) {
[qaList addObject:@"1"];
[qaHeightArray addObject:@"25"];
[self.dataSourceList addObject:qaList];
[heightListOfCellInSections addObject:qaHeightArray];
}
}
}
}];
BOOL isListNULL = NO;
if (!_dataList || _dataList.count == 0) {
isListNULL = YES;
}
_dataList = list;
if (readmode == imageMode) {
[self setImageV];
}else {
}
[self.tableView reloadData];
if (isListNULL) {
// [self.tableView setContentOffset:CGPointZero animated:YES];
[CoreAnimationEffect animationEaseOut:self.view];
}
}
#pragma mark UITableViewDelegate and UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (self.dataList && self.dataList.count > 0) {
return self.dataList.count;
}else return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.dataList && self.dataList.count > 0) {
if ([self.dataList[section] isKindOfClass:[nodeObjectBO class]]) {
nodeObjectBO *obj = self.dataList[section];
NSArray *array = obj.contList;
if ([obj.dataType integerValue] == 5) {
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
return 1;
}else{
return array.count;
}
}else if ([obj.dataType integerValue] == 4) {
return array.count*4;
}
return array.count;
}else return 1;
}else return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (heightListOfCellInSections && heightListOfCellInSections.count > 0) {
id heightObj = heightListOfCellInSections[indexPath.section];
if ([heightObj isKindOfClass:[NSString class]]) {
return [heightObj floatValue];
}else {
NSArray *heightList = (NSArray*)heightObj;
return [heightList[indexPath.row] floatValue];
}
}else return 0;
}
//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
// id data = self.dataSourceList[section];
// if ([data isKindOfClass:[specialObjectBO class]]) {
// return nil;
// }else if ([data isKindOfClass:[nodeObjectBO class]]) {
// if ([[(nodeObjectBO *)data dataType] integerValue] == 6) {
// return nil;
// }
// }
// UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect_screen.size.width, 10)];
// view.backgroundColor = [UIColor whiteColor];
// return view;
//}
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// id data = self.dataSourceList[section];
// if ([data isKindOfClass:[specialObjectBO class]]) {
// return 0.f;
// }else if ([data isKindOfClass:[nodeObjectBO class]]) {
// if ([[(nodeObjectBO *)data dataType] integerValue] == 6) {
// return 0.f;
// }
// }
//
// return 10.f;
//}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
id data = self.dataSourceList[section];
if ([data isKindOfClass:[specialObjectBO class]]) {
return 0;
}else {
if ([data isKindOfClass:[nodeObjectBO class]]) {
nodeObjectBO *nodeBO = data;
if ([nodeBO.dataType intValue] == 5) {
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
return 0;
}else {
return 30;
}
}else return 30;
}else return 30;
}
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
HeaderView *view = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:tableSectionHeaderId];
for (UIView *subView in view.subviews) {
if ([subView isKindOfClass:[UILabel class]] || [subView isKindOfClass:[UIButton class]]) {
[subView removeFromSuperview];
}
}
view.contentView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 7, rect_screen.size.width-20, 18)];
label.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
label.textColor = [UIColor colorWithHexString:BLUECOLOR];
label.backgroundColor = [UIColor clearColor];
[view addSubview:label];
id data = self.dataSourceList[section];
if ([data isKindOfClass:[specialObjectBO class]]) {
return nil;
}else {
if ([data isKindOfClass:[nodeObjectBO class]]) {
nodeObjectBO *nodeBO = data;
if ([nodeBO.dataType intValue] == 5) {
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
return nil;
}else {
label.text = nodeBO.name;
UIButton* moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
[moreButton setImage:Image(@"frontPage/askMoreArrow.png") forState:UIControlStateNormal];
[moreButton setImage:Image(@"frontPage/askMoreArrow.png") forState:UIControlStateHighlighted];
[moreButton setTitle:@"更多>>" forState:UIControlStateNormal];
[moreButton setTitleColor:[UIColor colorWithHexString:LIGHTGRAY] forState:UIControlStateNormal];
[moreButton setTitleColor:[UIColor colorWithHexString:BUTTONSELECTBACK] forState:UIControlStateHighlighted];
moreButton.titleLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
moreButton.titleLabel.textAlignment = NSTextAlignmentLeft;
[moreButton addTarget:self action:@selector(checkMoreInfo:) forControlEvents:UIControlEventTouchUpInside];
moreButton.frame = CGRectMake(0 + rect_screen.size.width-70,
0,
70,
30);
[moreButton setImageEdgeInsets:UIEdgeInsetsMake(CGRectGetHeight(moreButton.bounds)/2-5,
CGRectGetWidth(moreButton.bounds)-13,
CGRectGetHeight(moreButton.bounds)/2-5,
0)];
[moreButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 13)];
moreButton.tag = section + MOREBUTTONTAG;
[view addSubview:moreButton];
return view;
}
}else {
label.text = nodeBO.name;
if ([nodeBO.dataType intValue] != 6) {
if ([nodeBO.hasMore intValue] == 1) {
UIButton* moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
[moreButton setImage:Image(@"frontPage/askMoreArrow.png") forState:UIControlStateNormal];
[moreButton setImage:Image(@"frontPage/askMoreArrow.png") forState:UIControlStateHighlighted];
[moreButton setTitle:@"更多>>" forState:UIControlStateNormal];
[moreButton setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal];
[moreButton setTitleColor:[UIColor colorWithHexString:BUTTONSELECTBACK] forState:UIControlStateHighlighted];
moreButton.titleLabel.font = appFont(11, NO);
moreButton.titleLabel.textAlignment = NSTextAlignmentLeft;
[moreButton addTarget:self action:@selector(checkMoreInfo:) forControlEvents:UIControlEventTouchUpInside];
moreButton.frame = CGRectMake(0 + rect_screen.size.width-70,
0,
70,
30);
[moreButton setImageEdgeInsets:UIEdgeInsetsMake(CGRectGetHeight(moreButton.bounds)/2-5,
CGRectGetWidth(moreButton.bounds)-13,
CGRectGetHeight(moreButton.bounds)/2-5,
0)];
[moreButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 13)];
moreButton.tag = section + MOREBUTTONTAG;
[view addSubview:moreButton];
}
}
return view;
}
}else {
label.text = @"热追问";
return view;
}
}
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
id data = self.dataSourceList[indexPath.section];
if ([data isKindOfClass:[specialObjectBO class]]) {
return [self getSpecialHeadCell:table cellForRowAtIndexPath:indexPath];
}else if ([data isKindOfClass:[nodeObjectBO class]]) {
nodeObjectBO *nodeBO = data;
/*
dataType Int ? "内容列表中的展现方式: 1、 普通新闻列表,有更多链接,如图: 2、 图集新闻列表,有更多链接,如图: 3、 视频新闻列表,有更多链接,如图: 4、 热问答列表,如图: 5、 幻灯栏口列表,如图: 6、 直播栏口,如图:
只有在专题接口中用到"
*/
if ([nodeBO.dataType intValue] == 5) {
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
return [self getCoverFlowCell:table cellForRowAtIndexPath:indexPath];
}else{
return [self getNewestCell:table cellForRowAtIndexPath:indexPath];
}
}else if ([nodeBO.dataType intValue] == 6) {
return [self getLiveCell:table cellForRowAtIndexPath:indexPath];
}else if ([nodeBO.dataType intValue] == 2) { //图集栏口
return [self getImageScanCell:table cellForRowAtIndexPath:indexPath];
} else if ([nodeBO.dataType intValue] == 3) { //视屏栏口
return [self getMovieCell:table cellForRowAtIndexPath:indexPath];
}else if ([nodeBO.dataType intValue] != 4) {
return [self getNewestCell:table cellForRowAtIndexPath:indexPath];
}else {
static NSString* httpTableViewCellIdentefier = @"TPHttpTableViewController cell";
UITableViewCell* cell = [table dequeueReusableCellWithIdentifier:httpTableViewCellIdentefier];
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:httpTableViewCellIdentefier];
cell.backgroundColor = [UIColor whiteColor];
}
cell.textLabel.text = [NSString stringWithFormat:@"section:%ld,row=%ld",(long)indexPath.row, (long)indexPath.row];
return cell;
}
}else {
NSArray *otherSectionArray = data;
id obj = otherSectionArray[indexPath.row];
if ([obj isKindOfClass:[commentObjectVO class]]) { //热追问
commentObjectVO *comment = obj;
switch ([comment.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:
return nil;
break;
}
}else { //foot
return [self getSectionFoot:table cellForRowAtIndexPath:indexPath];
}
}
}
- (specialTopicHeadCell*)getSpecialHeadCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* specialTopicHeadCellId = @"specialTopicHeadCell cell";
specialTopicHeadCell* cell = (specialTopicHeadCell*)[table dequeueReusableCellWithIdentifier:specialTopicHeadCellId];
if (nil == cell) {
cell = [[specialTopicHeadCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:specialTopicHeadCellId];
}
id data = self.dataSourceList[indexPath.section];
cell.specialBO = data;
specialBo = data;
return cell;
}
- (topicCoverFlowCell*)getCoverFlowCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* coverFlowCellId = @"coverFlowCell cell";
topicCoverFlowCell* cell = (topicCoverFlowCell*)[table dequeueReusableCellWithIdentifier:coverFlowCellId];
if (nil == cell) {
cell = [[topicCoverFlowCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:coverFlowCellId];
}
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
cell.orientation = orientation;
id data = self.dataSourceList[indexPath.section];
cell.nodeBO = data;
cell.delegate = self;
cell.tag = 10086;
return cell;
}
- (sepicalLiveCell*)getLiveCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* sepicalLiveCellId = @"sepicalLiveCell cell";
sepicalLiveCell* cell = (sepicalLiveCell*)[table dequeueReusableCellWithIdentifier:sepicalLiveCellId];
if (nil == cell) {
cell = [[sepicalLiveCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:sepicalLiveCellId];
}
nodeObjectBO *data = self.dataSourceList[indexPath.section];
NSDictionary *dic = data.contList[0];
cell.dic = dic;
return cell;
}
- (specialContentCell *)getNewestCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* sepicalLiveCellId = @"specialContentCell cell";
specialContentCell* cell = (specialContentCell *)[table dequeueReusableCellWithIdentifier:sepicalLiveCellId];
if (nil == cell) {
cell = [[specialContentCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:sepicalLiveCellId];
}
nodeObjectBO *data = self.dataSourceList[indexPath.section];
listContObjectVO *listBO = setJsonDicToDataModel(data.contList[indexPath.row], [listContObjectVO class]);
if (data.contList.count-1 == indexPath.row) {
cell.isLast = @"1";
}else {
cell.isLast = @"0";
}
cell.contObjectVO = listBO;
return cell;
}
- (VedioSpecialCell *)getMovieCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* sepicalLiveCellId = @"movie cell";
VedioSpecialCell *cell = [table dequeueReusableCellWithIdentifier:sepicalLiveCellId];
if (nil == cell) {
cell = [[VedioSpecialCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:sepicalLiveCellId];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
nodeObjectBO *data = self.dataSourceList[indexPath.section];
listContObjectVO *listBO = setJsonDicToDataModel(data.contList[indexPath.row], [listContObjectVO class]);
[cell setListContent:listBO];
return cell;
}
- (ImageSpecialCell *)getImageScanCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* sepicalLiveCellId = @"image cell";
ImageSpecialCell *cell = [table dequeueReusableCellWithIdentifier:sepicalLiveCellId];
if (nil == cell) {
cell = [[ImageSpecialCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:sepicalLiveCellId];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
nodeObjectBO *data = self.dataSourceList[indexPath.section];
listContObjectVO *listBO = setJsonDicToDataModel(data.contList[indexPath.row], [listContObjectVO class]);
[cell setListContent:listBO];
return cell;
}
- (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.dataSourceList[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.dataSourceList[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.dataSourceList[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.dataSourceList[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;
NSMutableArray *heightarray = heightListOfCellInSections[IndexPath.section];
[heightarray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
[heightListOfCellInSections replaceObjectAtIndex:IndexPath.section withObject:heightarray];
NSArray *array = @[IndexPath];
[Self.tableView beginUpdates];
[Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[Self.tableView endUpdates];
}else {
CGFloat four = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE);
cellHeight = four+25;
NSMutableArray *heightarray = heightListOfCellInSections[IndexPath.section];
[heightarray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
[heightListOfCellInSections 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;
}
- (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 {
if (indexPath.section == 0) {
return;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
id data = self.dataSourceList[indexPath.section];
if ([data isKindOfClass:[nodeObjectBO class]]) {
nodeObjectBO *nodeBO= data;
if ([nodeBO.dataType intValue] == 6) {
NSArray *list = nodeBO.contList;
if (list.count >0) {
NSDictionary *dic = list[0];
TPLiveHomeController *liveVC = TPLiveHomeController.new;
liveVC.nodeId = dic[@"nodeId"];
[self.navigationController pushViewController:liveVC animated:YES];
}
}else {
listContObjectVO *listBO = setJsonDicToDataModel(nodeBO.contList[indexPath.row], [listContObjectVO class]);
pushContentWithListContentObject(self.navigationController, listBO);
}
}else if ([data isKindOfClass:[NSArray class]]) {
NSArray *otherSectionArray = data;
id obj = otherSectionArray[indexPath.row];
if ([obj isKindOfClass:[commentObjectVO class]]) {
commentObjectVO *item = obj;
if ([item.type intValue] == 2) {
}else {
// TODO answerContentCell
}
}
}
}
#pragma mark - anserDelegate
- (void)hasPraisedAnswer:(NSIndexPath *)indexPath withCommentBO:(commentObjectVO *)commentBO{
NSArray *otherSectionArray = self.dataSourceList[indexPath.section];
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:otherSectionArray];
[tempArray replaceObjectAtIndex:indexPath.row withObject:commentBO];
[self.dataSourceList replaceObjectAtIndex:indexPath.section withObject:tempArray];
}
#pragma mark - askDelegate
-(void)gotoUserInfo:(commentObjectVO *)comment{
if (![comment.userInfo[@"userId"] isEqualToString:[TPUserDefault instance].userBO.userId]) {
myDynamicController *dynamicVC = [myDynamicController new];
dynamicVC.comment = comment;
[self.navigationController pushViewController:dynamicVC animated:YES];
}else{
}
}
- (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) {
NSArray *otherSectionArray = self.dataSourceList[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(@"点赞失败");
}
}];
}
}
- (void)gotoHotAskWithCommentVO:(commentObjectVO *)comment {
[self gotoHotAsk:comment];
}
- (void)askIconBaseGotoHotAsk:(commentObjectVO *)comment {
[self gotoHotAsk:comment];
}
- (void)askIconBaseGotoUserInfo:(commentObjectVO *)comment {
[self gotoUserInfo:comment];
}
- (void)gotoHotAsk:(commentObjectVO *)comment {
askDetailController *hotAskVC = [[askDetailController alloc]init];
hotAskVC.commentBO = comment;
[self.navigationController pushViewController:hotAskVC animated:YES];
}
#pragma mark - check more content in list
- (void)checkMoreInfo:(UIButton*)btn {
id data = self.dataSourceList[btn.tag - MOREBUTTONTAG];
if ([data isKindOfClass:[nodeObjectBO class]]) {
nodeObjectBO *nodeBO = data;
topicMoreInfoController *vc = [[topicMoreInfoController alloc] init];
vc.specialBo = specialBo;
vc.nodeObj = nodeBO;
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)refreshPage {
if ([self.delegate respondsToSelector:@selector(needRefreshPage)]) {
[self.delegate needRefreshPage];
}
}
#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)), 170, appFont(TEXT_SEVEN_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 *specialContentBO = [contentObjectBO new];
specialContentBO.name = comment.askCommentBO.contName;
specialContentBO.summary = comment.content;
specialContentBO.shareUrl = comment.askCommentBO.objInfo[@"shareUrl"];
if ([self.delegate respondsToSelector:@selector(gotoShare:contentBO:)]) {
[self.delegate gotoShare:img contentBO:specialContentBO];
}
// }
}
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
NSString *msg = nil ;
// if(error != NULL){
// msg = @"保存图片失败" ;
// }else{
// msg = @"已保存至相册" ;
// }
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)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
|