|
//
// myDynamicTableController.m
// ThePaperBase
//
// Created by YoungLee on 15/8/31.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "myDynamicTableController.h"
#import "AsyncImageView.h"
#import "otherPersonModel.h"
#import "otherPersonCell.h"
#import "otherPersonTopicCell.h"
#import "otherPersonNoDataCell.h"
#import "SDWebImageManager.h"
#import "topicContentController.h"
#import "writeCommentAndAskController.h"
#import "TPImageScannerController.h"
#import "Reachability.h"
#import "otherPersonTopCell.h"
#import "otherPersonContentCell.h"
#import "otherPersonPicCell.h"
#import "otherPersonBottomCell.h"
#import "TPEmojiLabel.h"
#import "askDetailController.h"
#import "ImageShareController.h"
#import "imageShareContent.h"
#import "topicDeatilController.h"
#define CONTENTWIDTH rect_screen.size.width - 40
@interface myDynamicTableController ()<otherDelegate,otherPersonCellDelegate,imageScanerDelegate,AnswerContentDelegate,AnswerPicBaseDelegate,msgBottomDelegate>{
CGFloat signHeight;
CGFloat signWidth;
CGFloat nameWidth;
BOOL isCommentSuccess;
NSMutableArray *heightArray;
NSMutableArray *dataArray;
userBO *userbo;
imageShareContent *shareContentView;
}
@property(nonatomic, strong)UILabel *newestLabel;
@property(nonatomic, strong)UIView *topView;
@property(nonatomic, strong)AsyncImageView *userImg;
@property(nonatomic, strong)UIImageView *vImg;
@property(nonatomic, strong)UILabel *userName;
@property(nonatomic, strong)UIImageView *sexImg;
@property(nonatomic, strong)UILabel *sign;
@property(nonatomic, strong)UIButton *gotoPersonInfo;
@property(nonatomic, strong)otherPersonModel *personModel;
@property(nonatomic, strong)writeCommentAndAskController *writeCommentContentVC;
@property(nonatomic, strong)NSMutableArray *dataList;
@property(nonatomic, strong)NSMutableArray *nextDataList;
@property(nonatomic, strong)NSMutableArray *oldArray;
@property(nonatomic, strong)UIView *tableHead;
@end
@implementation myDynamicTableController
static NSString *otherPersonTopCellID = @"otherPersonTopCell";
static NSString *otherPersonContentCellID = @"otherPersonContentCell";
static NSString *otherPersonPicCellID = @"otherPersonPicCell";
static NSString *otherPersonBottomCellID = @"otherPersonBottomCell";
static NSString *haveDataTopCellID = @"otherPersonTopicCell";
static NSString *noDataCellID = @"noDataCellID";
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.tableView.tableHeaderView = self.topView;
self.tableView.clipsToBounds = YES;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
[self.tableView registerClass:[otherPersonNoDataCell class] forCellReuseIdentifier:noDataCellID];
[self.tableView registerClass:[otherPersonTopCell class] forCellReuseIdentifier:otherPersonTopCellID];
[self.tableView registerClass:[otherPersonBottomCell class] forCellReuseIdentifier:otherPersonBottomCellID];
[self.tableView registerClass:[otherPersonContentCell class] forCellReuseIdentifier:otherPersonContentCellID];
[self.tableView registerClass:[otherPersonPicCell class] forCellReuseIdentifier:otherPersonPicCellID];
[self configCanRefresh:YES canLoad:YES];
self.personModel = otherPersonModel.new;
self.personModel.otherDele = self;
[self firstAutoRefreshHandler];
[self getRemote];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
// 个人主页(我的提问,关注的问题,私信等):个人主页(我的提问,关注的问题,私信等)进入原新闻切换成夜间模式返回,显示异常(bug:6153)
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark -- remote
-(void) getRemote{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if (self.commentBo.commentId) {
[dict setObject:self.commentBo.userInfo[@"userId"] forKey:@"uid"];
[dict setObject:self.commentBo.commentId forKey:@"cid"];
}else{
[dict setObject:self.commentBo.userInfo[@"userId"] forKey:@"uid"];
}
self.personModel.dataDict = dict;
}
-(void)pullRefreshHandler{
// [self manualRefresh];
[self getRemote];
}
-(void)pullLoadMoreHander{
if (!self.nextUrl) {
// TPLOG(@"数据有问题,无法获取新数据");
[self loadFailed];
return;
}else{
// self.personModel.oldArray = self.dataList;
self.personModel.nextUrl = self.nextUrl;
}
}
#pragma mark -- click top
- (void)scrollTableViewToTop {
[self.tableView setContentOffset:CGPointZero animated:YES];
}
#pragma mrak -- view
-(UIView *)topView{
if (!_topView) {
_topView = [[UIView alloc] initWithFrame:CGRectMake(0,
0,
rect_screen.size.width,
150)];
_topView.backgroundColor = [UIColor colorWithHexString:BLUECOLOR];
[self.topView addSubview:self.userImg];
[self.topView addSubview:self.vImg];
[self.topView addSubview:self.userName];
[self.topView addSubview:self.sexImg];
[self.topView addSubview:self.sign];
[self.topView addSubview:self.gotoPersonInfo];
[self setTopLayout];
}
return _topView;
}
-(AsyncImageView *)userImg{
if (!_userImg) {
_userImg = [AsyncImageView new];
_userImg.isHaveWaterPrint = NO;
_userImg.clipsToBounds = YES;
_userImg.isHaveWaterPrint = NO;
_userImg.layer.cornerRadius = 25;
_userImg.layer.borderWidth = 1;
_userImg.defaultImage = Image(@"login/loginIcon_s.png");
/**
* bug:5287(打底图问题汇总)
*/
_userImg.layer.borderColor = [UIColor whiteColor].CGColor;
}
return _userImg;
}
-(UIButton *)gotoPersonInfo{
if (!_gotoPersonInfo) {
_gotoPersonInfo = [UIButton buttonWithType:UIButtonTypeCustom];
_gotoPersonInfo.backgroundColor = [UIColor clearColor];
[_gotoPersonInfo addTarget:self action:@selector(gotoPersonInfoSelector:) forControlEvents:UIControlEventTouchUpInside];
}
return _gotoPersonInfo;
}
-(UIImageView *)vImg{
if (!_vImg) {
_vImg = [UIImageView new];
_vImg.image = Image(@"topic/vipVerify.png");
_vImg.layer.cornerRadius = 15/2;
_vImg.layer.borderColor = [UIColor whiteColor].CGColor;
_vImg.layer.borderWidth = 1.5;
}
return _vImg;
}
-(UILabel *)userName{
if (!_userName) {
_userName = [UILabel new];
_userName.textColor = [UIColor whiteColor];
_userName.backgroundColor = [UIColor clearColor];
_userName.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
}
return _userName;
}
-(UIImageView *)sexImg{
if (!_sexImg) {
_sexImg = [UIImageView new];
_sexImg.userInteractionEnabled = YES;
_sexImg.layer.cornerRadius = 6;
_sexImg.layer.borderWidth = 1;
_sexImg.layer.borderColor = [UIColor whiteColor].CGColor;
}
return _sexImg;
}
-(UILabel *)sign{
if (!_sign) {
_sign = [UILabel new];
_sign.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_sign.numberOfLines = 0;
_sign.lineBreakMode = NSLineBreakByWordWrapping;
_sign.textColor = [UIColor whiteColor];
_sign.backgroundColor = [UIColor clearColor];
_sign.textAlignment = NSTextAlignmentLeft;
}
return _sign;
}
-(UIView *)tableHead{
if (!_tableHead) {
_tableHead = [UIView new];
_tableHead.backgroundColor = [UIColor clearColor];
}
return _tableHead;
}
#pragma mark -- layout
-(void) setTopLayout{
[self.userImg makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@50);
make.top.equalTo(@20);
make.height.equalTo(@50);
make.centerX.equalTo(self.topView.centerX);
}];
[self.gotoPersonInfo makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.userImg.left);
make.right.equalTo(self.userImg.right);
make.top.equalTo(self.userImg.top);
make.bottom.equalTo(self.userImg.bottom);
}];
[self.vImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.userImg.right).offset(-13);
make.width.equalTo(@15);
make.bottom.equalTo(self.userImg.bottom);
make.height.equalTo(@15);
}];
[self.userName makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.userImg.centerX);
make.width.mas_equalTo(0);
make.top.equalTo(self.userImg.bottom).offset(10);
make.height.equalTo(@17);
}];
[self.sexImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.userName.right).offset(5);
make.width.equalTo(@12);
make.centerY.equalTo(self.userName.centerY);
make.height.equalTo(@12);
}];
[self.sign makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.topView.left).offset(65);
make.right.equalTo(self.topView.right).offset(-65);
make.top.equalTo(self.userName.bottom).offset(10);
make.height.mas_equalTo(25);
}];
}
-(void) reTopLayout{
[self.userName remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.userImg.centerX);
make.width.mas_equalTo(nameWidth);
make.top.equalTo(self.userImg.bottom).offset(10);
make.height.equalTo(@17);
}];
[self.sign remakeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(signWidth);
make.centerX.equalTo(self.topView.centerX);
make.top.equalTo(self.userName.bottom).offset(10);
make.height.mas_equalTo(signHeight);
}];
}
#pragma mark -- setData List
-(void)setDataList:(NSMutableArray *)list{
_dataList = list;
heightArray = [NSMutableArray array];
dataArray = [NSMutableArray array];
[_dataList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[self orgData:obj];
}];
[self.tableView reloadData];
}
-(void)setNextDataList:(NSMutableArray *)list{
_nextDataList = list;
[_nextDataList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[self orgData:obj];
}];
[self.tableView reloadData];
}
-(void) orgData:(NSMutableDictionary *)obj{
if ([obj[@"objectType"] isEqualToString:@"4"]) {
TopicInfoBO *topicInfo = setJsonDicToDataModel(obj[@"object"], [TopicInfoBO class]);
[dataArray addObject:topicInfo];
CGFloat titleHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topicInfo.title, 6, appFont(TEXT_FOUR_LEVELSIZE, NO)), CONTENTWIDTH, appFont(TEXT_FOUR_LEVELSIZE, NO));
[heightArray addObject:@(titleHeight + 71)];
}else{
commentObjectVO *commentBO = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]);
NSString *topTitle;
if([commentBO.type intValue] == 3){
NSString *name = commentBO.parent[@"content"];
topTitle = [NSString stringWithFormat:@"【原提问】%@",name];
}else{
if([commentBO.objectType intValue] == 3){
topTitle = [NSString stringWithFormat:@"【原话题】%@",commentBO.contName];
}else{
topTitle = [NSString stringWithFormat:@"【原新闻】%@",commentBO.contName];
}
}
CGFloat topHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 3, appFont(TEXT_SIX_LEVELSIZE, NO)), rect_screen.size.width - 40, appFont(TEXT_SIX_LEVELSIZE, NO));
[dataArray addObject:commentBO];
[heightArray addObject:@(topHeight +21)];
commentObjectVO *answerBo = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]);
answerBo.type = @"100";
// answerBo.content = [NSString stringWithFormat:@"%@[心][心][心][心][心][心][心]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]",answerBo.content];
int contentHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:CONTENTWIDTH Text:answerBo.content LineSpace:10 ParagraphSpacing:0];
answerBo.labelHeight = contentHeight;
[dataArray addObject:answerBo];
[heightArray addObject:@(contentHeight + 20)];
// [self rebuildCommentBOInAnswer:obj];
commentObjectVO *bottomBo = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]);
bottomBo.type = @"102";
[dataArray addObject:bottomBo];
[heightArray addObject:@(30)];
}
}
- (void)rebuildCommentBOInAnswer:(NSMutableDictionary *)obj{
commentObjectVO *picComment = setJsonDicToDataModel(obj, [commentObjectVO class]);
imageObjectBO *image1 = [imageObjectBO new];
image1.url = @"http://img1d.xgo-img.com.cn/pics/1503/240/180/1502574.jpg";
image1.width = @"2560";
image1.height = @"1600";
image1.tags = @"1";
imageObjectBO *image2 = [imageObjectBO new];
image2.url = @"http://img1d.xgo-img.com.cn/pics/1503/240/180/1502574.jpg";
image2.width = @"240";
image2.height = @"180";
image2.tags = @"2";
imageObjectBO *image3 = [imageObjectBO new];
image3.url = @"http://ww2.sinaimg.cn/thumb180/68065fcatw1e6ec5iflt3j206x0iodh4.jpg";
image3.width = @"180";
image3.height = @"180";
image3.tags = @"2";
switch (rand()%3) {
case 0:
picComment.imageList = @[image1];
break;
case 1:
picComment.imageList = @[image1,image2];
break;
case 2:
picComment.imageList = @[image1,image2,image3];
break;
default:
break;
}
picComment.type = @"101";
[dataArray addObject:picComment];
if (picComment.imageList.count >0) {
if (picComment.imageList.count == 1) {
imageObjectBO *imageB = picComment.imageList[0];
CGSize imageSize = CGSizeMake([imageB.width floatValue], [imageB.height floatValue]);
CGSize size = CGSizeZero;
if (imageSize.width > CONTENTWIDTH) {
size = CGSizeMake(CONTENTWIDTH, (imageSize.height*CONTENTWIDTH)/imageSize.width);
}else {
size = CGSizeMake([imageB.width floatValue], [imageB.height floatValue]);
}
[heightArray addObject:[NSString stringWithFormat:@"%f",size.height+10]];
}else {
[heightArray addObject:[NSString stringWithFormat:@"%f",quo_pic_width+10]];
}
}
}
#pragma mark - table view delegate and datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return dataArray.count?dataArray.count:0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(dataArray.count >0){
return 30;
}else{
return 0;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
// UIView *secView = [[UIView alloc] init];
// secView.backgroundColor = [UIColor clearColor];
UILabel *headView = [[UILabel alloc] initWithFrame:CGRectMake(0, 10,70, 20)];
headView.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
headView.backgroundColor = [UIColor colorWithHexString:BLUECOLOR];
headView.textColor = [UIColor whiteColor];
headView.text = @"最新动态";
headView.textAlignment = NSTextAlignmentCenter;
headView.lineBreakMode = NSLineBreakByWordWrapping;
[self.tableHead addSubview:headView];
return self.tableHead;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (heightArray.count > 0) {
return [heightArray[indexPath.row] floatValue];
}else{
return CGRectGetHeight(self.tableView.bounds) - CGRectGetHeight(self.tableView.tableHeaderView.bounds);
}
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (dataArray.count>0) {
id data = dataArray[indexPath.row];
if ([data isKindOfClass:[TopicInfoBO class]]) {
return [self haveDateTopicCell:tableView cellForRowAtIndexPath:indexPath];
}else{
commentObjectVO *comentBo = dataArray[indexPath.row];
if ([comentBo.type intValue] == 100) {
return [self getContentCell:tableView cellForRowAtIndexPath:indexPath];
}else if ([comentBo.type intValue] == 102) {
return [self getBottomCell:tableView cellForRowAtIndexPath:indexPath];
}else if ([comentBo.type intValue] == 101) {
return [self getPicCell:tableView cellForRowAtIndexPath:indexPath];
}else{
return [self getTopCell:tableView cellForRowAtIndexPath:indexPath];
}
}
}else{
return [self noDataCell:tableView cellForRowAtIndexPath:indexPath];
}
}
- (otherPersonTopCell*)getTopCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
otherPersonTopCell *cell = [tableView dequeueReusableCellWithIdentifier:otherPersonTopCellID];
if (nil == cell) {
cell = [[otherPersonTopCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:otherPersonTopCellID];
}
cell.comment = dataArray[indexPath.row];
return cell;
}
- (otherPersonContentCell*)getContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
otherPersonContentCell *cell = [tableView dequeueReusableCellWithIdentifier:otherPersonContentCellID];
if (nil == cell) {
cell = [[otherPersonContentCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:otherPersonContentCellID];
}
cell.commentBO = dataArray[indexPath.row];
cell.frontComment = dataArray[indexPath.row - 1];
cell.indexPath = indexPath;
cell.delegate = self;
return cell;
}
- (otherPersonPicCell*)getPicCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
otherPersonPicCell *cell = [tableView dequeueReusableCellWithIdentifier:otherPersonPicCellID];
if (nil == cell) {
cell = [[otherPersonPicCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:otherPersonPicCellID];
}
cell.commentBO = dataArray[indexPath.row];
cell.delegate = self;
return cell;
}
- (otherPersonBottomCell*)getBottomCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
otherPersonBottomCell *cell = [tableView dequeueReusableCellWithIdentifier:otherPersonBottomCellID];
if (nil == cell) {
cell = [[otherPersonBottomCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:otherPersonBottomCellID];
}
cell.comment = dataArray[indexPath.row];
cell.delegate = self;
return cell;
}
- (otherPersonTopicCell*)haveDateTopicCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
otherPersonTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:haveDataTopCellID];
if (nil == cell) {
cell = [[otherPersonTopicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:haveDataTopCellID];
}
cell.user = self.userBo;
cell.topic = dataArray[indexPath.row];
return cell;
}
- (otherPersonNoDataCell*)noDataCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
otherPersonNoDataCell *cell = [tableView dequeueReusableCellWithIdentifier:noDataCellID];
if (nil == cell) {
cell = [[otherPersonNoDataCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:noDataCellID];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[otherPersonTopicCell class]]) {
TopicInfoBO *topic = dataArray[indexPath.row];
topicContentController *vc = topicContentController.new;
vc.preTopicInfo = topic;
[self.navigationController pushViewController:vc animated:YES];
}else if ([cell isKindOfClass:[otherPersonContentCell class]]){
commentObjectVO *comment = dataArray[indexPath.row -1];
if ([comment.type intValue] == 2) {
if ([comment.objectType intValue] == 3) {//话题问答详情页
topicDeatilController *topic = [[topicDeatilController alloc] init];
topic.commentBO = comment;
TopicInfoBO *topicBO = [TopicInfoBO new];
topicBO.topicId = comment.contId;
topic.topicInfo = topicBO;
[self.navigationController pushViewController:topic animated:YES];
}else{
askDetailController *vc = askDetailController.new;
vc.commentBO = comment;
[self.navigationController pushViewController:vc animated:YES];
}
}
}else if ([cell isKindOfClass:[otherPersonTopCell class]]){
commentObjectVO *comment = dataArray[indexPath.row];
if([comment.type intValue] == 3){
if ([comment.objectType intValue] == 3) {//话题问答详情页
topicDeatilController *topic = [[topicDeatilController alloc] init];
topic.commentBO = comment;
TopicInfoBO *topicBO = [TopicInfoBO new];
topicBO.topicId = comment.contId;
topic.topicInfo = topicBO;
[self.navigationController pushViewController:topic animated:YES];
}else{//新闻问答详情页
askDetailController *askDetailVC = [[askDetailController alloc] init];
askDetailVC.commentBO = setJsonDicToDataModel(comment.parent, [commentObjectVO class]);
[self.navigationController pushViewController:askDetailVC animated:YES];
}
}else{
comment.forwordType = comment.objInfo[@"forwordType"];
pushContentWithCommentBO(self.navigationController, comment);
}
}
}
#pragma mark -- cell delegate
-(void)setUserBo:(userBO *)user{
_userBo = user;
}
-(void)praiseHandlerWithIndexPath:(NSIndexPath *)indexPath{
NSIndexPath *index;
commentObjectVO *nextComment = dataArray[indexPath.row +1];
if ([nextComment.type intValue] == 102) {
index = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
}else{
index = [NSIndexPath indexPathForRow:indexPath.row+2 inSection:indexPath.section];
}
otherPersonBottomCell *cell = (otherPersonBottomCell*)[self.tableView cellForRowAtIndexPath:index];
[cell commentOK:cell.okBtn];
}
-(void)hasPraisedComment:(NSIndexPath *)indexPath withCommentBO:(commentObjectVO *)commentBO{
[self.dataList replaceObjectAtIndex:indexPath.row withObject:commentBO];
}
-(void)hasPraisedTopic:(NSIndexPath *)indexPath withCommentBO:(TopicInfoBO *)topic{
[self.dataList replaceObjectAtIndex:indexPath.row withObject:topic];
}
-(void) gotoPersonInfoSelector:(UIButton *)btn{
if ([self.userBo.userId intValue] == [[TPUserDefault instance].userBO.userId intValue]) {
if ([self.delegate respondsToSelector:@selector(gotoLogin:)]) {
[self.delegate gotoLogin:self.userBo];
}
}else{
imageObjectBO *imageBO = imageObjectBO.new;
imageBO.url = self.userBo.pic;
imageBO.width = [NSString stringWithFormat:@"%f",self.userImg.imageView.image.size.width];
imageBO.height = [NSString stringWithFormat:@"%f",self.userImg.imageView.image.size.height];
imageBO.tags = @"WWW";
NSMutableArray *array = [NSMutableArray arrayWithObjects:imageBO, nil];
TPImageScannerController *imageScanner = [[TPImageScannerController alloc]init];
imageScanner.currentIndex = 0;
imageScanner.imageBOList =array;
imageScanner.type = contentImageScannerType;
imageScanner.delegate = self;
[self.navigationController pushViewController:imageScanner animated:YES];
}
}
#pragma mark --------- gotoshare
-(void)gotoShare:(commentObjectVO *)comment index:(NSIndexPath *)index{
ImageShareController *imageShareController = [ImageShareController new];
imageShareController.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
commentObjectVO *frontCom = dataArray[index.row - 1];
NSString *topTitle;
if ([frontCom.objectType intValue] == 3) {
topTitle = [NSString stringWithFormat:@"话题:%@",comment.contName];
}else{
topTitle = [NSString stringWithFormat:@"原新闻:%@",comment.contName];
}
if ([frontCom.type intValue] == 3) {
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.parent[@"content"] LineSpace:6 ParagraphSpacing:0];
CGFloat answerHieght = heightForAttributeStringWithLabel(getLineSpaceAttributedString(comment.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO));
imageShareController.frame = CGRectMake(0, 0, 240, 340+topicHeight+askHeight+answerHieght);
comment.userInfo = setDataModelToDic(self.userBo, [userBO class]);
[imageShareController setAskData:comment answerData:comment hostId:comment.objInfo[@"userId"] topHeight:topicHeight askStr:comment.parent[@"content"] askHeight:askHeight answerStr:comment.content answerHeight:answerHieght];
}else{
CGFloat topicHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 3, appFont(TEXT_SIX_LEVELSIZE, NO)), 170, appFont(TEXT_SIX_LEVELSIZE, NO));
int askHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FIVE_LEVELSIZE, NO) Width:170 Text:comment.content LineSpace:6 ParagraphSpacing:0];
comment.labelHeight = askHeight;
imageShareController.frame = CGRectMake(0, 0, 240, 280+topicHeight+askHeight);
comment.userInfo = setDataModelToDic(self.userBo, [userBO class]);
imageShareController.askData = comment;
}
UIImage* img = [self capture:imageShareController];
if (!img) {
ShowTextMessage(@"图片未完成");
return;
}
// UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
contentObjectBO *dynamicContentBo = [contentObjectBO new];
dynamicContentBo.name = comment.contName;
dynamicContentBo.summary = comment.content;
dynamicContentBo.shareUrl = comment.objInfo[@"shareUrl"];
if ([self.delegate respondsToSelector:@selector(gotoShare:contentBO:)]) {
[self.delegate gotoShare:img contentBO:dynamicContentBo];
}
// }
}
- (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;
}
- (void)imageContentClick:(imageObjectBO*)imageBO {
[self.navigationController popViewControllerAnimated:YES];
// [CoreAnimationEffect animationEaseOut:self.navigationController.view];
}
-(void)pushToAskInfo:(commentObjectVO *)comment{
if ([self.delegate respondsToSelector:@selector(gotoAskInfo:)]) {
[self.delegate gotoAskInfo:comment];
}
}
-(void)pushToDetail:(id)data{
if ([self.delegate respondsToSelector:@selector(gotoDetail:)]) {
[self.delegate gotoDetail:data];
}
}
-(void)gotoCommentWith:(commentObjectVO *)comment{
comment.userInfo = setDataModelToDic(self.userBo, [userBO class]);
if ([TPUserDefault instance].userBO) {
if ([self.delegate respondsToSelector:@selector(gotoCommentWith:)]) {
[self.delegate gotoCommentWith:comment];
}
}else {
// if ([self.delegate respondsToSelector:@selector(gotoLogin)]) {
// [self.delegate gotoLogin];
// }
}
}
- (void) reachabilityChanged:(NSNotification *)note
{
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
NSString *userImgID = getImageNameFromURL(self.userBo.pic);
self.userImg.imageUrl = self.userBo.pic;
self.userImg.imageId = userImgID;
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
self.userImg.imageView.image = Image(@"login/loginIcon_s.png");
}else {
if ([Remote IsEnableWIFI]) {
NSString *userImgID = getImageNameFromURL(self.userBo.pic);
self.userImg.imageUrl = self.userBo.pic;
self.userImg.imageId = userImgID;
}else {
self.userImg.imageView.image = Image(@"login/loginIcon_s.png");
}
}
}
- (void)getContentOffset:(CGPoint)contentOffset {
// 个人动态页,上推名字到顶部的渐变效果需要按照移动距离(bug:5221)
if ([self.delegate respondsToSelector:@selector(setLabel:name:)]) {
[self.delegate setLabel:contentOffset name:self.userBo.sname];
}
}
#pragma mark -- model delegate
-(void)returnDataList:(NSMutableArray *)data nextUrl:(NSString *)url{
self.dataList = data;
self.nextUrl = url;
// [self.tableView reloadData];
[self endRefresh];
}
-(void)returnUserBo:(NSString *)title sname:(NSString *)name imageUrl:(NSString *)url ismale:(BOOL)ismale isAuth:(BOOL)isAuth sign:(NSString *)sign userBo:(userBO *)user{
self.userBo = user;
self.title = title;
self.userName.text = name;
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
NSString *userImgID = getImageNameFromURL(url);
self.userImg.imageUrl = url;
self.userImg.imageId = userImgID;
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
self.userImg.imageView.image = Image(@"login/loginIcon_s.png");
}else {
if ([Remote IsEnableWIFI]) {
NSString *userImgID = getImageNameFromURL(url);
self.userImg.imageUrl = url;
self.userImg.imageId = userImgID;
}else {
self.userImg.imageView.image = Image(@"login/loginIcon_s.png");
}
}
nameWidth = widthForString(self.userName.text, self.userName.font, 14,self.userName.lineBreakMode);
nameWidth = [self.userName sizeThatFits:CGSizeZero].width;
if (ismale) {
self.sexImg.image = Image(@"topic/maleSex.png");
}else{
self.sexImg.image = Image(@"topic/femaleSex.png");
}
if (isAuth) {
self.vImg.hidden = NO;
}else{
self.vImg.hidden = YES;
}
self.sign.text = sign;
signWidth = [self.sign sizeThatFits:CGSizeMake(rect_screen.size.width - 130, 0)].width;
signHeight = heightForString(self.sign.text, self.sign.font, 270, self.sign.lineBreakMode);
[self reTopLayout];
}
-(void)returnNextUrlData:(NSMutableArray *)data nextUrl:(NSString *)url{
self.nextDataList = data;
[self loadSuccess];
self.nextUrl = url;
// [self.tableView reloadData];
}
-(void)returnNoData{
[self endRefresh];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
|