// // specialTopicTableController.m // ThePaperHD // // Created by scar1900 on 15/2/13. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "specialTopicTableController.h" #import "specialTopicHeadCell.h" #import "topicCoverFlowCell.h" #import "sepicalLiveCell.h" #import "topicContentListCell.h" #import "askContentCell.h" #import "answerContentCell.h" #import "hotAskListHomeController.h" #import "detailContentHomeController.h" #import "topicHomeController.h" #import "columnListController.h" #import "topicMoreInfoController.h" #import "customFlowLayout.h" #import "ImageContentController.h" #import "TPcontentWebController.h" #import "TPLiveHomeController.h" #import "otherPersonHomepageController.h" #define MOREBUTTONTAG 1300 @interface specialTopicTableController () { NSMutableArray *heightListOfCellInSections; } @property(nonatomic, strong)NSMutableArray *dataSourceList; @end @implementation specialTopicTableController @synthesize dataList = _dataList; @synthesize dataSourceList; @synthesize delegate; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.tableView.clipsToBounds = YES; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.contentInset = UIEdgeInsetsZero; } - (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; } [list enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[specialObjectBO class]]) { //专题图片和导读 specialObjectBO *specialBO = obj; [self.dataSourceList addObject:specialBO]; NSString *descStr = @"导读 | "; descStr = [descStr stringByAppendingString:specialBO.desc]; CGFloat topicHeadHeight = 0; CGFloat topicDescWidth = 0; /*计算高度图片高度和导读*/ topicDescWidth = 1312/2; CGFloat descHeight = returnTextHeightWithRTLabel(descStr, topicDescWidth, appFont(18, NO), 20); topicHeadHeight = 350/2+15+descHeight+15; [heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",topicHeadHeight]]; }else { nodeObjectBO *nodeBO = obj; if ([nodeBO.dataType intValue] != 4) { [self.dataSourceList addObject:nodeBO]; if ([nodeBO.dataType intValue]== 5) { //幻灯栏口 [heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",850.f/2]]; }else if ([nodeBO.dataType intValue] == 6) { //直播栏口 [heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",260.f/2]]; }else { //卡片文章列表 NSArray *contentList = nodeBO.contList; CGFloat height = 0; CGFloat width = (1312/2-35)/2; CGFloat viewScale = width/300; height = 215*viewScale; height = height*2+40+35; if (contentList.count<=2) { [heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",height/2]]; }else { [heightListOfCellInSections addObject:[NSString stringWithFormat:@"%f",height]]; } } }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; } [qaList addObject:commentBO]; CGFloat askHeight = 126/2; CGFloat askCotentHeight = returnTextHeightWithRTLabel(commentBO.content, 1170/2, appFont(15, NO),10); askHeight = askHeight + askCotentHeight + 13; [qaHeightArray addObject:[NSString stringWithFormat:@"%f", askHeight]]; if (commentBO.answerList && commentBO.answerList.count > 0) { commentObjectVO *answerBO = setJsonDicToDataModel(commentBO.answerList[0], [commentObjectVO class]); [qaList addObject:answerBO]; CGFloat hei = 130/2; //247环境下,时事频道下的第一篇专题的最后一条热追问,点击展开箭头不可正常加载(BUG:4729) // CGFloat answerContent = returnTextHeightWithRTLabel(answerBO.content, 1170/2, appFont(13, NO),10)>100?100+30:returnTextHeightWithRTLabel(answerBO.content, 1170/2, appFont(13, NO),10); CGFloat answerContent = returnTextHeightWithRTLabel(answerBO.content, 1170/2, appFont(interactionFontSize, NO),10)>100?100+30:returnTextHeightWithRTLabel(answerBO.content, 1170/2, appFont(interactionFontSize, NO),10); // TPLOG(@"%@\n%f",answerBO.content,answerContent); hei = hei+answerContent+10; [qaHeightArray addObject:[NSString stringWithFormat:@"%f", hei]]; } }]; 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; [self.tableView reloadData]; if (isListNULL) { [self.tableView setContentOffset:CGPointZero animated:YES]; [CoreAnimationEffect animationEaseOut:self.view]; } } -(void)gotoPersonInfo:(commentObjectVO *)comment{ if ([self.delegate respondsToSelector:@selector(gotoPersonInfo:)]) { [self.delegate gotoPersonInfo:comment]; } } #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.dataSourceList && self.dataSourceList.count > 0) { if ([self.dataSourceList[section] isKindOfClass:[NSMutableArray class]]) { NSMutableArray *array = self.dataSourceList[section]; 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; } - (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) { return 0; }else return 30; }else return 30; } } - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { CGFloat padding = 0; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { padding = 125; } UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1312/2, 30)]; view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; UIView *colorView = [[UIView alloc]initWithFrame:CGRectMake(padding, 5, 5, 20)]; colorView.backgroundColor = [UIColor colorWithHexString:BLUECOLOR]; [view addSubview:colorView]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(colorView.frame)+10, 0, 1312/2, 30)]; label.font = appFont(20, NO); label.textColor = [UIColor colorWithHexString:TextBlack]; 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) { return nil; }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(padding + CGRectGetWidth(view.bounds)-70, 0, 70, CGRectGetHeight(view.bounds)); [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; if ([nodeBO.dataType intValue] == 5) { return [self getCoverFlowCell:table cellForRowAtIndexPath:indexPath]; }else if ([nodeBO.dataType intValue] == 6) { return [self getLiveCell:table cellForRowAtIndexPath:indexPath]; }else if ([nodeBO.dataType intValue] != 4) { return [self getListCell: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; if ([comment.type intValue] == 2) { return [self getHotAskContentCell:table cellForRowAtIndexPath:indexPath]; }else return [self getHotAnswerContentCell:table cellForRowAtIndexPath:indexPath]; }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; 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; 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]; } id data = self.dataSourceList[indexPath.section]; cell.nodeBO = data; return cell; } - (topicContentListCell*)getListCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* topicContentListCellId = @"topicContentListCell cell"; topicContentListCell* cell = (topicContentListCell*)[table dequeueReusableCellWithIdentifier:topicContentListCellId]; if (nil == cell) { cell = [[topicContentListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:topicContentListCellId]; } id data = self.dataSourceList[indexPath.section]; cell.nodeBO = data; cell.delegate = self; return cell; } - (askContentCell*)getHotAskContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"hotAskContentCell"; askContentCell *cell = (askContentCell*)[tableView dequeueReusableCellWithIdentifier:cellID]; if (nil == cell) { cell = [[askContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } NSArray *otherSectionArray = self.dataSourceList[indexPath.section]; id obj = otherSectionArray[indexPath.row]; cell.commentBO = obj; cell.askContentDelegate = self; return cell; } - (answerContentCell*)getHotAnswerContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"answerContentCell"; answerContentCell *cell = (answerContentCell*)[tableView dequeueReusableCellWithIdentifier:cellID]; if (nil == cell) { cell = [[answerContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } NSArray *otherSectionArray = self.dataSourceList[indexPath.section]; id obj = otherSectionArray[indexPath.row]; cell.commentBO = obj; cell.delegate = self; cell.indexPath = indexPath; __block NSIndexPath* IndexPath = indexPath; __weak typeof(self) Self = self; [cell expandCell:^(BOOL isExpand, CGFloat labelHeight) { if (isExpand) { CGFloat offset = labelHeight - 170/2; NSMutableArray *qaHeightList = heightListOfCellInSections[indexPath.section]; NSString *qaAllHeightStr = qaHeightList[IndexPath.row]; CGFloat qaAllHeight = [qaAllHeightStr floatValue]+offset; [qaHeightList replaceObjectAtIndex:indexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]]; [heightListOfCellInSections replaceObjectAtIndex:IndexPath.section withObject:qaHeightList]; NSArray *array = @[IndexPath]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic]; }else { CGFloat offset = labelHeight - 170/2; NSMutableArray *qaHeightList = heightListOfCellInSections[indexPath.section]; NSString *qaAllHeightStr = qaHeightList[IndexPath.row]; CGFloat qaAllHeight = [qaAllHeightStr floatValue]-offset; [qaHeightList replaceObjectAtIndex:indexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]]; [heightListOfCellInSections replaceObjectAtIndex:IndexPath.section withObject:qaHeightList]; NSArray *array = @[IndexPath]; dispatch_async(dispatch_get_main_queue(), ^{ [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic]; [Self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; }); } }]; return cell; } - (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; } 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 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) { hotAskListHomeController *hotAskVC = [[hotAskListHomeController alloc]init]; hotAskVC.commentBO = item; hotAskVC.delegate = self; [self presentController:hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{ }dismiss:^{ }tapHandler:^{ if (hotAskVC.writeVC) { [hotAskVC.writeVC closeKeyBoard]; } }]; } } } } - (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]; } -(void)gotoUserInfo:(commentObjectVO *)comment{ if (![comment.userInfo[@"userId"] isEqualToString:[TPUserDefault instance].userBO.userId]) { otherPersonHomepageController *otherVC = [otherPersonHomepageController new]; otherVC.commentBo = comment; [self.navigationController pushViewController:otherVC animated:YES]; }else{ } } #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; customFlowLayout *layout = nil; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; CGSize itemSize = CGSizeZero; layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 35; layout.minimumInteritemSpacing = 35; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { CGFloat width = (self.view.bounds.size.width-35*3)/2; itemSize = CGSizeMake(width, 470/2); }else { CGFloat width = (self.view.bounds.size.width-35*4)/3; itemSize = CGSizeMake(width, 446/2); } layout.itemSize = itemSize; topicMoreInfoController *vc = [[topicMoreInfoController alloc]initWithCollectionViewLayout:layout]; vc.nodeObj = nodeBO; [self.navigationController pushViewController:vc animated:YES]; layout = nil; } } #pragma mark - coverFlow Delegate - (void)pushToCoverFlowDetail:(listContObjectVO *)listBO { [self pushOtherPage:listBO]; } #pragma mark - topic content list delegate - (void)goToMoreInfoPage:(listContObjectVO *)listBO { customFlowLayout *layout = nil; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; CGSize itemSize = CGSizeZero; layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 35; layout.minimumInteritemSpacing = 35; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { CGFloat width = (self.view.bounds.size.width-35*3)/2; itemSize = CGSizeMake(width, 470/2); }else { CGFloat width = (self.view.bounds.size.width-35*4)/3; itemSize = CGSizeMake(width, 446/2); } layout.itemSize = itemSize; columnListController *vc = [[columnListController alloc]initWithCollectionViewLayout:layout]; vc.listBO = listBO; [self.navigationController pushViewController:vc animated:YES]; layout = nil; } - (void)pushToDetailpage:(listContObjectVO *)listBO { [self pushOtherPage:listBO]; } #pragma mark - push detail method - (void)pushOtherPage:(id)data { if ([data isKindOfClass:[listContObjectVO class]]) { listContObjectVO *listItem = data; pushContentWithListContentObject(self.navigationController, listItem); }else if ([data isKindOfClass:[commentObjectVO class]]) { commentObjectVO *commentBO = data; pushContentWithCommentBO(self.navigationController, commentBO); } } #pragma mark - hot ask list delegate - (void)goToOriginContent:(objInfoBO *)commentBO presentedController:(TPHttpController *)presentedController{ __weak typeof(self) Self = self; [presentedController dismissControllerAnimated:YES completion:^{ pushContentWithObjInfo(Self.navigationController, commentBO); }]; } - (void)refreshPage { if ([self.delegate respondsToSelector:@selector(needRefreshPage)]) { [self.delegate needRefreshPage]; } } - (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