|
//
// otherPersonCell.m
// ThePaperHD
//
// Created by YoungLee on 15/4/27.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "otherPersonCell.h"
#import "TPSelectButton.h"
@interface otherPersonCell(){
CGFloat titleHeight;
CGFloat contentHeight;
}
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UILabel *typeLabel;
@property(nonatomic, strong)UILabel *title;
@property(nonatomic, strong)RTLabel *content;
@property(nonatomic, strong)UILabel *time;
@property(nonatomic, strong)TPSelectButton *praiseButton;
@property(nonatomic, strong)UILabel *praiseText;
@property(nonatomic, strong)UIView *line;
@property(nonatomic, strong)UIButton *pushDetail;
@property(nonatomic, strong)UIButton *pushForward;
@property(nonatomic, strong)UIButton *menuButton;
@property(nonatomic, strong)id otherData;
@end
@implementation otherPersonCell
@synthesize otherData = _otherData;
@synthesize indexPath;
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
//需要呼出自定义菜单
- (BOOL)canBecomeFirstResponder{
[super canBecomeFirstResponder];
return YES;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.clipsToBounds = YES;
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self.contentView addSubview:self.backView];
// [self.backView addSubview:self.typeLabel];
// [self.backView addSubview:self.title];
[self.backView addSubview:self.content];
[self.backView addSubview:self.time];
[self.backView addSubview:self.praiseButton];
[self.backView addSubview:self.praiseText];
[self.backView addSubview:self.line];
[self.backView addSubview:self.pushDetail];
[self.backView addSubview:self.menuButton];
[self.backView addSubview:self.pushForward];
}
return self;
}
-(void)setData:(id)dataSource{
_otherData = dataSource;
if ([dataSource isKindOfClass:[commentObjectVO class]]) {
commentObjectVO *commentBo = dataSource;
self.title.hidden = NO;
self.typeLabel.text = [self setTypeName:commentBo.type];
self.title.text = [self settitleName:commentBo];
self.content.text = commentBo.content;
self.time.text = commentBo.pubTime;
self.praiseText.text = commentBo.praiseTimes;
if ([commentBo.isPraised isEqualToString:@"1"]) {
[self.praiseButton setSelect:YES animation:YES];
self.praiseButton.userInteractionEnabled = NO;
}else{
[self.praiseButton setSelect:NO animation:YES];
self.praiseButton.userInteractionEnabled = YES;
}
}else if([dataSource isKindOfClass:[TopicInfoBO class]]){
TopicInfoBO *topicInfo = dataSource;
self.typeLabel.text = @"话题";
self.praiseText.hidden = NO;
self.praiseButton.hidden = NO;
self.content.text = topicInfo.title;
self.time.text = topicInfo.publishTime;
self.praiseText.text = topicInfo.praiseTimes;
titleHeight = 20;
self.title.hidden = YES;
if ([topicInfo.isPraised isEqualToString:@"1"]) {
[self.praiseButton setSelect:YES animation:YES];
self.praiseButton.userInteractionEnabled = NO;
}else{
[self.praiseButton setSelect:NO animation:YES];
self.praiseButton.userInteractionEnabled = YES;
}
}
// contentHeight = heightForString(self.content.text, appFont(17, NO), 730, NSLineBreakByWordWrapping);
contentHeight = returnTextHeightWithRTLabel(self.content.text, 730, self.content.font, 6);
[self layoutSubviews];
}
//1-跟帖,2-提问,3-回答
-(NSString *) setTypeName:(NSString *) typeStr{
NSString *str;
switch ([typeStr integerValue]) {
case 1:
str = @"评论";
self.praiseText.hidden = NO;
self.praiseButton.hidden = NO;
break;
case 2:
str = @"提问";
self.praiseText.hidden = YES;
self.praiseButton.hidden = YES;
break;
case 3:
str = @"回答";
self.praiseText.hidden = NO;
self.praiseButton.hidden = NO;
break;
default:
break;
}
return str;
}
//1- 新闻 2- 直播栏目 3- 话题
-(NSString*) settitleName:(commentObjectVO *) comment{
NSString *str;
NSString *contName = comment.contName;
NSString *contentName = comment.parent[@"content"];
if([comment.type isEqualToString:@"1"]){//如果是评论,后面只能是原新闻
str = [NSString stringWithFormat:@"【原新闻】%@",contName];
}else if ([comment.type isEqualToString:@"2"]){//如果是提问,后面只有两种:原话题,原新闻
if([comment.objectType isEqualToString:@"3"]){
str = [NSString stringWithFormat:@"【原话题】%@",contName];
}else{
str = [NSString stringWithFormat:@"【原新闻】%@",contName];
}
}else{
str = [NSString stringWithFormat:@"【原提问】%@",contentName];
}
titleHeight = heightForString(str, appFont(TEXT_SIX_LEVELSIZE, NO), 688, NSLineBreakByWordWrapping);
// titleHeight = returnTextHeightWithRTLabel(str, 688, appFont(TEXT_SIX_LEVELSIZE, NO), 2);
if (titleHeight < 20) {
titleHeight = 20;
}
return str;
}
#pragma mark -- view
-(UIView *)backView{
if (!_backView) {
_backView = [[UIView alloc] init];
}
return _backView;
}
-(UILabel *)typeLabel{
if (!_typeLabel) {
_typeLabel = [[UILabel alloc] init];
_typeLabel.backgroundColor = [UIColor colorWithHexString:BLUECOLOR];
_typeLabel.textColor = [UIColor colorWithHexString:BackGroundColor];
_typeLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_typeLabel.textAlignment = NSTextAlignmentCenter;
}
return _typeLabel;
}
-(UILabel *)title{
if (!_title) {
_title = [[UILabel alloc] init];
_title.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
_title.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_title.numberOfLines = 0;
_title.lineBreakMode = NSLineBreakByWordWrapping;
_title.textColor = [UIColor colorWithHexString:TextLightGray];
}
return _title;
}
-(RTLabel *)content{
if (!_content) {
_content = [[RTLabel alloc] init];
_content.font = appFont(TEXT_TWO_LEVELSIZE, NO);
// _content.numberOfLines = 0;
// _content.lineBreakMode = NSLineBreakByWordWrapping;
_content.lineSpacing = 6;
_content.lineBreakMode = RTTextLineBreakModeWordWrapping;
_content.textColor = [UIColor colorWithHexString:TextBlack];
_content.backgroundColor = [UIColor clearColor];
}
return _content;
}
-(UILabel *)time{
if (!_time) {
_time = [[UILabel alloc]init];
_time.font = appFont(12, NO);
_time.textColor = [UIColor colorWithHexString:TextGray];
_time.backgroundColor = [UIColor clearColor];
}
return _time;
}
-(UIButton *)pushDetail{
if (!_pushDetail) {
_pushDetail = [[UIButton alloc] init];
_pushDetail.backgroundColor = [UIColor clearColor];
[_pushDetail addTarget:self action:@selector(pushDetailSelector:) forControlEvents:UIControlEventTouchUpInside];
}
return _pushDetail;
}
- (TPSelectButton*)praiseButton {
if (!_praiseButton) {
_praiseButton = [[TPSelectButton alloc]initWithFrame:CGRectZero
target:self
selector:@selector(praiseEvent:)];
[_praiseButton setBUttonNormalImage:Image(@"detailPage/praise_small.png")
highLightImage:Image(@"detailPage/praise_small_s.png")
selectedImage:Image(@"detailPage/praise_small_s.png")];
_praiseButton.textLabel.font = appFont(11, NO);
_praiseButton.topPadding = 5;
_praiseButton.textLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
_praiseButton.textLabel.hidden = YES;
}
return _praiseButton;
}
-(UILabel *)praiseText{
if (!_praiseText) {
_praiseText = [[UILabel alloc] init];
_praiseText.font = appFont(10, NO);
_praiseText.textColor = [UIColor colorWithHexString:TextGray];
_praiseText.textAlignment = NSTextAlignmentCenter;
_praiseText.backgroundColor = [UIColor clearColor];
}
return _praiseText;
}
-(UIView *)line{
if (!_line) {
_line = [[UIView alloc]init];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
- (UIButton*)menuButton {
if (!_menuButton) {
_menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
_menuButton.backgroundColor = [UIColor clearColor];
[_menuButton addTarget:self action:@selector(menuTap:) forControlEvents:UIControlEventTouchUpInside];
}
return _menuButton;
}
-(UIButton *)pushForward{
if (!_pushForward) {
_pushForward = [[UIButton alloc] init];
_pushForward.backgroundColor = [UIColor clearColor];
[_pushForward addTarget:self action:@selector(pushForwardSelector:) forControlEvents:UIControlEventTouchUpInside];
}
return _pushForward;
}
#pragma mark - menu tap handler
- (void)menuTap:(UIButton*)btn {
[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:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
return;
}
[menu setMenuItems:[NSArray arrayWithObjects:commentBack, copy, praise, nil]];
[menu setTargetRect:self.content.frame inView:self.backView];
[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:))
{
return YES;
}
else
{
return NO;
}
}
- (void)commentBack:(id)sender {
if ([self.otherDelegate respondsToSelector:@selector(commentBackForUser:)]) {
[self.otherDelegate commentBackForUser:(commentObjectVO *)_otherData];
}
}
- (void)copyText:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.content.text;
ShowMessage(@"复制成功", YES);
[MobClick event:@"22"];
}
- (void)praise:(id)sender {
commentObjectVO *comment = (commentObjectVO*) _otherData;
if (self.praiseButton.button.selected) {
return;
}
//个人动态:对评论、回答点出小菜单-点赞,没有点赞动画(bug:6052)
[self.praiseButton setSelected:YES animated:YES];
NSDictionary *dic = @{@"commentId":comment.commentId};
__weak typeof(self) Self = self;
[Remote doJsonActionWithBlock:2000 requestUrl:commentPraiseURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
[MobClick event:@"24"];
NSString *praseNumStr = responseData[@"praiseTimes"];
if([praseNumStr intValue] <1000){//点赞:点赞超过1K的,几个页面会出现显示不全的现象(bug:5371)
Self.praiseButton.textLabel.text = praseNumStr;
Self.praiseText.text = praseNumStr;
}
comment.isPraised = @"1";
comment.praiseTimes = Self.praiseButton.textLabel.text;
if ([Self.otherDelegate respondsToSelector:@selector(hasPraisedComment:withCommentBO:)]) {
[Self.otherDelegate hasPraisedComment:Self.indexPath withCommentBO:comment];
}
TPLOG(@"点赞成功");
//点赞按钮:点赞按钮点赞后,再次点击异常(bug:5370)
Self.praiseButton.userInteractionEnabled = NO;
// [Self.praiseButton setSelect:YES animation:YES];
Self.praiseText.frame = CGRectMake(CGRectGetMinX(Self.praiseButton.frame)-widthForString(Self.praiseText.text, appFont(10, NO), 20, NSLineBreakByWordWrapping)-10, CGRectGetMaxY(Self.content.frame)+10, widthForString(Self.praiseText.text, appFont(10, NO), 20, NSLineBreakByWordWrapping), 20);
}else {
ShowMessage(@"点赞失败", NO);
}
}];
}
- (void)praiseEvent:(UIButton*) btn {
if (self.praiseButton.button.selected) {
return;
}
[self.praiseButton setSelected:YES animated:YES];//【需求】点赞动画(bug:4969)
if ([_otherData isKindOfClass:[TopicInfoBO class]]) {
TopicInfoBO *topic = (TopicInfoBO*)_otherData;
NSDictionary *dic = @{@"topicId":topic.topicId,@"otype":@3};
__weak typeof(self) Self = self;
[Remote doJsonActionWithBlock:2001 requestUrl:optTopicURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
[MobClick event:@"33"];
NSString *praseNumStr = responseData[@"praiseTimes"];
Self.praiseButton.textLabel.text = praseNumStr;
if([praseNumStr intValue] <1000){//点赞:点赞超过1K的,几个页面会出现显示不全的现象(bug:5371)
Self.praiseButton.textLabel.text = praseNumStr;
}
Self.praiseText.text = praseNumStr;
topic.isPraised = @"1";
topic.praiseTimes = praseNumStr;
TPLOG(@"点赞成功");
//点赞按钮:点赞按钮点赞后,再次点击异常(bug:5370)
Self.praiseButton.userInteractionEnabled = NO;
if ([Self.otherDelegate respondsToSelector:@selector(hasPraisedTopic:withCommentBO:)]) {
[Self.otherDelegate hasPraisedTopic:Self.indexPath withCommentBO:topic];
}
// [Self.praiseButton setSelect:YES animation:YES];
Self.praiseText.frame = CGRectMake(CGRectGetMinX(Self.praiseButton.frame)-widthForString(Self.praiseText.text, appFont(10, NO), 20, NSLineBreakByWordWrapping)-10, CGRectGetMaxY(Self.content.frame)+10, widthForString(Self.praiseText.text, appFont(10, NO), 20, NSLineBreakByWordWrapping), 20);
}else {
ShowMessage(@"点赞失败", NO);
}
}];
}else{
commentObjectVO *comment = (commentObjectVO *)_otherData;
NSDictionary *dic = @{@"commentId":((commentObjectVO *)_otherData).commentId};
__weak typeof(self) Self = self;
[Remote doJsonActionWithBlock:2000 requestUrl:commentPraiseURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
[MobClick event:@"24"];
NSString *praseNumStr = responseData[@"praiseTimes"];
if([praseNumStr intValue] <1000){//点赞:点赞超过1K的,几个页面会出现显示不全的现象(bug:5371)
Self.praiseButton.textLabel.text = praseNumStr;
}
Self.praiseText.text = Self.praiseButton.textLabel.text;
comment.isPraised = @"1";
comment.praiseTimes = Self.praiseButton.textLabel.text;
if ([Self.otherDelegate respondsToSelector:@selector(hasPraisedComment:withCommentBO:)]) {
[Self.otherDelegate hasPraisedComment:Self.indexPath withCommentBO:comment];
}
TPLOG(@"点赞成功");
//点赞按钮:点赞按钮点赞后,再次点击异常(bug:5370)
Self.praiseButton.userInteractionEnabled = NO;
// [Self.praiseButton setSelect:YES animation:YES];
Self.praiseText.frame = CGRectMake(CGRectGetMinX(Self.praiseButton.frame)-widthForString(Self.praiseText.text, appFont(10, NO), 20, NSLineBreakByWordWrapping)-10, CGRectGetMaxY(Self.content.frame)+10, widthForString(Self.praiseText.text, appFont(10, NO), 20, NSLineBreakByWordWrapping), 20);
}else {
ShowMessage(@"点赞失败", NO);
}
}];
}
}
-(void) pushDetailSelector:(UIButton *) btn{
if ([self.otherDelegate respondsToSelector:@selector(pushToDetail:)]) {
[self.otherDelegate pushToDetail:_otherData];
}
}
-(void) pushForwardSelector:(UIButton *) btn{
if ([self.otherDelegate respondsToSelector:@selector(pushToForward:)]) {
[self.otherDelegate pushToForward:_otherData];
}
}
-(void)layoutSubviews{
[super layoutSubviews];
self.backView.frame = CGRectMake(CGRectGetWidth(self.bounds)/2-768/2, 0, 768, CGRectGetMaxY(self.contentView.bounds));
// self.typeLabel.frame = CGRectMake(20, 10, 40, titleHeight);
// self.title.frame = CGRectMake(CGRectGetMaxX(self.typeLabel.frame), 10, 688, titleHeight);
//
self.content.frame = CGRectMake(20, 15,730, contentHeight+5);
self.time.frame = CGRectMake(20, CGRectGetMaxY(self.content.frame)+10, 100, 20);
self.praiseButton.frame = CGRectMake(CGRectGetMaxX(self.backView.bounds)-50, CGRectGetMaxY(self.content.frame), 25, 30);
self.praiseText.frame = CGRectMake(CGRectGetMinX(self.praiseButton.frame)-widthForString(self.praiseText.text, appFont(10, NO), 20, NSLineBreakByWordWrapping)-10, CGRectGetMaxY(self.content.frame)+10, widthForString(self.praiseText.text, appFont(10, NO), 20, NSLineBreakByWordWrapping), 20);
self.line.frame = CGRectMake(20, CGRectGetHeight(self.backView.frame)-5, CGRectGetMaxX(self.backView.bounds)-40, 1);
if ([self.typeLabel.text isEqualToString:@"话题"]) {
self.menuButton.hidden = YES;
self.pushForward.hidden = YES;
self.pushDetail.frame = CGRectMake(0, 0, 768, CGRectGetMaxY(self.content.frame));
}else{
self.pushDetail.frame = self.title.frame;
if ([self.typeLabel.text isEqualToString:@"评论"]
|| [self.typeLabel.text isEqualToString:@"回答"]) {
self.pushDetail.frame = self.title.frame;
self.menuButton.frame = CGRectMake(20, CGRectGetMaxY(self.title.frame), CGRectGetMaxX(self.backView.bounds)-40, CGRectGetHeight(self.backView.bounds)-CGRectGetHeight(self.title.frame)-45);
self.pushForward.hidden = YES;
self.menuButton.hidden = NO;
}else{
self.pushForward.hidden = NO;
self.menuButton.hidden = YES;
self.pushDetail.frame = self.title.frame;
self.pushForward.frame = CGRectMake(20, CGRectGetMaxY(self.title.frame), CGRectGetMaxX(self.backView.bounds), CGRectGetHeight(self.backView.bounds)-CGRectGetHeight(self.title.frame));
}
}
}
@end
|