|
//
// commentTableController.m
// ThePaperDemo
//
// Created by scar1900 on 14-9-25.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "commentTableController.h"
//#import "commentSubAnwserCell.h"
//#import "commentActionView.h"
#import "myDynamicController.h"
#import "AnswerContentCommentCell.h"
#import "AnswerIconCommentCell.h"
#import "AnswerQuoCommentCell.h"
#import "ImageShareController.h"
#import "imageShareContent.h"
@interface commentTableController()<UITableViewDataSource,UITableViewDelegate,AnswerContentDelegate,AnswerIconBaseDelegate,AnswerQuoDelegate> {
BOOL isCommentSuccess;
NSMutableArray *listMutableArray;
}
@property(nonatomic, strong)UIView *writeCommentView;
@property(nonatomic, strong)NSMutableArray *cellHeightArray;
@property(nonatomic, strong)UILabel *backLabel;
//@property(nonatomic, strong)commentActionView *commentAction;
@property(nonatomic, strong)writeCommentAndAskController *writeCommentContentVC;
@end
@implementation commentTableController
@synthesize commentList = _commentList;
@synthesize nodeId;
@synthesize delegate;
#pragma mark - load view
- (void)viewDidLoad {
[super viewDidLoad];
[self configCanRefresh:YES canLoad:YES];
listMutableArray = [NSMutableArray array];
[self needNoFirstAutoRefresh];
self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.tableView.frame = CGRectMake(0,
0,
self.view.frame.size.width,
CGRectGetHeight(self.view.frame)-50);
self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
isCommentSuccess = NO;
[self.view addSubview:self.writeCommentView];
[self.view insertSubview:self.writeCommentView aboveSubview:self.tableView];
[self.view addSubview:self.backLabel];
[self.view insertSubview:self.backLabel belowSubview:self.tableView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
- (void)needrefreshNightMode:(id)sender{
self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.writeCommentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
_backLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (UILabel*)backLabel {
if (!_backLabel) {
_backLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)/2-90/2, 125, 90, 35)];
_backLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
_backLabel.textAlignment = NSTextAlignmentCenter;
_backLabel.text = @"评论一下吧";
}
_backLabel.font = appFont(35/2, NO);
return _backLabel;
}
- (UIView*)writeCommentView {
if (!_writeCommentView) {
_writeCommentView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetHeight(self.view.bounds)-50-63, CGRectGetWidth(self.view.bounds), 50)];
_writeCommentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_writeCommentView.bounds), 0.5)];
lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[_writeCommentView addSubview:lineView];
UIImageView *iconView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 20, 20)];
iconView.image = Image(@"detailPage/commentIcon.png");
[_writeCommentView addSubview:iconView];
UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(iconView.frame)+5, CGRectGetWidth(_writeCommentView.bounds)-40, 1)];
lineView1.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[_writeCommentView addSubview:lineView1];
UILabel *textLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(iconView.frame)+15/2, CGRectGetMinY(iconView.frame)+4, 30, 15)];
textLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
textLabel.textColor = [UIColor colorWithHexString:LINECOLOR];
textLabel.textAlignment = NSTextAlignmentLeft;
textLabel.text = @"评论";
[_writeCommentView addSubview:textLabel];
UIButton *writeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
writeBtn.backgroundColor = [UIColor clearColor];
writeBtn.frame = _writeCommentView.bounds;
[writeBtn addTarget:self action:@selector(clickToWrite:) forControlEvents:UIControlEventTouchUpInside];
[_writeCommentView addSubview:writeBtn];
}
return _writeCommentView;
}
- (void)setCommentList:(NSMutableArray *)list {
if (list.count == 1) {
[list insertObject:[NSMutableArray array] atIndex:0];
}
// _commentList = list;
listMutableArray = list;
_commentList = [NSMutableArray array];
self.cellHeightArray = [NSMutableArray array];
if (list.count == 0) {
return;
}
NSMutableArray *commentTempList = [list lastObject]; //新评论
NSMutableArray *hotCommentTempList = [list firstObject];
if (commentTempList.count == 0 && hotCommentTempList.count == 0) {
self.tableView.hidden = YES;
self.backLabel.hidden = NO;
}else {
self.tableView.hidden = NO;
self.backLabel.hidden = YES;
}
NSMutableArray *tempArray = [NSMutableArray array];
NSMutableArray *hotList = [NSMutableArray array];
NSMutableArray *newCommentRowHeightList = [NSMutableArray array];
NSMutableArray *hotCommentRowHeightList = [NSMutableArray array];
if (list.count == 2 && hotCommentTempList.count > 0) { //热评论
// NSMutableArray *hotCommentRowHeightList = [NSMutableArray array];
NSArray *hotCommentList = list[0];
[hotCommentList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) {
NSDictionary *dic = setDataModelToDic(obj, [commentObjectVO class]);
commentObjectVO *anwerBO = setJsonDicToDataModel(dic, [commentObjectVO class]);
anwerBO.type = @"34";
[newCommentRowHeightList addObject:@"60"];
[tempArray addObject:anwerBO];
commentObjectVO *answer = setJsonDicToDataModel(dic, [commentObjectVO class]);
answer.type = @"3";
CGFloat anserHeight = 10;
if (answer.quoteInfo && answer.quoteInfo.allKeys.count>0) {
anserHeight = 0;
}
int anserH = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width-20-20 Text:answer.content LineSpace:10 ParagraphSpacing:0];
answer.labelHeight = anserH;
[tempArray addObject:answer];
anserHeight += anserH;
[newCommentRowHeightList addObject:[NSString stringWithFormat:@"%f",anserHeight]];
if (answer.quoteInfo && answer.quoteInfo.allKeys.count>0) {//假如引用信息(盖楼)
commentObjectVO *quoInfo = setJsonDicToDataModel(answer.quoteInfo, [commentObjectVO class]);
quoInfo.type = @"1";
CGFloat quoHeight = 50/2+15+15;
int quoLabelHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20 - 20 - 16 Text:quoInfo.content LineSpace:10 ParagraphSpacing:0];
quoInfo.labelHeight = quoLabelHeight;
CGFloat twoLine = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE);
if (quoLabelHeight > twoLine && ![quoInfo.isQuoExpand isEqualToString:@"1"]) {
quoLabelHeight = twoLine;
quoHeight += 15;
}
quoHeight += quoLabelHeight;
[tempArray addObject:quoInfo];
[newCommentRowHeightList addObject:[NSString stringWithFormat:@"%f",quoHeight]];
}
}];
[_commentList addObject:tempArray];
[self.cellHeightArray addObject:newCommentRowHeightList];
}
if (commentTempList.count > 0) {
// NSMutableArray *commentRowHeightList = [NSMutableArray array];
NSArray *commentList = [list lastObject];
[commentList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) {
NSDictionary *dic = setDataModelToDic(obj, [commentObjectVO class]);
commentObjectVO *anwerBO = setJsonDicToDataModel(dic, [commentObjectVO class]);
anwerBO.type = @"34";
[hotCommentRowHeightList addObject:@"60"];//
[hotList addObject:anwerBO];
commentObjectVO *answer = setJsonDicToDataModel(dic, [commentObjectVO class]);
answer.type = @"3";
CGFloat anserHeight = 10;
if (answer.quoteInfo && answer.quoteInfo.allKeys.count>0) {
anserHeight = 0;
}
int anserH = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width-20-20 Text:answer.content LineSpace:10 ParagraphSpacing:0];
answer.labelHeight = anserH;
[hotList addObject:answer];
anserHeight += anserH;
[hotCommentRowHeightList addObject:[NSString stringWithFormat:@"%f",anserHeight]];
if (answer.quoteInfo && answer.quoteInfo.allKeys.count>0) {//假如引用信息(盖楼)
commentObjectVO *quoInfo = setJsonDicToDataModel(answer.quoteInfo, [commentObjectVO class]);
quoInfo.type = @"1";
CGFloat quoHeight = 50/2+15+15;
int quoLabelHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20 - 20 - 16 Text:quoInfo.content LineSpace:10 ParagraphSpacing:0];
quoInfo.labelHeight = quoLabelHeight;
if (quoLabelHeight > getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE) && ![quoInfo.isQuoExpand isEqualToString:@"1"]) {
quoLabelHeight = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE);
quoHeight += 15;
}
quoHeight += quoLabelHeight;
[hotList addObject:quoInfo];
[hotCommentRowHeightList addObject:[NSString stringWithFormat:@"%f",quoHeight]];
}
}];
[_commentList addObject:hotList];
[self.cellHeightArray addObject:hotCommentRowHeightList];
}
[self.tableView reloadData];
}
#pragma mark UITableViewDelegate and UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSMutableArray *commentTempList = [listMutableArray lastObject];
NSMutableArray *hotCommentTempList = [listMutableArray firstObject];
if (commentTempList.count > 0 && hotCommentTempList.count > 0) {
return 2;
}else if (commentTempList.count == 0 && hotCommentTempList.count > 0) {
return 1;
}else if (commentTempList.count > 0 && hotCommentTempList.count == 0) {
return 1;
}else return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *commentList = self.cellHeightArray[section];
return commentList.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *heightList = self.cellHeightArray[indexPath.section];
return heightList ? [heightList[indexPath.row] floatValue]:0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (self.commentList.count == 2 && self.cellHeightArray.count == 2) {
return 30;
}else if (self.commentList.count == 2 && self.cellHeightArray.count == 1) {
NSMutableArray *commentTempList = [listMutableArray lastObject];
if (commentTempList.count == 0) {
return 30;
}else return 0.f;
}else return 0.f;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (self.commentList.count == 2) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 30)];
view.backgroundColor = [UIColor clearColor];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 56, 20)];
label.textAlignment = NSTextAlignmentCenter;
label.font = appFont(13, NO);
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithHexString:BLUECOLOR];
[view addSubview:label];
NSMutableArray *commentTempList = [self.commentList lastObject];
NSMutableArray *hotCommentTempList = [self.commentList firstObject];
if (section == 0) {
if (hotCommentTempList.count >0 ) {
label.text = @"热评论";
}else if (hotCommentTempList.count == 0 && commentTempList.count >0) {
label.text = @"新评论";
}else return nil;
}else {
if (commentTempList.count == 0) {
return nil;
}
label.text = @"新评论";
}
return view;
}else {
return nil;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *sectionArray = self.commentList[indexPath.section];
commentObjectVO *comment = sectionArray[indexPath.row];
switch ([comment.type integerValue]) {
case 1://跟帖
return [self returnAnswerQuoTable:tableView cellForRowAtIndexPath:indexPath];
break;
case 3://回答
return [self returnAnswerContentTableTable:tableView cellForRowAtIndexPath:indexPath];
break;
case 34://回答头像
return [self returnAnswerIconTable:tableView cellForRowAtIndexPath:indexPath];
break;
default:
break;
}
return nil;
}
- (AnswerIconCommentCell *)returnAnswerIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AnswerIconBaseCellId";
AnswerIconCommentCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AnswerIconCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSArray *sectionArray = self.commentList[index.section];
commentObjectVO *comment = sectionArray[index.row];
cell.commentBO = comment;
cell.delegate = self;
return cell;
}
- (AnswerContentCommentCell *)returnAnswerContentTableTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AnswerContentBaseCellId";
AnswerContentCommentCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AnswerContentCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSArray *sectionArray = self.commentList[index.section];
commentObjectVO *comment = sectionArray[index.row];
cell.commentBO = comment;
cell.indexPath = index;
cell.delegate = self;
return cell;
}
- (AnswerQuoCommentCell *)returnAnswerQuoTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AnswerQuoBaseCellId";
AnswerQuoCommentCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AnswerQuoCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSArray *sectionArray = self.commentList[index.section];
commentObjectVO *comment = sectionArray[index.row];
cell.isComment = YES;
cell.commentBO = comment;
cell.delegate = self;
__block NSIndexPath *IndexPath = index;
__weak typeof(self) Self = self;
[cell quoBlock:^(BOOL isQuoExpand, CGFloat quoHeight) {
CGFloat backY = [cell.quoContentLabel convertRect:cell.quoContentLabel.bounds toView:KEY_WINDOW].origin.y-64;
if (isQuoExpand) {
[MobClick event:@"85"];
quoHeight = quoHeight+50/2+15+15;
if (cell.commentBO.imageList.count > 0) {
quoHeight += quo_pic_width+15/2;
}
NSMutableArray *sectionArray = Self.cellHeightArray[IndexPath.section];
[sectionArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]];
[Self.cellHeightArray replaceObjectAtIndex:IndexPath.section withObject:sectionArray];
NSIndexPath *lastIndex1 = [NSIndexPath indexPathForRow:IndexPath.row-2 inSection:IndexPath.section];
NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:IndexPath.row-1 inSection:IndexPath.section];
NSArray *array = @[IndexPath,lastIndex,lastIndex1];
[Self.tableView beginUpdates];
[Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[Self.tableView endUpdates];
}else {
quoHeight = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE)+50/2+15+15+15;
if (cell.commentBO.imageList.count > 0) {
quoHeight += quo_pic_width+15/2;
}
NSMutableArray *sectionArray = Self.cellHeightArray[IndexPath.section];
[sectionArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]];
[Self.cellHeightArray replaceObjectAtIndex:IndexPath.section withObject:sectionArray];
NSIndexPath *lastIndex1 = [NSIndexPath indexPathForRow:IndexPath.row-2 inSection:IndexPath.section];
NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:IndexPath.row-1 inSection:IndexPath.section];
NSArray *array = @[IndexPath,lastIndex,lastIndex1];
[Self.tableView beginUpdates];
[Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[Self.tableView endUpdates];
if (backY < 0) {
[Self.tableView beginUpdates];
[Self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
[Self.tableView endUpdates];
}
}
}];
return cell;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
return;
}
}
#pragma mark - TPTableView delegate
- (void)pullRefreshHandler {
NSDictionary *dic = @{@"c":self.nodeId};
[Remote doJsonAction:1
requestUrl:contentCommentURL
parameter:dic
delegate:self];
}
- (void)pullLoadMoreHander {
[Remote doJsonAction:2
requestUrl:self.nextUrl
parameter:nil
delegate:self];
}
#pragma mark - remote delegate
- (void)startWaitCursor:(int)actionTag {
}
- (void)stopWaitCursor:(int)actionTag {
}
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData {
if (actionTag == 1) {
if (responsData[@"commentList"]) {
NSMutableArray *commentList = [NSMutableArray array];
NSMutableArray *tempArray = [NSMutableArray array];
NSMutableArray *hotList = [NSMutableArray array];
NSArray *list = responsData[@"commentList"];
[list enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]);
commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO);
[tempArray addObject:commentBO];
}];
NSArray *hotTempList = responsData[@"hotList"];
NSString *total = responsData[@"recordTotal"];
if ([self.delegate respondsToSelector:@selector(reflashNumsWithCount:)]) {
[self.delegate reflashNumsWithCount:total];
}
/**
* bug:5021(新闻详情页互动列表,发表了评论、提问、回答后,相应的评论和追问数字没有增加)
*/
[hotTempList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]);
commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO);
[hotList addObject:commentBO];
}];
if (hotList.count > 0) {
[commentList addObject:hotList];
}
[commentList addObject:tempArray];
self.commentList = commentList;
NSString *url = responsData[@"nextUrl"];
self.nextUrl = url;
}
[self endRefresh];
[self.tableView setContentOffset:CGPointMake(0, 1)];
if (isCommentSuccess) {
NSArray *hotTempList = responsData[@"hotList"];
if (hotTempList.count > 0) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]
atScrollPosition:UITableViewScrollPositionTop
animated:YES];
}
isCommentSuccess = NO;
}
// NSString *record = responsData[@"recordTotal"];
// if ([self.delegate respondsToSelector:@selector(endCommentRefresh:)]) {
// [self.delegate endCommentRefresh:record];
// }
}else {
NSMutableArray *tempCommentList= [NSMutableArray arrayWithArray:listMutableArray];
NSMutableArray *commentList = [tempCommentList lastObject];
NSMutableArray *tempArray = [NSMutableArray array];
NSArray *list = responsData[@"commentList"];
[list enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]);
commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO);
[tempArray addObject:commentBO];
}];
[commentList addObjectsFromArray:tempArray];
if (tempCommentList.count == 2) {
[tempCommentList replaceObjectAtIndex:1 withObject:commentList];
}else {
[tempCommentList replaceObjectAtIndex:0 withObject:commentList];
}
self.commentList = tempCommentList;
// NSMutableArray *indexArray = [NSMutableArray array];
// for (int i = tempCommentList.count;i<self.dataList.count;i++) {
// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
// [indexArray addObject:indexPath];
// }
// [self.tableView insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
[self loadSuccess];
NSString *url = responsData[@"nextUrl"];
self.nextUrl = url;
}
}
#pragma mark - write content delegate
- (void)commentSuccess:(commentAndAskType)type {
self.writeCommentContentVC = nil;
isCommentSuccess = YES;
[self manualRefresh];
}
- (void)praiseHandlerWithIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *index = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:indexPath.section];
AnswerIconBaseCell *cell = (AnswerIconBaseCell *)[self.tableView cellForRowAtIndexPath:index];
[cell commentOK:cell.OkButton];
if (cell == nil) {
NSArray *sectionArray = self.commentList[index.section];
commentObjectVO *obj = sectionArray[index.row];
if (obj.isPraised.intValue == 1) {
return;
}
NSDictionary *dic = @{@"commentId":obj.commentId};
[Remote doJsonActionWithBlock:2000 requestUrl:commentPraiseURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
[MobClick event:@"24"];
if ([responseData[@"praiseTimes"] integerValue] < 1001) {
NSString *praseNum = [NSString stringWithFormat:@"%@",responseData[@"praiseTimes"]];
obj.praiseTimes = praseNum;
TPLOG(@"点赞成功");
}
obj.isPraised = @"1";
TPLOG(@"点赞成功");
}else {
TPLOG(@"点赞失败");
}
}];
}
}
- (void)gotoCommentWith:(commentObjectVO *)comment {
if ([TPUserDefault instance].userBO) {
[MobClick event:@"37"];
if ([self.delegate respondsToSelector:@selector(presentWriteToUser:)]) {
[self.delegate presentWriteToUser:comment];
}
}else {
if ([self.delegate respondsToSelector:@selector(commentPushToLoginView)]) {
[self.delegate commentPushToLoginView];
}
}
}
- (void)gotoUserInfo:(commentObjectVO *)comment {
[(TPWindow*)KEY_WINDOW closeAndSotoEmbeddedVideo];
if (![comment.userInfo[@"userId"] isEqualToString:[TPUserDefault instance].userBO.userId]) {
myDynamicController *dynamicVC = [myDynamicController new];
dynamicVC.comment = comment;
[self.navigationController pushViewController:dynamicVC animated:YES];
}else{
}
}
#pragma mark --------- gotoshare
-(void)gotoShare:(commentObjectVO *)comment index:(NSIndexPath *)index{
ImageShareController *imageShareController = [ImageShareController new];
imageShareController.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
NSString *topTitle;
if ([comment.objectType intValue] == 3) {
topTitle = [NSString stringWithFormat:@"话题:%@",comment.contName];
}else{
topTitle = [NSString stringWithFormat:@"原新闻:%@",comment.contName];
}
CGFloat topicHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 3, appFont(TEXT_SIX_LEVELSIZE, NO)), 160, appFont(TEXT_SIX_LEVELSIZE, NO));
// int askHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FIVE_LEVELSIZE, NO) Width:170 Text:comment.content LineSpace:6 ParagraphSpacing:0];
CGFloat askHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(comment.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO));
comment.labelHeight = askHeight;
imageShareController.frame = CGRectMake(0, 0, 240, 280+topicHeight+askHeight);
imageShareController.askData = comment;
UIImage* img = [self capture:imageShareController];
if (!img) {
ShowTextMessage(@"图片未完成");
return;
}
// UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
contentObjectBO *contentBO = [contentObjectBO new];
contentBO.name = comment.contName;
contentBO.summary = comment.content;
contentBO.shareUrl = comment.objInfo[@"shareUrl"];
if ([self.delegate respondsToSelector:@selector(commentToShare:contentBO:)]) {
[self.delegate commentToShare:img contentBO:contentBO];
}
}
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
NSString *msg = nil ;
// if(error != NULL){
// msg = @"保存图片失败" ;
// }else{
// msg = @"已保存至相册" ;
// }
ShowTextMessage(msg);
}
- (UIImage *)capture:(ImageShareController*)view
{
if ([view isKindOfClass:[UIImageView class]]) {
return ((UIImageView*)view).image;
}
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
#pragma mark - write handler
- (void)clickToWrite:(UIButton*)btn {
if ([TPUserDefault instance].userBO) {
[MobClick event:@"34"];
if ([self.delegate respondsToSelector:@selector(presentWriteContent)]) {
((MLNavigationController *)self.navigationController).canDragBack = NO;
[self.delegate presentWriteContent];
}
}else {
if ([self.delegate respondsToSelector:@selector(commentPushToLoginView)]) {
[self.delegate commentPushToLoginView];
}
}
}
- (void)deleteCommentSuccess {
[self manualRefresh];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
|