// // hotAnswerCell.m // ThePaperHD // // Created by scar1900 on 15/2/2. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "hotAnswerCell.h" #import "TPSelectButton.h" @interface hotAnswerCell() { CGFloat viewScale; CGFloat askNameHeight; CGFloat answerNameHeight; } @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UIImageView *backImgView; @property(nonatomic, strong)UIImageView *itemBorderView; @property(nonatomic, strong)UILabel *contentNameLabel; @property(nonatomic, strong)UIView *contentLineView; @property(nonatomic, strong)UILabel *askContentLabel; @property(nonatomic, strong)UILabel *answerContentLabel; @property(nonatomic, strong)UIView *lineView; @property(nonatomic, strong)UIImageView *layerView; @property(nonatomic, strong)TPSelectButton *praiseButton; @property(nonatomic, strong)commentObjectVO *answerBO; @property(nonatomic, strong)UIImageView *shadowLine; @end @implementation hotAnswerCell @synthesize commentBO = _commentBO; @synthesize delegate; @synthesize answerBO = _answerBO; @synthesize indexPath; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // self.backgroundColor = [UIColor clearColor]; viewScale = frame.size.width/300; self.clipsToBounds = YES; [self addSubview:self.backView]; [self.backView addSubview:self.backImgView]; [self.backView addSubview:self.contentNameLabel]; [self.backView addSubview:self.contentLineView]; [self.backView addSubview:self.askContentLabel]; [self.backView addSubview:self.answerContentLabel]; [self.backView addSubview:self.lineView]; [self.backView addSubview:self.praiseButton]; [self.backView addSubview:self.layerView]; [self.backView addSubview:self.shadowLine]; [self addSubview:self.itemBorderView]; UIButton *labelBack = [UIButton buttonWithType:UIButtonTypeCustom]; labelBack.tag = 100; labelBack.backgroundColor = [UIColor clearColor]; [labelBack addTarget:self action:@selector(headButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:labelBack]; UIButton *answerDetailBtn = [UIButton buttonWithType:UIButtonTypeCustom]; answerDetailBtn.tag = 101; answerDetailBtn.backgroundColor = [UIColor clearColor]; [answerDetailBtn addTarget:self action:@selector(answerDetailClick:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:answerDetailBtn]; } return self; } - (UIImageView*)shadowLine { if (!_shadowLine) { _shadowLine = [[UIImageView alloc]initWithImage:Image(@"other/askCardShadowLine.png")]; } return _shadowLine; } - (UIView*)backView { if (!_backView){ _backView = [[UIView alloc]initWithFrame:CGRectZero]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } - (UIImageView*)layerView { if (!_layerView) { _layerView = [[UIImageView alloc]initWithFrame:CGRectZero]; _layerView.backgroundColor = [UIColor clearColor]; } return _layerView; } - (UIImageView*)backImgView { if (!_backImgView) { _backImgView = [[UIImageView alloc]initWithFrame:CGRectZero]; _backImgView.image = Image(@"frontPage/hotAskBack.png"); } return _backImgView; } - (UIImageView*)itemBorderView { if (!_itemBorderView) { _itemBorderView = [[UIImageView alloc]init]; _itemBorderView.image = Image(@"frontPage/itemBorder.png"); } return _itemBorderView; } - (UILabel*)contentNameLabel { if (!_contentNameLabel) { _contentNameLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _contentNameLabel.textColor = [UIColor whiteColor]; _contentNameLabel.lineBreakMode = NSLineBreakByWordWrapping; _contentNameLabel.numberOfLines = 0; _contentNameLabel.textAlignment = NSTextAlignmentLeft; _contentNameLabel.font = appFont(11, NO); _contentNameLabel.backgroundColor = [UIColor clearColor]; } return _contentNameLabel; } - (UIView*)contentLineView { if (!_contentLineView) { _contentLineView = [[UIView alloc]initWithFrame:CGRectZero]; _contentLineView.backgroundColor = [UIColor whiteColor]; _contentLineView.alpha = 0.8; } return _contentLineView; } - (UILabel*)askContentLabel { if (!_askContentLabel) { _askContentLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _askContentLabel.textColor = [UIColor whiteColor]; _askContentLabel.textAlignment = NSTextAlignmentLeft; _askContentLabel.lineBreakMode = NSLineBreakByWordWrapping; _askContentLabel.numberOfLines = 0; _askContentLabel.font = appFont(20, YES); _askContentLabel.backgroundColor = [UIColor clearColor]; } return _askContentLabel; } - (UILabel*)answerContentLabel { if (!_answerContentLabel) { _answerContentLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _answerContentLabel.textColor = [UIColor whiteColor]; _answerContentLabel.textAlignment = NSTextAlignmentLeft; _answerContentLabel.lineBreakMode = NSLineBreakByWordWrapping; _answerContentLabel.numberOfLines = 3; _answerContentLabel.font = appFont(14, NO); _answerContentLabel.backgroundColor = [UIColor clearColor]; } return _answerContentLabel; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc]initWithFrame:CGRectZero]; _lineView.backgroundColor = [UIColor whiteColor]; _lineView.alpha = 0.8; } return _lineView; } - (TPSelectButton*)praiseButton { if (!_praiseButton) { _praiseButton = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(praiseHandler:)]; [_praiseButton setBUttonNormalImage:Image(@"frontPage/hotAskPraise.png") highLightImage:Image(@"frontPage/hotAskPraise_s.png") selectedImage:Image(@"frontPage/hotAskPraise_s.png")]; _praiseButton.textLabel.font = appFont(10, NO); _praiseButton.textLabel.textColor = [UIColor whiteColor]; _praiseButton.userInteractionEnabled = NO; } return _praiseButton; } - (void)setCommentBO:(commentObjectVO *)data { _commentBO = data; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ viewScale = self.bounds.size.width/300; NSDictionary *answerDic = data.answerList[0]; self.answerBO = setJsonDicToDataModel(answerDic, [commentObjectVO class]); NSInteger r = arc4random() % [[TPUserDefault instance].hotAskColorList count]; NSDictionary *colorDic = [TPUserDefault instance].hotAskColorList[r]; NSString *imageStr = colorDic[@"image"]; UIColor *backColor = colorDic[@"color"]; dispatch_async(dispatch_get_main_queue(), ^{ if ([data.objectType isEqualToString:@"3"]) { self.contentNameLabel.text = [NSString stringWithFormat:@"【原话题】%@",data.contName]; }else{ self.contentNameLabel.text = [NSString stringWithFormat:@"【原新闻】%@",data.contName]; } // self.contentNameLabel.text = data.contName; self.askContentLabel.text = data.content; self.layerView.image = Image(imageStr); self.backView.backgroundColor = backColor; [self layoutSubviews]; }); }); } - (void)setAnswerBO:(commentObjectVO *)data { _answerBO = data; dispatch_async(dispatch_get_main_queue(), ^{ self.answerContentLabel.text = data.content; NSString *praiseNum = data.praiseTimes; if (!isBlankString(praiseNum)) { self.praiseButton.titleText = praiseNum; } if (data.isPraised && [data.isPraised intValue] == 1) { [self.praiseButton setSelect:YES animation:NO]; self.praiseButton.userInteractionEnabled = NO; }else { [self.praiseButton setSelect:NO animation:NO]; self.praiseButton.userInteractionEnabled = NO; } }); } - (void)headButtonClick:(UIButton*)btn { if ([self.delegate respondsToSelector:@selector(titleClick:)]) { [self.delegate titleClick:self.commentBO]; } } - (void)answerDetailClick:(UIButton*)btn { if ([self.delegate respondsToSelector:@selector(popDetailAnswerPage:backColor:)]) { [self.delegate popDetailAnswerPage:self.commentBO backColor:self.backView.backgroundColor]; } } - (void)praiseHandler:(UIButton*)btn { if (btn.selected) { return; } [self.praiseButton setSelected:YES animated:YES];//【需求】点赞动画(bug:4969) NSDictionary *answerDic = self.commentBO.answerList[0]; commentObjectVO *answerBO = setJsonDicToDataModel(answerDic, [commentObjectVO class]); NSDictionary *dic = @{@"commentId":answerBO.commentId}; __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:2000 requestUrl:commentPraiseURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success) { NSString *praseNumStr = responseData[@"praiseTimes"]; if([praseNumStr intValue] <1000){//点赞:点赞超过1K的,几个页面会出现显示不全的现象(bug:5371) Self.praiseButton.textLabel.text = praseNumStr; } Self.answerBO.isPraised = @"1"; Self.answerBO.praiseTimes = Self.praiseButton.textLabel.text; if ([Self.delegate respondsToSelector:@selector(hasPraisedComment:withCommentBO:)]) { [Self.delegate hasPraisedComment:Self.indexPath withCommentBO:Self.answerBO]; } TPLOG(@"点赞成功"); //点赞按钮:点赞按钮点赞后,再次点击异常(bug:5370) Self.praiseButton.userInteractionEnabled = NO; // [Self.praiseButton setSelect:YES animation:YES]; }else { ShowMessage(@"点赞失败", NO); } }]; } - (void)layoutSubviews { viewScale = self.bounds.size.width/300; self.backView.frame = CGRectMake(1, 1, CGRectGetWidth(self.bounds)-2, 215*viewScale-2); self.backImgView.frame = self.backView.bounds; self.itemBorderView.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 215*viewScale); CGFloat contentNameHeight = heightForString(self.contentNameLabel.text, self.contentNameLabel.font, CGRectGetWidth(self.backView.bounds)-30, NSLineBreakByWordWrapping); self.contentNameLabel.frame = CGRectMake(15, 2, CGRectGetWidth(self.backView.bounds)-30, contentNameHeight); self.contentLineView.frame = CGRectMake(0, CGRectGetMaxY(self.contentNameLabel.frame)+3, CGRectGetWidth(self.backView.bounds), 1); self.askContentLabel.frame = CGRectMake(15, CGRectGetMaxY(self.contentLineView.frame), CGRectGetWidth(self.backView.bounds)-30, CGRectGetHeight(self.bounds)-116/2*viewScale-contentNameHeight-3); self.answerContentLabel.frame = CGRectMake(40, CGRectGetMaxY(self.askContentLabel.frame)+2, CGRectGetWidth(self.backView.bounds)-40-15, 116/2*viewScale); self.lineView.frame = CGRectMake(32, CGRectGetMinY(self.answerContentLabel.frame), 1, 116/2*viewScale); [self.answerContentLabel sizeToFit]; UIButton *labelBack = (UIButton*)[self viewWithTag:100]; labelBack.frame = self.contentNameLabel.bounds; UIButton *answerDetailBtn = (UIButton*)[self viewWithTag:101]; answerDetailBtn.frame =CGRectMake(40, CGRectGetMaxY(self.askContentLabel.frame)+2, CGRectGetWidth(self.backView.bounds)-40-15, 116/2*viewScale); self.praiseButton.frame = CGRectMake(0, CGRectGetHeight(self.backView.bounds)-45, 32, 30); self.layerView.frame = CGRectMake(0, CGRectGetHeight(self.backView.bounds)-40*viewScale, CGRectGetWidth(self.backView.bounds), 40*viewScale); self.shadowLine.frame = CGRectMake(0, CGRectGetMinY(self.answerContentLabel.frame)-12, CGRectGetWidth(self.backView.bounds), 13*viewScale); [super layoutSubviews]; } @end