|
//
// hotAnswerContentCell.m
// ThePaperHD
//
// Created by scar1900 on 15/1/28.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "hotAnswerContentCell.h"
#import "AsyncImageView.h"
@interface hotAnswerContentCell(){
NSString *hostId;
}
@property(nonatomic, strong)UIImageView *commentBack;
@property(nonatomic, strong)UILabel *quoNameLable; //楼层用户名
@property(nonatomic, strong)UILabel *quoContentLabel; //楼层内
//@property(nonatomic, strong) NSString *hostId ;
@end
@implementation hotAnswerContentCell
@synthesize commentBO = _commentBO;
@synthesize isHaveCopyMenu = _isHaveCopyMenu;
@synthesize isNeedTizhu = _isNeedTizhu;
@synthesize topicHostId = _topicHostId;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:CardBackGroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.clipsToBounds = YES;
_isNeedTizhu = YES;
// [self addSubview:self.commentBack];
// [self.commentBack addSubview:self.quoNameLable];
// [self.commentBack addSubview:self.quoContentLabel];
[self bringSubviewToFront:self.menuButton];
self.isHaveCopyMenu = YES;
}
return self;
}
- (void)setIsHaveCopyMenu:(BOOL)menu {
_isHaveCopyMenu = menu;
if (menu) {
self.menuButton.hidden = NO;
}else {
self.menuButton.hidden = YES;
}
}
-(void)setIsNeedTizhu:(BOOL)tizhu{
_isNeedTizhu = tizhu;
}
-(void)setTopicHostId:(NSString *)hosId{
_topicHostId = hosId;
}
- (void)setCommentBO:(commentObjectVO *)data {
_commentBO = data;
if (_commentBO.quoteInfo.count > 0) {
self.lineView.hidden = YES;
}else{
self.lineView.hidden = NO;
}
__weak typeof(self) Self = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
userBO *user = setJsonDicToDataModel(data.userInfo, [userBO class]);
NSString *nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@"";
self.answerNameHeight = heightForString(nameStr, self.answerNameLabel.font, 400, self.answerNameLabel.lineBreakMode);
// CGFloat trueContentHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(data.content, 10, appFont(interactionFontSize, NO)), 930/2, appFont(interactionFontSize, NO));
CGFloat trueContentHeight = data.labelHeight;
if (!data.isExpand || [data.isExpand intValue] == 0) {
Self.answerContentHeight = trueContentHeight>interaction4LinesSpace?interaction4LinesSpace:trueContentHeight;
}else {
Self.answerContentHeight = trueContentHeight;
}
NSString *praiseNum = data.praiseTimes;
dispatch_async(dispatch_get_main_queue(), ^{
if ([user.isAuth integerValue] == 1) {//认证用户提问或回答,头像不显示加”V“(bug:4116)
Self.vipImg.hidden = NO;
}else{
Self.vipImg.hidden = YES;
}
Self.headPicImgView.imageUrl = user.pic;
Self.hostLabel.hidden = YES;
Self.answerContentLabel.textColor = [UIColor colorWithHexString:TextGray];
if ([data.objectType isEqualToString:@"3"]){
if ([_topicHostId isEqualToString:user.userId]) {
Self.hostLabel.hidden = NO;
if (Self.indexPath.row==1){
Self.answerContentLabel.textColor = [UIColor colorWithHexString:ANSWERBLUECOLOR];
}
}
}
Self.answerNameLabel.text = nameStr;
Self.answerContentLabel.attributedText = getLineSpaceAttributedString(data.content, 10, appFont(interactionFontSize, NO));
if (trueContentHeight > interaction4LinesSpace) {
Self.expandBtn.hidden = NO;
}else Self.expandBtn.hidden = YES;
// if (data.quoteInfo && data.quoteInfo.allKeys.count>0) {
// NSDictionary *dic = data.quoteInfo;
// commentObjectVO *quoBO = setJsonDicToDataModel(dic, [commentObjectVO class]);
//
// Self.commentBack.hidden = NO;
//
// Self.quoNameLable.text =[NSString stringWithFormat:@"%@:",quoBO.userName];
// Self.quoContentLabel.text = quoBO.content;
// }else {
// Self.commentBack.hidden = YES;
// }
Self.timeLabel.text = data.pubTime;
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 = YES;
}
[Self layoutSubviews];
});
});
}
- (UIImageView*)commentBack {
if (!_commentBack) {
_commentBack = [[UIImageView alloc]initWithImage:Image(@"detailPage/commentBack.png")];
if ([[TPUserDefault instance].isNightMode intValue] > 0) {
_commentBack.image = Image(@"detailPage/commentBack_night.png");
}
_commentBack.userInteractionEnabled = YES;
}
return _commentBack;
}
- (UILabel*)quoNameLable {
if (!_quoNameLable) {
_quoNameLable = [[UILabel alloc]initWithFrame:CGRectZero];
_quoNameLable.textColor = [UIColor colorWithHexString:BLUECOLOR];
_quoNameLable.textAlignment = NSTextAlignmentLeft;
_quoNameLable.font = appFont(12,NO);
_quoNameLable.backgroundColor = [UIColor clearColor];
}
return _quoNameLable;
}
- (UILabel*)quoContentLabel {
if (!_quoContentLabel) {
_quoContentLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_quoContentLabel.textColor = [UIColor colorWithHexString:TextGray];
_quoContentLabel.textAlignment = NSTextAlignmentLeft;
_quoContentLabel.numberOfLines = 2;
_quoContentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_quoContentLabel.font = appFont(interactionFontSize,NO);
_quoContentLabel.backgroundColor = [UIColor clearColor];
}
return _quoContentLabel;
}
- (void)expandEvent:(UIButton*)btn {
if (!self.commentBO.isExpand || [self.commentBO.isExpand intValue] == 0) {
self.commentBO.isExpand = @"1";
}else {
self.commentBO.isExpand = @"0";
}
// CGFloat trueContentHeight= returnTextHeightWithRTLabel(self.commentBO.content, 930/2, appFont(interactionFontSize, NO),10);
CGFloat trueContentHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(self.commentBO.content, 10, appFont(interactionFontSize, NO)), 930/2, appFont(interactionFontSize, NO));
if (expandCell) {
expandCell([self.commentBO.isExpand boolValue],trueContentHeight);
}
}
- (void)layoutSubviews {
[super layoutSubviews];
self.headPicImgView.frame = CGRectMake(90,
15,
35,
35);
//【需求】话题:话题的问答详情页(bug:4315) 35 90改为20
self.vipImg.center = CGPointMake(self.headPicImgView.center.x+15, self.headPicImgView.center.y+12);//认证用户提问或回答,头像不显示加”V“(bug:4116)
CGFloat nameWidth = widthForString(self.answerNameLabel.text, self.answerNameLabel.font, self.answerNameHeight, self.answerNameLabel.lineBreakMode);
self.answerNameLabel.frame = CGRectMake(CGRectGetMaxX(self.headPicImgView.frame)+10,
CGRectGetMinY(self.headPicImgView.frame)+7,
nameWidth,
self.answerNameHeight);
self.answerNameButton.frame = CGRectMake(CGRectGetMinX(self.answerNameLabel.frame)-5, CGRectGetMinY(self.answerNameLabel.frame)-5, nameWidth+10, self.answerNameHeight+10);
self.hostLabel.frame = CGRectMake(CGRectGetMaxX(self.answerNameLabel.frame)+5,CGRectGetMinY(self.answerNameLabel.frame)+ CGRectGetHeight(self.answerNameLabel.frame)/2 - 6, 26, 12);
self.timeLabel.frame = CGRectMake(CGRectGetMinX(self.answerNameLabel.frame),
CGRectGetMaxY(self.answerNameLabel.frame),
100,
16);
//247环境下,时事频道下的第一篇专题的最后一条热追问,点击展开箭头不可正常加载(BUG:4729)
// self.answerContentLabel.frame = CGRectMake(CGRectGetMinX(self.headPicImgView.frame),
// CGRectGetMaxY(self.headPicImgView.frame)+15,
// 930/2,
// self.answerContentHeight);
self.answerContentLabel.frame = CGRectMake(CGRectGetMinX(self.headPicImgView.frame),
CGRectGetMaxY(self.headPicImgView.frame)+15,
930/2,
self.answerContentHeight);
if (!self.commentBO.isExpand || [self.commentBO.isExpand intValue] == 0) {
[self.expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal];
}else {
[self.expandBtn setImage:Image(@"detailPage/expandArrowUp.png") forState:UIControlStateNormal];
}
self.expandBtn.frame = CGRectMake(CGRectGetMinX(self.answerContentLabel.frame),
CGRectGetMaxY(self.answerContentLabel.frame)+4,
CGRectGetWidth(self.answerContentLabel.frame),
30);
[self.expandBtn setImageEdgeInsets:UIEdgeInsetsMake(15-15/2,
CGRectGetWidth(self.expandBtn.frame)/2-13,
15-15/2,
CGRectGetWidth(self.expandBtn.frame)/2-13)];
self.lineView.frame = CGRectMake(CGRectGetMinX(self.answerContentLabel.frame),
CGRectGetHeight(self.bounds)-1,
CGRectGetWidth(self.bounds)-90,
1);
// if (!self.commentBack.hidden) {
// if (self.expandBtn.hidden) {
// self.commentBack.frame =CGRectMake(CGRectGetMinX(self.answerContentLabel.frame),
// CGRectGetMaxY(self.answerContentLabel.frame)+15,
// 951/2,
// 167/2);
// }else {
// self.commentBack.frame =CGRectMake(CGRectGetMinX(self.answerContentLabel.frame),
// CGRectGetMaxY(self.expandBtn.frame)+5,
// 951/2,
// 167/2);
// }
//
// self.quoNameLable.frame = CGRectMake(10, 18, CGRectGetWidth(self.commentBack.frame)-20, 20);
// self.quoContentLabel.frame = CGRectMake(10, CGRectGetMaxY(self.quoNameLable.frame), CGRectGetWidth(self.quoNameLable.frame)-20, 55);
// [self.quoContentLabel sizeToFit];
//
// }else {
// self.commentBack.frame = CGRectZero;
//
// }
//判断menuButton的大小
//【倒退】【互动】:问吧回复;新闻追问回复内容展开按钮无法展开(bug:5959)
if (self.expandBtn.hidden || [self.commentBO.isExpand intValue] == 1) {
self.menuButton.frame = self.answerContentLabel.frame;
}else{
self.menuButton.frame = CGRectMake(CGRectGetMinX(self.headPicImgView.frame),
CGRectGetMaxY(self.answerNameButton.frame)+5,
CGRectGetWidth(self.bounds)-CGRectGetMinX(self.headPicImgView.frame),
interaction4LinesSpace);
}
self.praiseButton.frame = CGRectMake(CGRectGetWidth(self.bounds)-50, CGRectGetMinY(self.headPicImgView.frame), 25, 45);
self.pushInfo.frame = self.headPicImgView.frame;
}
#pragma mark - menu tap handler
- (void)menuTap:(UITapGestureRecognizer*)tap {
[self becomeFirstResponder];
UIMenuItem *commentBack = [[UIMenuItem alloc] initWithTitle:@"回复"action:@selector(commentBack:)];
UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"复制"action:@selector(copyText:)];
UIMenuItem *praise = [[UIMenuItem alloc] initWithTitle:@"点赞"action:@selector(praise:)];
UIMenuItem *delete = [[UIMenuItem alloc] initWithTitle:@"删除"action:@selector(deleteComment:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
return;
}
NSDictionary *userInfo = self.commentBO.userInfo;
userBO *user = setJsonDicToDataModel(userInfo, [userBO class]);
if ([user.userId longLongValue] == [[TPUserDefault instance].userBO.userId longLongValue]) {
[menu setMenuItems:[NSArray arrayWithObjects:delete,commentBack, copy, praise,nil]];
}else {
[menu setMenuItems:[NSArray arrayWithObjects:commentBack, copy, praise, nil]];
}
[menu setTargetRect:self.answerContentLabel.frame inView:self];
[menu setMenuVisible:YES animated:YES];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
[super canPerformAction:action withSender:sender];
if ( action == @selector(commentBack:) || action == @selector(copyText:) || action == @selector(praise:)
|| action == @selector(deleteComment:))
{
return YES;
}
else
{
return NO;
}
}
- (void)commentBack:(id)sender {
if ([self.delegate respondsToSelector:@selector(answerForUserBack: closeHidden:)]) {
[self.delegate answerForUserBack:self.commentBO closeHidden:YES];
}
// if ([self.delegate respondsToSelector:@selector(closeHidden:)]) {
// [self.delegate closeHidden:YES];
// }
}
@end
|