澎湃iPad上线版本

commentAndAskController.m 22KB

    // // commentAndAskController.m // ThePaperHD // // Created by scar1900 on 15/1/16. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "commentAndAskController.h" #import "ATPagingView.h" #import "commentTableController.h" #import "askTableController.h" #import "hotAskListHomeController.h" #import "detailContentHomeController.h" #import "topicHomeController.h" #import "ImageContentController.h" #import "commentAndAskController.h" #import "TPcontentWebController.h" #import "TPLiveHomeController.h" #import "otherPersonHomepageController.h" #define HANDLELINETAG 200 @interface commentAndAskController ()<ATPagingViewDelegate,commentTableDelegate,askTableDelegate,hotAskListHomeDelegate> { CGFloat statusHeight; } @property(nonatomic, strong)ATPagingView *pagingView; @property(nonatomic, strong)NSMutableArray *pageViewControllers; @property(nonatomic, strong)NSArray *viewControllers; @property(nonatomic, strong)UIView *handlerView; @property(nonatomic, strong)UIButton *commentButton; @property(nonatomic, strong)UIButton *askButton; @property(nonatomic, strong)UIView *topLine; @property(nonatomic, strong)UILabel *commentLabel; @property(nonatomic, strong)UILabel *askLabel; @property(nonatomic, strong)UILabel *commentNumLabel; @property(nonatomic, strong)UILabel *askNumLabel; @property(nonatomic, strong)hotAskListHomeController *hotAskVC; @end @implementation commentAndAskController @synthesize nodeId = _nodeId; @synthesize viewControllers,pageViewControllers; @synthesize commentList = _commentList; @synthesize commentNextUrl = _commentNextUrl; @synthesize commentTotalRecord = _commentTotalRecord,askTotalRecord = _askTotalRecord; @synthesize askNextUrl = _askNextUrl, qaDic = _qaDic; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor clearColor]; if (isIOS7) { statusHeight =18; }else statusHeight = 0; [self.view addSubview:self.handlerView]; [self.view addSubview:self.commentButton]; [self.view addSubview:self.askButton]; [self.view insertSubview:self.commentButton belowSubview:self.handlerView]; [self.view addSubview:self.topLine]; [self.commentButton addSubview:self.commentLabel]; [self.askButton addSubview:self.askLabel]; [self.commentButton addSubview:self.commentNumLabel]; [self.askButton addSubview:self.askNumLabel]; self.view.clipsToBounds = YES; self.commentButton.selected = YES; self.askButton.selected = NO; self.commentLabel.textColor = [UIColor whiteColor]; self.commentNumLabel.textColor = [UIColor whiteColor]; self.askLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; self.askNumLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; self.viewControllers = [NSArray arrayWithObjects:@"commentTableController",@"askTableController", nil]; [viewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if (nil == self.pageViewControllers) { self.pageViewControllers = [NSMutableArray array]; } if ([obj isKindOfClass:[UIViewController class]]) { [self.pageViewControllers addObject:obj]; [self addChildViewController:obj]; } else { [self.pageViewControllers addObject:[NSNull null]]; } }]; UIView *view = self.pagingView; view.frame = CGRectMake(CGRectGetMaxX(self.handlerView.frame), CGRectGetMaxY(self.commentButton.frame), self.view.frame.size.width-CGRectGetWidth(self.handlerView.frame), self.view.frame.size.height-CGRectGetHeight(self.commentButton.frame)); [self.view addSubview:view]; [self.view insertSubview:view belowSubview:self.handlerView]; [self.pagingView reloadData]; self.commentLabel.frame = CGRectMake(CGRectGetWidth(self.commentButton.frame)/2-30/2, CGRectGetHeight(self.commentButton.frame)/2-10, 30, 20); self.askLabel.frame = CGRectMake(CGRectGetWidth(self.askButton.frame)/2-30/2, CGRectGetHeight(self.askButton.frame)/2-10, 30, 20); } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; __weak typeof(self) Self = self; if (self.hotAskVC && self.hotAskVC.isNeedHold) { [self presentController:self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{ } dismiss:^{ if (!Self.hotAskVC.isNeedHold) { Self.hotAskVC = nil; } }]; } } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; self.handlerView.frame = CGRectMake(0, 0, 25, CGRectGetHeight(self.view.bounds)); UIView *firstLine = [self.handlerView viewWithTag:HANDLELINETAG+1]; firstLine.frame = CGRectMake(CGRectGetWidth(self.handlerView.bounds)-15, CGRectGetHeight(self.handlerView.bounds)/2-15, 3, 30); UIView *secondLine = [self.handlerView viewWithTag:HANDLELINETAG+2]; secondLine.frame =CGRectMake(CGRectGetWidth(self.handlerView.bounds)-9, CGRectGetHeight(self.handlerView.bounds)/2-15, 3, 30); UIView *view = self.pagingView; [self.pagingView removeFromSuperview]; view.frame = CGRectMake(CGRectGetMaxX(self.handlerView.frame), CGRectGetMaxY(self.commentButton.frame), self.view.frame.size.width-CGRectGetWidth(self.handlerView.frame), self.view.frame.size.height-CGRectGetHeight(self.commentButton.frame)); [self.view addSubview:view]; [self.view insertSubview:view belowSubview:self.handlerView]; [self.pagingView reloadData]; } #pragma mark - paging view - (ATPagingView*)pagingView { if (!_pagingView) { _pagingView = [[ATPagingView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.handlerView.frame), CGRectGetMaxY(self.commentButton.frame), self.view.frame.size.width-CGRectGetWidth(self.handlerView.frame), self.view.frame.size.height-CGRectGetHeight(self.commentButton.frame))]; _pagingView.gapBetweenPages = 0; _pagingView.recyclingEnabled = NO; _pagingView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; // _pagingView.autoresizingMask = AutoresizingFull; _pagingView.delegate = self; _pagingView.clipsToBounds = YES; _pagingView.scrollView.scrollEnabled = YES; } return _pagingView; } - (void)setNodeId:(NSString *)nodeId { _nodeId = nodeId; [self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[commentTableController class]]) { commentTableController *commentTable = obj; commentTable.nodeId = self.nodeId; commentTable.delegate = self; } if ([obj isKindOfClass:[askTableController class]]) { askTableController *askTable = obj; askTable.nodeId = self.nodeId; askTable.delegate = self; __weak typeof(self) Self = self; [askTable goToAskDetailPage:^(id commentObj) { if (!Self.hotAskVC) { Self.hotAskVC = [[hotAskListHomeController alloc]init]; Self.hotAskVC.commentBO = commentObj; Self.hotAskVC.delegate = Self; Self.hotAskVC.commentOT = Self.commentOT; } [Self presentController:Self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{ }dismiss:^{ if (!Self.hotAskVC.isNeedHold) { Self.hotAskVC = nil; } }tapHandler:^{ if (Self.hotAskVC.writeVC) { [Self.hotAskVC.writeVC closeKeyBoard]; } }]; }]; } }]; } - (UIView*)topLine { if (!_topLine) { _topLine = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.commentButton.frame), CGRectGetMaxY(self.commentButton.frame)-1, CGRectGetWidth(self.commentButton.frame)+CGRectGetWidth(self.askButton.frame), 1)]; _topLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _topLine; } - (UIView*)handlerView { if (!_handlerView) { _handlerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 25, CGRectGetHeight(self.view.bounds))]; _handlerView.backgroundColor = [UIColor clearColor]; UIView *firstLine = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.handlerView.bounds)-15, CGRectGetHeight(self.handlerView.bounds)/2-15, 3, 30)]; firstLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; firstLine.tag = HANDLELINETAG + 1;; [_handlerView addSubview:firstLine]; UIView *secondLine = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.handlerView.bounds)-9, CGRectGetHeight(self.handlerView.bounds)/2-15, 3, 30)]; secondLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; secondLine.autoresizingMask = AutoresizingAuto; secondLine.tag = HANDLELINETAG + 2; [_handlerView addSubview:secondLine]; } return _handlerView; } - (UIButton*)commentButton { if (!_commentButton) { _commentButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_commentButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xedf7fc"]) forState:UIControlStateNormal]; [_commentButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateSelected]; _commentButton.frame = CGRectMake(CGRectGetMaxX(self.handlerView.frame), 0, (1214/2-CGRectGetWidth(self.handlerView.frame))/2, 50); [_commentButton addTarget:self action:@selector(clickComment:) forControlEvents:UIControlEventTouchUpInside]; } return _commentButton; } - (UIButton*)askButton { if (!_askButton) { _askButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_askButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xedf7fc"]) forState:UIControlStateNormal]; [_askButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateSelected]; _askButton.frame = CGRectMake(CGRectGetMaxX(self.commentButton.frame), 0, CGRectGetWidth(self.commentButton.frame), 50); [_askButton addTarget:self action:@selector(clickAsk:) forControlEvents:UIControlEventTouchUpInside]; } return _askButton; } - (void)setCommentList:(NSMutableArray *)list { _commentList = list; [self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[commentTableController class]]) { commentTableController *commentTable = obj; commentTable.dataList = list; if (self.commentOT && !isBlankString(self.commentOT)) { commentTable.commentOT = self.commentOT; } } }]; } - (void)setCommentNextUrl:(NSString *)url { _commentNextUrl = url; [self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[commentTableController class]]) { commentTableController *commentTable = obj; commentTable.nextUrl = url; } }]; } - (void)setQaDic:(NSMutableDictionary *)dic { _qaDic = dic; [self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[askTableController class]]) { askTableController *askTable = obj; askTable.qaDic = dic; if (self.commentOT && !isBlankString(self.commentOT)) { askTable.commentOT = self.commentOT; } } }]; } - (void)setAskNextUrl:(NSString *)url { _askNextUrl = url; [self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[askTableController class]]) { askTableController *askTable = obj; askTable.nextUrl = url; if (self.commentOT && !isBlankString(self.commentOT)) {//直播和图集,互动列表中的追问数没有包含回答数,只有提问数(bug:4962 bug:5300) askTable.commentOT= self.commentOT; } } }]; } - (UILabel*)commentLabel { if (!_commentLabel) { _commentLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _commentLabel.font = appFont(15, NO); _commentLabel.text = @"评论"; _commentLabel.backgroundColor = [UIColor clearColor]; } return _commentLabel; } - (UILabel*)commentNumLabel { if (!_commentNumLabel) { _commentNumLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _commentNumLabel.font = appFont(11, NO); _commentNumLabel.backgroundColor = [UIColor clearColor]; } return _commentNumLabel; } - (UILabel*)askLabel { if (!_askLabel) { _askLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _askLabel.font = appFont(15, NO); _askLabel.text = @"追问"; _askLabel.backgroundColor = [UIColor clearColor]; } return _askLabel; } - (UILabel*)askNumLabel { if (!_askNumLabel) { _askNumLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _askNumLabel.font = appFont(11, NO); _askNumLabel.backgroundColor = [UIColor clearColor]; } return _askNumLabel; } - (void)setCommentTotalRecord:(NSInteger)record { _commentTotalRecord = record; NSString *numStr = [NSString stringWithFormat:@"(%ld)",(long)record]; CGFloat commentNumWidth = widthForString(numStr, self.commentNumLabel.font, 11, NSLineBreakByCharWrapping); CGFloat commentWidth = 30; CGFloat totalWidth = commentWidth+commentNumWidth+6; self.commentNumLabel.text = numStr; self.commentLabel.frame = CGRectMake(CGRectGetWidth(self.commentButton.frame)/2-totalWidth/2, CGRectGetHeight(self.commentButton.frame)/2-10, commentWidth, 20); self.commentNumLabel.frame = CGRectMake(CGRectGetMaxX(self.commentLabel.frame)+2, CGRectGetMaxY(self.commentLabel.frame)-15, commentNumWidth, 15); } - (void)setAskTotalRecord:(NSInteger)record { _askTotalRecord = record; _commentTotalRecord = record; NSString *numStr = [NSString stringWithFormat:@"(%ld)",(long)record]; CGFloat commentNumWidth = widthForString(numStr, self.askNumLabel.font, 13, NSLineBreakByCharWrapping); CGFloat commentWidth = 30.f; CGFloat totalWidth = commentWidth+commentNumWidth+6; self.askNumLabel.text = numStr; self.askLabel.frame = CGRectMake(CGRectGetWidth(self.askButton.frame)/2-totalWidth/2, CGRectGetHeight(self.askButton.frame)/2-10, commentWidth, 20); self.askNumLabel.frame = CGRectMake(CGRectGetMaxX(self.askLabel.frame)+2, CGRectGetMaxY(self.askLabel.frame)-15, commentNumWidth, 15); } #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); }]; } #pragma mark - button handler - (void)clickComment:(UIButton*)btn { if (btn.selected) { [self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[commentTableController class]]) { commentTableController *commentTable = obj; [commentTable.tableView setContentOffset:CGPointZero animated:YES]; } }]; return; } [UIView animateWithDuration:0.25 animations:^{ btn.selected = !btn.selected; if (btn.selected) { self.askButton.selected = NO; } self.commentLabel.textColor = [UIColor whiteColor]; self.commentNumLabel.textColor = [UIColor whiteColor]; self.askLabel.textColor = [UIColor colorWithHexString:@"0x848383"]; self.askNumLabel.textColor = [UIColor colorWithHexString:@"0x848383"]; }]; self.pagingView.currentPageIndex = 0; // [CoreAnimationEffect animationPushLeft:self.pagingView]; } - (void)clickAsk:(UIButton*)btn { if (btn.selected) { [self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[askTableController class]]) { askTableController *askTable = obj; [askTable.tableView setContentOffset:CGPointZero animated:YES]; } }]; return; } [UIView animateWithDuration:0.25 animations:^{ btn.selected = !btn.selected; if (btn.selected) { self.commentButton.selected = NO; } self.commentLabel.textColor = [UIColor colorWithHexString:@"0x848383"]; self.commentNumLabel.textColor = [UIColor colorWithHexString:@"0x848383"]; self.askLabel.textColor = [UIColor whiteColor]; self.askNumLabel.textColor = [UIColor whiteColor]; }]; self.pagingView.currentPageIndex = 1; // [CoreAnimationEffect animationPushRight:self.pagingView]; } -(void)gotoPersonInfo:(commentObjectVO *)comment{ [self dismissControllerAnimated:YES completion:^{ otherPersonHomepageController *otherVC = [otherPersonHomepageController new]; otherVC.commentBo = comment; [self.navigationController pushViewController:otherVC animated:YES]; }]; } #pragma mark ATPagingViewDelegate methods - (NSInteger)numberOfPagesInPagingView:(ATPagingView *)pagingView { return self.viewControllers.count; } - (UIView *)viewForPageInPagingView:(ATPagingView *)pagingView atIndex:(NSInteger)index { if (self.pageViewControllers[index] == [NSNull null]) { NSString *className = self.viewControllers[index]; Class class = NSClassFromString(className); // UIViewController *vc = [[class alloc] init]; // self.pageViewControllers[index] = vc; // [self addChildViewController:vc]; //【需求】无网络处理优化(重新加载打底图)(bug:5953) if ([className isEqualToString:@"commentTableController"]) { commentTableController *commentVC = [[class alloc] init]; commentVC.nodeId = self.nodeId; commentVC.commentOT = self.commentOT; commentVC.delegate = self; self.pageViewControllers[index] = commentVC; [self addChildViewController:commentVC]; }else{ askTableController *askVC = [[class alloc] init]; askVC.nodeId = self.nodeId; askVC.commentOT = self.commentOT; askVC.delegate = self; self.pageViewControllers[index] = askVC; [self addChildViewController:askVC]; } } return ((UIViewController*)self.pageViewControllers[index]).view; } - (void)currentPageDidChangeInPagingView:(ATPagingView *)pageView { [UIView animateWithDuration:0.25 animations:^{ if (pageView.currentPageIndex == 0) { self.commentButton.selected = YES; self.askButton.selected = NO; self.commentLabel.textColor = [UIColor whiteColor]; self.commentNumLabel.textColor = [UIColor whiteColor]; self.askLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; self.askNumLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; }else { self.commentButton.selected = NO; self.askButton.selected = YES; self.commentLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; self.commentNumLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; self.askLabel.textColor = [UIColor whiteColor]; self.askNumLabel.textColor = [UIColor whiteColor]; } }]; } - (void)pagesDidChangeInPagingView:(ATPagingView *)pageView { } - (void)pagingViewWillBeginMoving:(ATPagingView *)pageView { } - (void)pagingViewdDidScroll:(UIScrollView *)scrollerView { } #pragma mark - api - (void)hiddenHandler { self.handlerView.hidden = YES; } - (void)appearHander { self.handlerView.hidden = NO; } #pragma mark - comment and table delegate - (void)endCommentRefresh:(NSString *)commentRecord { self.commentTotalRecord = [commentRecord integerValue]; } - (void)endAskRefresh:(NSString *)askRecord { self.askTotalRecord = [askRecord integerValue]; } - (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