WeiboCell.m 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. //
  2. // WeiboCell.m
  3. // wq
  4. //
  5. // Created by weqia on 13-8-28.
  6. // Copyright (c) 2013年 Weqia. All rights reserved.
  7. //
  8. #import "WeiboCell.h"
  9. #import "UIImageView+HBHttpCache.h"
  10. #import "TimeUtil.h"
  11. #import <QuartzCore/QuartzCore.h>
  12. #import "NSStrUtil.h"
  13. #import "ObjUrlData.h"
  14. //#import "userInfoVC.h"
  15. #import "JXUserInfoVC.h"
  16. #import "UIImageView+FileType.h"
  17. #import "JXLikeListViewController.h"
  18. #import "UILabel+YBAttributeTextTapAction.h"
  19. #import "ImageResize.h"
  20. #import "JXGoogleMapVC.h"
  21. #import "JXMapData.h"
  22. #define ICON_WIDTH (JX_SCREEN_WIDTH - 25*3)/4 // 点赞回复等按钮之前的距离
  23. @interface WeiboCell ()<HBCoreLabelDelegate,YBAttributeTapActionDelegate>
  24. {
  25. // MPMoviePlayerController* _player;
  26. }
  27. @property (nonatomic, strong) UIView *shareView;
  28. @property (nonatomic, strong) JXImageView *shareIcon;
  29. @property (nonatomic, strong) UILabel *shareTitle;
  30. @property (nonatomic, assign) int delInt;
  31. @end
  32. @implementation WeiboCell
  33. @synthesize tableViewP,title,content,imageContent,fileView,time,delBtn,locLabel,mLogo,replyContent,btnDelete,btnReply,btnShare,back,tableReply,lockView,refreshCount,weibo;
  34. @synthesize pauseBtn;
  35. @synthesize imagePlayer;
  36. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  37. {
  38. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  39. if (self) {
  40. _pool = [[NSMutableArray alloc]init];
  41. self.selectionStyle = UITableViewCellSelectionStyleNone;
  42. mLogo = [[JXImageView alloc]initWithFrame:CGRectMake(15,14,42,42)];
  43. mLogo.delegate = self;
  44. mLogo.didTouch = @selector(actionUser:);
  45. mLogo.layer.cornerRadius = mLogo.frame.size.width / 2;
  46. mLogo.layer.masksToBounds = YES;
  47. [self.contentView addSubview:mLogo];
  48. CGFloat X = CGRectGetMaxX(mLogo.frame)+10;
  49. title = [[UILabel alloc] initWithFrame:CGRectMake(X, 16, JX_SCREEN_WIDTH - 114, 19)];
  50. title.text = Localized(@"WeiboCell_Star");
  51. title.textColor = HEXCOLOR(0x576b95);
  52. [self.contentView addSubview:title];
  53. //时间
  54. time = [[UILabel alloc]initWithFrame:CGRectMake(X,CGRectGetMaxY(title.frame)+8,40,13)];
  55. time.textColor = HEXCOLOR(0x999999);
  56. time.font = [UIFont systemFontOfSize:12];
  57. delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  58. [delBtn setTitle:Localized(@"JX_Delete") forState:UIControlStateNormal];
  59. [delBtn setTitle:Localized(@"JX_Delete") forState:UIControlStateHighlighted];
  60. [delBtn setTitleColor:HEXCOLOR(0x576b95) forState:UIControlStateNormal];
  61. [delBtn setTitleColor:HEXCOLOR(0x576b95) forState:UIControlStateHighlighted];
  62. delBtn.titleLabel.font = g_factory.font12;
  63. delBtn.tag = self.tag;
  64. delBtn.hidden = YES;
  65. [delBtn addTarget:self action:@selector(delBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  66. //说说文本
  67. content = [[HBCoreLabel alloc]initWithFrame:CGRectMake(X, CGRectGetMaxY(mLogo.frame)+11, JX_SCREEN_WIDTH - X-15, 21)];
  68. content.delegate = self;
  69. content.textColor = HEXCOLOR(0x323232);
  70. [self.contentView addSubview:content];
  71. imageContent = [[UIView alloc]initWithFrame:CGRectMake(X, CGRectGetMaxY(mLogo.frame)+11, JX_SCREEN_WIDTH - X*2, 21)];
  72. [self.contentView addSubview:imageContent];
  73. _audioPlayer = [[JXAudioPlayer alloc]initWithParent:self.imageContent frame:CGRectNull isLeft:YES];
  74. _audioPlayer.isOpenProximityMonitoring = YES;
  75. fileView = [[UIView alloc] initWithFrame:CGRectMake(X, 40, JX_SCREEN_WIDTH -100, 100)];
  76. // fileView.backgroundColor = [UIColor redColor];
  77. // fileView.layer.borderWidth = 0.5f;
  78. // fileView.layer.borderColor = [UIColor lightGrayColor].CGColor;
  79. fileView.backgroundColor = HEXCOLOR(0xF2F2F2);
  80. UITapGestureRecognizer * tapges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fileUrlCopy)];
  81. [fileView addGestureRecognizer:tapges];
  82. [self.contentView addSubview:fileView];
  83. fileView.hidden = YES;
  84. if(!_typeView){
  85. _typeView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 60, 60)];
  86. _typeView.layer.cornerRadius = 3;
  87. _typeView.layer.masksToBounds = YES;
  88. // _typeView.backgroundColor = [UIColor redColor];
  89. [fileView addSubview:_typeView];
  90. }
  91. if(!_fileTitleLabel){
  92. _fileTitleLabel = [UIFactory createLabelWith:CGRectZero text:@"--.--" font:g_factory.font15 textColor:[UIColor blackColor] backgroundColor:[UIColor clearColor]];
  93. _fileTitleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
  94. _fileTitleLabel.frame = CGRectMake(CGRectGetMaxX(_typeView.frame) +5, 0, CGRectGetWidth(fileView.frame)-CGRectGetMaxX(_typeView.frame)-5-5, 25);
  95. _fileTitleLabel.center = CGPointMake(_fileTitleLabel.center.x, _typeView.center.y);
  96. _fileTitleLabel.textAlignment = NSTextAlignmentLeft;
  97. [fileView addSubview:_fileTitleLabel];
  98. }
  99. [self createShareView];
  100. replyContent = [[UIView alloc]initWithFrame:CGRectMake(X,CGRectGetMaxY(mLogo.frame)+11,JX_SCREEN_WIDTH -X-15,30)];
  101. replyContent.backgroundColor = [UIColor clearColor];
  102. [self.contentView addSubview:replyContent];
  103. locLabel = [UIFactory createLabelWith:CGRectZero text:nil font:g_factory.font11 textColor:HEXCOLOR(0x576b95) backgroundColor:[UIColor clearColor]];
  104. locLabel.frame = CGRectMake(15, CGRectGetMaxY(replyContent.frame)+12, JX_SCREEN_WIDTH -70, 14);
  105. locLabel.hidden = YES;
  106. locLabel.userInteractionEnabled = YES;
  107. [self.contentView addSubview:locLabel];
  108. UITapGestureRecognizer *locTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onLoction)];
  109. [locLabel addGestureRecognizer:locTap];
  110. tableReply = [[UITableView alloc]initWithFrame:CGRectMake(0,31,JX_SCREEN_WIDTH -75,0)];
  111. tableReply.dataSource = self;
  112. tableReply.delegate = self;
  113. tableReply.tag = self.tag;
  114. tableReply.backgroundColor = [UIColor clearColor];
  115. tableReply.separatorStyle = UITableViewCellSeparatorStyleNone;
  116. _moreLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableReply.frame.size.width, 23)];
  117. _moreLabel.backgroundColor = [UIColor clearColor];
  118. _moreLabel.textAlignment = NSTextAlignmentCenter;
  119. _moreLabel.font = SYSFONT(13);
  120. _moreLabel.text=Localized(@"JX_SeeMoreComments");
  121. _moreLabel.userInteractionEnabled=YES;
  122. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getMoreData)];
  123. [_moreLabel addGestureRecognizer:tap];
  124. tableReply.tableFooterView = _moreLabel;
  125. //举报按钮
  126. _btnReport = [UIButton buttonWithType:UIButtonTypeCustom];
  127. _btnReport.frame = CGRectMake(JX_SCREEN_WIDTH -15-25,15,25,25);
  128. [_btnReport setImage:[UIImage imageNamed:@"weibo_report"] forState:UIControlStateNormal];
  129. [_btnReport setImage:[UIImage imageNamed:@"weibo_reported"] forState:UIControlStateHighlighted];
  130. _btnReport.tag = self.tag*1000+4;
  131. [_btnReport addTarget:self action:@selector(btnReply:) forControlEvents:UIControlEventTouchUpInside];
  132. //收藏按钮
  133. _btnCollection = [UIButton buttonWithType:UIButtonTypeCustom];
  134. [_btnCollection setImage:[UIImage imageNamed:@"weibo_collection"] forState:UIControlStateNormal];
  135. [_btnCollection setImage:[UIImage imageNamed:@"weibo_collected"] forState:UIControlStateHighlighted];
  136. [_btnCollection setImage:[UIImage imageNamed:@"weibo_collected"] forState:UIControlStateSelected];
  137. _btnCollection.tag = self.tag*1000+3;
  138. [_btnCollection addTarget:self action:@selector(btnReply:) forControlEvents:UIControlEventTouchUpInside];
  139. //回复按钮
  140. btnReply = [UIButton buttonWithType:UIButtonTypeCustom];
  141. [btnReply setTitleColor:HEXCOLOR(0x556b95) forState:UIControlStateNormal];
  142. [btnReply.titleLabel setFont:SYSFONT(13)];
  143. [btnReply setImage:[UIImage imageNamed:@"weibo_comment"] forState:UIControlStateNormal];
  144. [btnReply setImage:[UIImage imageNamed:@"weibo_commented"] forState:UIControlStateHighlighted];
  145. btnReply.tag = self.tag*1000+2;
  146. [btnReply setTitleEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
  147. [btnReply setImageEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 0)];
  148. [btnReply addTarget:self action:@selector(btnReply:) forControlEvents:UIControlEventTouchUpInside];
  149. //点赞,回复按钮
  150. _btnLike = [UIButton buttonWithType:UIButtonTypeCustom];
  151. [_btnLike setTitleColor:HEXCOLOR(0x556b95) forState:UIControlStateNormal];
  152. [_btnLike.titleLabel setFont:SYSFONT(13)];
  153. [_btnLike setImage:[UIImage imageNamed:@"weibo_thumb"] forState:UIControlStateNormal];
  154. [_btnLike setImage:[UIImage imageNamed:@"weibo_thumbed"] forState:UIControlStateHighlighted];
  155. [_btnLike setImage:[UIImage imageNamed:@"weibo_thumbed"] forState:UIControlStateSelected];
  156. [_btnLike setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
  157. _btnLike.tag = self.tag*1000+1;
  158. [_btnLike addTarget:self action:@selector(btnReply:) forControlEvents:UIControlEventTouchUpInside];
  159. //回复区背景图
  160. back = [[UIImageView alloc]initWithFrame:CGRectMake(0,25,replyContent.frame.size.width,0)];
  161. back.image = [[[UIImage imageNamed:@"AlbumTriangleB"] imageWithTintColor:HEXCOLOR(0xF2F2F2)] stretchableImageWithLeftCapWidth:30 topCapHeight:30];
  162. back.userInteractionEnabled = YES;
  163. [self.contentView addSubview:_btnReport];
  164. [self.contentView addSubview:time];
  165. [self.contentView addSubview:delBtn];
  166. [replyContent addSubview:btnReply];
  167. [replyContent addSubview:_btnLike];
  168. [replyContent addSubview:_btnCollection];
  169. [replyContent addSubview:back];
  170. [replyContent addSubview:tableReply];
  171. }
  172. return self;
  173. }
  174. - (void)createShareView {
  175. if (!_shareView) {
  176. _shareView = [[UIView alloc] initWithFrame:CGRectMake(57, 25, JX_SCREEN_WIDTH - 100, 70)];
  177. _shareView.backgroundColor = HEXCOLOR(0xf0f0f0);
  178. _shareView.hidden = YES;
  179. UITapGestureRecognizer * tapges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shareUrlAction)];
  180. [_shareView addGestureRecognizer:tapges];
  181. [self.contentView addSubview:_shareView];
  182. _shareIcon = [[JXImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
  183. // imageView.image = [UIImage imageNamed:@"ALOGO_1200"];
  184. [_shareIcon sd_setImageWithURL:[NSURL URLWithString:weibo.sdkIcon] placeholderImage:[UIImage imageNamed:@"ALOGO_1200"]];
  185. [_shareView addSubview:_shareIcon];
  186. _shareTitle = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_shareIcon.frame) + 5, _shareIcon.frame.origin.y, _shareView.frame.size.width - CGRectGetMaxX(_shareIcon.frame) - 15, _shareIcon.frame.size.height)];
  187. _shareTitle.numberOfLines = 0;
  188. // label.text = @"哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈";
  189. _shareTitle.text = weibo.sdkTitle;
  190. _shareTitle.font = [UIFont systemFontOfSize:14.0];
  191. [_shareView addSubview:_shareTitle];
  192. }
  193. }
  194. - (void)shareUrlAction {
  195. if (self.delegate && [self.delegate respondsToSelector:@selector(weiboCell:shareUrlActionWithUrl:title:)]) {
  196. [self.delegate weiboCell:self shareUrlActionWithUrl:weibo.sdkUrl title:weibo.sdkTitle];
  197. }
  198. }
  199. - (void)setupData {
  200. btnReply.frame = CGRectMake(0,0,60,25);
  201. _btnCollection.frame = CGRectMake(JX_SCREEN_WIDTH/2-67,0,25,25);
  202. _btnLike.frame = CGRectMake(back.frame.size.width-67-25,0,60,25);
  203. if ([weibo.userId isEqualToString:MY_USER_ID]) {
  204. _btnReport.hidden = YES;
  205. }else {
  206. _btnReport.hidden = NO;
  207. }
  208. [_btnLike setTitle:[self getMaxValue:weibo.praiseCount] forState:UIControlStateNormal];
  209. [btnReply setTitle:[self getMaxValue:weibo.commentCount] forState:UIControlStateNormal];
  210. }
  211. - (NSString *)getMaxValue:(int)value {
  212. NSString *str = [NSString string];
  213. if (value > 99) {
  214. str = @"99+";
  215. }else {
  216. str = [NSString stringWithFormat:@"%d",value];
  217. }
  218. return str;
  219. }
  220. //复制信息到剪贴板
  221. - (void)fileUrlCopy{
  222. [self.controller fileAction:weibo];
  223. // ObjUrlData * url= [weibo.files firstObject];
  224. // if (url.url.length >0) {
  225. // UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  226. // [pasteboard setString:url.url];
  227. // [g_server showMsg:Localized(@"JXCopyToBoardSuccess") delay:1.5];
  228. // }else{
  229. // [g_App showAlert:Localized(@"JXFile_notExist")];
  230. // }
  231. }
  232. -(void)delBtnAction:(WeiboData*)cellData{
  233. [self.controller delBtnAction:self.weibo];
  234. }
  235. - (void)setIsPraise:(BOOL)isPraise {
  236. _isPraise = isPraise;
  237. _btnLike.selected = isPraise;
  238. }
  239. - (void)setIsCollect:(BOOL)isCollect {
  240. _isCollect = isCollect;
  241. _btnCollection.selected = isCollect;
  242. }
  243. //莫名其妙,直接写在btnReply里无效
  244. - (void)btnReply:(UIButton*)button{
  245. // if (self.menuView) {
  246. // [self.menuView dismissBaseView];
  247. // return;
  248. // }
  249. // NSArray *strArr = @[Localized(@"JX_Good"),Localized(@"JX_Comment"),Localized(@"JXUserInfoVC_Report")];
  250. // NSArray *imgArr = @[@"blog_giveLike",@"blog_comments"];
  251. // self.baseView = [[UIView alloc] init];
  252. // self.baseView.backgroundColor = HEXCOLOR(0x3B4042);
  253. // self.baseView.layer.masksToBounds = YES;
  254. // self.baseView.layer.cornerRadius = 3.0f;
  255. // [self addSubview:self.baseView];
  256. // NSInteger w = 0;
  257. // UIButton *cellView;
  258. // for (int i = 0; i < strArr.count; i++) {
  259. // NSString *str = strArr[i];
  260. // CGSize size = [str boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYSFONT(13)} context:nil].size;
  261. // cellView = [[UIButton alloc] init];
  262. // UIImageView *imgV;
  263. //
  264. // if (imgArr.count > 0 && i < imgArr.count) {
  265. // CGFloat H = 14.f;
  266. // cellView.frame = CGRectMake(w, 0, INSET*2+H+size.width, HEIGHT);
  267. // imgV = [[UIImageView alloc] initWithFrame:CGRectMake(INSET, (HEIGHT-H)/2, H, H)];
  268. // imgV.image = [UIImage imageNamed:imgArr[i]];
  269. // [cellView addSubview:imgV];
  270. // } else {
  271. // cellView.frame = CGRectMake(w, 0, INSET*2+size.width, HEIGHT);
  272. // }
  273. // UILabel *textLabel = [[UILabel alloc] init];
  274. // textLabel.font = SYSFONT(13);
  275. // textLabel.text = str;
  276. // textLabel.textColor = [UIColor whiteColor];
  277. // if (i < imgArr.count) {
  278. // textLabel.frame = CGRectMake(CGRectGetMaxX(imgV.frame)+4, (HEIGHT-size.height)/2, size.width, size.height);
  279. // }else {
  280. // textLabel.frame = CGRectMake(0, (HEIGHT-size.height)/2, cellView.frame.size.width, size.height);
  281. // textLabel.textAlignment = NSTextAlignmentCenter;
  282. // }
  283. // [cellView addSubview:textLabel];
  284. // cellView.backgroundColor = [UIColor clearColor];
  285. // [self.baseView addSubview:cellView];
  286. // if (i > 0) {
  287. // UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 4, 0.5, HEIGHT-8)];
  288. // line.backgroundColor = [UIColor whiteColor];
  289. // [cellView addSubview:line];
  290. // }
  291. // w += cellView.frame.size.width;
  292. // }
  293. //
  294. // CGPoint point = replyContent.center;
  295. // CGFloat y = point.y-32/2-2;
  296. //
  297. // self.menuView = [[JXMenuView alloc] initWithPoint:CGPointMake(10, y) Title:strArr Images:imgArr];
  298. // [self addSubview:self.menuView];
  299. [_btnLike setTitle:[self getMaxValue:weibo.praiseCount] forState:UIControlStateNormal];
  300. [btnReply setTitle:[self getMaxValue:weibo.commentCount] forState:UIControlStateNormal];
  301. [self.controller btnReplyAction:button WithCell:self];
  302. // button.tag = self.tag;
  303. // [self.controller btnReplyAction:button];
  304. }
  305. -(id)initWithCoder:(NSCoder *)aDecoder
  306. {
  307. self=[super initWithCoder:aDecoder];
  308. if(self){
  309. }
  310. return self;
  311. }
  312. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  313. {
  314. [super setSelected:selected animated:animated];
  315. // Configure the view for the selected state
  316. }
  317. #pragma -mark 私有方法
  318. -(void) prepare
  319. {
  320. [super prepareForReuse];
  321. for(UIView * view in imageContent.subviews)
  322. [view removeFromSuperview];
  323. UIView * view=[self.contentView viewWithTag:191];
  324. if(view){
  325. [view removeFromSuperview];
  326. }
  327. view=[self.contentView viewWithTag:192];
  328. if(view){
  329. [view removeFromSuperview];
  330. }
  331. linesLimit=NO;
  332. }
  333. //根据回复数量修改高度
  334. +(float) heightForReply:(NSArray*)replys
  335. {
  336. if([replys count]==0)
  337. return 0;
  338. float height=6;
  339. for(WeiboReplyData * data in replys){
  340. height+=data.height+4;
  341. }
  342. return height;
  343. }
  344. #pragma mark --------------依据图片数量设置大小-----------------
  345. -(void)addImagesWithFiles:(float)offset
  346. {
  347. //判断说说是否有图片
  348. if(self.weibo.imageHeight==0){
  349. self.imageContent.hidden=YES;
  350. CGRect frame=self.imageContent.frame;
  351. frame.origin.y=self.content.frame.origin.y+self.content.frame.size.height+offset+5;
  352. frame.size.height=0;
  353. self.imageContent.frame=frame;
  354. return;
  355. }else{
  356. self.imageContent.hidden=NO;
  357. CGRect frame=self.imageContent.frame;
  358. frame.origin.y=self.content.frame.origin.y+self.content.frame.size.height+offset+5;
  359. frame.size.height=self.weibo.imageHeight;
  360. self.imageContent.frame=frame;
  361. }
  362. __weak WeiboCell * wself=self;
  363. __weak WeiboData * wweibo=self.weibo;
  364. dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  365. dispatch_async(queue, ^{
  366. if (wself&&wweibo.willDisplay&&wweibo) {
  367. __strong WeiboCell * sself=wself;
  368. __strong WeiboData * sweibo=wweibo;
  369. dispatch_async(dispatch_get_main_queue(), ^{
  370. HBShowImageControl *imageControl=[[HBShowImageControl alloc]initWithFrame:sself.imageContent.bounds];
  371. imageControl.controller=sself.controller;
  372. imageControl.smallTag=THUMB_WEIBO_SMALL_1;
  373. // control.smallTag=THUMB_WEIBO_BIG;
  374. imageControl.bigTag=THUMB_WEIBO_BIG;
  375. imageControl.larges = sweibo.larges;
  376. //缩略图显示为原图
  377. // [control setImagesFileStr:sweibo.smalls];
  378. [imageControl setImagesFileStr:sweibo.larges];
  379. [sself.imageContent addSubview:imageControl];
  380. imageControl.delegate=sself;
  381. });
  382. }
  383. });
  384. }
  385. //获取头像当音视频背景
  386. -(void)addImageForAudioVideo:(float)offset
  387. {
  388. // NSString* imageUrl=nil;
  389. // if([self.weibo.larges count]>0)
  390. // imageUrl = ((ObjUrlData*)[self.weibo.larges objectAtIndex:0]).url;
  391. // else
  392. // imageUrl = [g_server getHeadImageOUrl:weibo.userId];
  393. self.imageContent.hidden=NO;
  394. CGRect frame=self.imageContent.frame;
  395. frame.origin.y=self.content.frame.origin.y+self.content.frame.size.height+offset+5;
  396. frame.size.height=self.weibo.imageHeight+self.weibo.videoHeight;
  397. self.imageContent.frame=frame;
  398. CGFloat w = 150;
  399. CGFloat h = 200;
  400. if (self.weibo.videoHeight < 200) {
  401. w = 200;
  402. h = 150;
  403. }
  404. imagePlayer = [[JXImageView alloc] initWithFrame:CGRectMake(0, 0, w, h)];
  405. imagePlayer.changeAlpha = NO;
  406. imagePlayer.didTouch = @selector(doNotThing);
  407. imagePlayer.delegate = self.controller;
  408. [self.imageContent addSubview:imagePlayer];
  409. // [g_App.jxServer getImage:imageUrl imageView:imagePlayer];
  410. // [imagePlayer sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"avatar_normal"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  411. //按比例缩小iv
  412. // if (imagePlayer.image) {
  413. // float count = imagePlayer.frame.size.height / imagePlayer.image.size.height;
  414. //
  415. // imagePlayer.frame = CGRectMake(0, imagePlayer.frame.origin.y, imagePlayer.image.size.width * count, imagePlayer.frame.size.height);
  416. // }
  417. imagePlayer.contentMode = UIViewContentModeScaleAspectFit;
  418. if(weibo.isVideo){
  419. [imagePlayer sd_setImageWithURL:[[self.weibo.images firstObject] valueForKey:@"oUrl"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  420. if (error) {
  421. [FileInfo getFirstImageFromVideoWithImageVIew:[self.weibo getMediaURL] imageView:imagePlayer];
  422. }
  423. imagePlayer.image = [ImageResize image:image fillSize:imagePlayer.frame.size];
  424. }];
  425. // [FileInfo getFullFirstImageFromVideo:[self.weibo getMediaURL] imageView:imagePlayer];
  426. UIButton *pauseBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
  427. pauseBtn.center = CGPointMake(imagePlayer.frame.size.width/2,imagePlayer.frame.size.height/2);
  428. [pauseBtn setBackgroundImage:[UIImage imageNamed:@"playvideo"] forState:UIControlStateNormal];
  429. [pauseBtn addTarget:self action:@selector(showTheVideo) forControlEvents:UIControlEventTouchUpInside];
  430. [imagePlayer addSubview:pauseBtn];
  431. }
  432. // }];
  433. }
  434. - (void)setupAudioPlayer:(float)offset {
  435. if (!_audioPlayer) {
  436. _audioPlayer = [[JXAudioPlayer alloc]initWithParent:self.imageContent frame:CGRectNull isLeft:YES];
  437. }
  438. ObjUrlData *data = (ObjUrlData *)[self.weibo.audios firstObject];
  439. if([data.timeLen intValue] <= 0)
  440. data.timeLen = @1;
  441. int w = (JX_SCREEN_WIDTH-HEAD_SIZE-INSETS*2-70)/30;
  442. w = 70+w*[data.timeLen intValue];
  443. if(w<70)
  444. w = 70;
  445. if(w>200)
  446. w = 200;
  447. self.imageContent.hidden=NO;
  448. CGRect frame=self.imageContent.frame;
  449. frame.origin.y=self.content.frame.origin.y+self.content.frame.size.height+offset+5;
  450. frame.size = CGSizeMake(w, 30);
  451. self.imageContent.frame=CGRectMake(self.imageContent.frame.origin.x, frame.origin.y, self.imageContent.frame.size.width, frame.size.height);
  452. self.imageContent.userInteractionEnabled = YES;
  453. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(startAudioPlay)];
  454. [self.imageContent addGestureRecognizer:tap];
  455. _audioPlayer.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
  456. _audioPlayer.audioFile = [self.weibo getMediaURL];
  457. _audioPlayer.timeLen = [data.timeLen intValue];
  458. _audioPlayer.timeLenView.textColor = HEXCOLOR(0x999999);
  459. _audioPlayer.voiceBtn.backgroundColor = HEXCOLOR(0xECEDEF);
  460. // _audioPlayer.parent.backgroundColor = HEXCOLOR(0xECEDEF);
  461. }
  462. - (void)startAudioPlay {
  463. [_audioPlayer switch];
  464. }
  465. #pragma -mark 点击播放视频
  466. - (void)showTheVideo {
  467. [self.delegate weiboCell:self clickVideoWithIndex:self.tag];
  468. }
  469. - (void)doNotThing{
  470. }
  471. - (void)onLoction {
  472. double location_x = [self.weibo.latitude doubleValue];
  473. double location_y = [self.weibo.longitude doubleValue];
  474. JXMapData * mapData = [[JXMapData alloc] init];
  475. mapData.latitude = [NSString stringWithFormat:@"%f",location_x];
  476. mapData.longitude = [NSString stringWithFormat:@"%f",location_y];
  477. NSArray * locations = @[mapData];
  478. mapData.title = self.weibo.location;
  479. if (g_config.isChina) {
  480. JXLocationVC * vc = [JXLocationVC alloc];
  481. vc.placeNames = self.weibo.location;
  482. vc.locations = [NSMutableArray arrayWithArray:locations];
  483. vc.locationType = JXLocationTypeShowStaticLocation;
  484. vc = [vc init];
  485. [g_navigation pushViewController:vc animated:YES];
  486. }else {
  487. JXGoogleMapVC *gooMap = [JXGoogleMapVC alloc] ;
  488. gooMap.locations = [NSMutableArray arrayWithArray:locations];
  489. gooMap.locationType = JXGooLocationTypeShowStaticLocation;
  490. gooMap.placeNames = self.weibo.location;
  491. gooMap = [gooMap init];
  492. [g_navigation pushViewController:gooMap animated:YES];
  493. }
  494. }
  495. #pragma -mark 接口方法
  496. -(void)loadReply
  497. {
  498. // _replys=self.weibo.replys;
  499. [self.tableReply reloadData];
  500. }
  501. #pragma mark ------------------填充数据--------------
  502. -(void)setWeibo:(WeiboData *)value
  503. {
  504. value.willDisplay=YES;
  505. // if(value.local==self.weibo.local&&linesLimit==value.linesLimit&&[self.weibo.replys count]==[value.replys count])
  506. // return;
  507. weibo=value;
  508. [self prepare];
  509. replyCount=(int)[self.weibo.replys count];
  510. linesLimit=self.weibo.linesLimit;
  511. title.text = self.weibo.userNickName;
  512. [g_App.jxServer getHeadImageSmall:self.weibo.userId userName:self.weibo.userNickName imageView:self.mLogo];
  513. [self.content registerCopyAction];
  514. self.content.linesLimit=self.weibo.linesLimit;
  515. __weak HBCoreLabel * wcontent=self.content;
  516. MatchParser* match=[self.weibo getMatch:^(MatchParser *parser,id data) {
  517. if (wcontent) {
  518. WeiboData * weibo=(WeiboData*)data;
  519. if (weibo.willDisplay) {
  520. dispatch_async(dispatch_get_main_queue(), ^{
  521. wcontent.match=parser;
  522. });
  523. }
  524. }
  525. } data:self.weibo];
  526. self.content.match=match;
  527. self.time.text=[TimeUtil getTimeStrStyle1:weibo.createTime];
  528. CGRect frame=self.time.frame;
  529. // frame.size.width=[self.time.text sizeWithFont:self.time.font].width+10;
  530. frame.size.width = [self.time.text sizeWithAttributes:@{NSFontAttributeName:self.time.font}].width + 10;
  531. self.time.frame=frame;
  532. CGFloat delW = [self.delBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.delBtn.titleLabel.font}].width +10;
  533. self.delBtn.frame = CGRectMake(CGRectGetMaxX(self.time.frame)+5, CGRectGetMinY(self.time.frame), delW, CGRectGetHeight(self.time.frame));
  534. if (weibo.location.length >0){
  535. self.locLabel.text = weibo.location;
  536. locLabel.hidden = NO;
  537. }else{
  538. locLabel.hidden = YES;
  539. }
  540. self.tableReply.scrollEnabled=NO;
  541. float offset=0.0f;
  542. if(self.weibo.numberOfLineLimit<self.weibo.numberOfLinesTotal){
  543. UIButton * button=[UIButton buttonWithType:UIButtonTypeCustom];
  544. [button setTitleColor:self.title.textColor forState:UIControlStateNormal];
  545. [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
  546. [button.titleLabel setFont:g_factory.font15];
  547. [self.contentView addSubview:button];
  548. [button addTarget:self action:@selector(limitAction) forControlEvents:UIControlEventTouchUpInside];
  549. #pragma mark - 这里更改了说说的坐标
  550. if(self.weibo.linesLimit){
  551. [button setTitle:Localized(@"WeiboCell_AllText") forState:UIControlStateNormal];
  552. content.frame=CGRectMake(CGRectGetMaxX(mLogo.frame)+10, CGRectGetMaxY(mLogo.frame)+11, JX_SCREEN_WIDTH -CGRectGetMaxX(mLogo.frame)-10-15,self.weibo.heightOflimit);
  553. offset=22;
  554. }else{
  555. [button setTitle:Localized(@"WeiboCell_Stop") forState:UIControlStateNormal];
  556. content.frame=CGRectMake(CGRectGetMaxX(mLogo.frame)+10, CGRectGetMaxY(mLogo.frame)+11, JX_SCREEN_WIDTH -CGRectGetMaxX(mLogo.frame)-10-15,self.weibo.height);
  557. offset=22;
  558. }
  559. if ((self.weibo.images.count > 0 || self.weibo.larges.count > 0 || self.weibo.smalls.count > 0) || self.weibo.audios.count > 0 || self.weibo.videos.count > 0 || self.weibo.files.count > 0) {
  560. offset += 15;
  561. }
  562. button.frame=CGRectMake(CGRectGetMinX(content.frame), CGRectGetMaxY(content.frame)+9, 50, 20);
  563. [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 16)];
  564. button.tag=191;
  565. }else{
  566. content.frame=CGRectMake(CGRectGetMaxX(mLogo.frame)+10, CGRectGetMaxY(mLogo.frame)+11, JX_SCREEN_WIDTH -CGRectGetMaxX(mLogo.frame)-10-15,self.weibo.height);
  567. }
  568. if([weibo.videos count]>0)
  569. [self addImageForAudioVideo:offset];
  570. else if ( [weibo.audios count]>0)
  571. [self setupAudioPlayer:offset];
  572. else
  573. [self addImagesWithFiles:offset];
  574. if (weibo.type == weibo_dataType_share) {
  575. self.shareView.hidden = NO;
  576. CGRect frame=CGRectMake(CGRectGetMaxX(mLogo.frame)+10, 25, JX_SCREEN_WIDTH - 100, 70);
  577. frame.origin.y=CGRectGetMaxY(self.content.frame)+offset+5;
  578. self.shareView.frame=frame;
  579. _shareTitle.text = weibo.sdkTitle;
  580. [_shareIcon sd_setImageWithURL:[NSURL URLWithString:weibo.sdkIcon] placeholderImage:[UIImage imageNamed:@"ALOGO_1200"]];
  581. }else {
  582. self.shareView.frame = CGRectZero;
  583. self.shareView.hidden = YES;
  584. }
  585. if ([weibo.files count]>0) {
  586. self.fileView.hidden = NO;
  587. self.fileView.frame = CGRectMake(CGRectGetMaxX(mLogo.frame)+10, 40, JX_SCREEN_WIDTH -100, 100);
  588. CGRect frame=self.fileView.frame;
  589. frame.origin.y=self.content.frame.origin.y+self.content.frame.size.height+offset+5;
  590. // frame.size.height=self.weibo.imageHeight;
  591. self.fileView.frame=frame;
  592. ObjUrlData * url= [weibo.files firstObject];
  593. // url.url;
  594. // url.fileSize = [NSString stringWithFormat:@"%@",msg.fileSize];
  595. // url.type = @"4";
  596. NSString *urlName;
  597. if (url.name.length > 0) {
  598. urlName = url.name;
  599. }else {
  600. urlName = [url.url lastPathComponent];
  601. }
  602. _fileTitleLabel.text = urlName;
  603. NSString * fileExt = [urlName pathExtension];
  604. NSInteger fileType = [self fileTypeWithExt:fileExt];
  605. [_typeView setFileType:fileType];
  606. }else{
  607. self.fileView.frame = CGRectZero;
  608. self.fileView.hidden = YES;
  609. }
  610. int moreH = 0;
  611. if (self.weibo.replys.count == 20) {
  612. moreH = 23;
  613. tableReply.tableFooterView = _moreLabel;
  614. }else {
  615. tableReply.tableFooterView = nil;
  616. }
  617. float height=self.weibo.replyHeight;
  618. if(height>=0){
  619. [self createTableHead];
  620. if (self.weibo.heightPraise > 0) {
  621. height = self.weibo.replyHeight - self.weibo.heightPraise + _heightPraise + 5;
  622. }
  623. frame=self.replyContent.frame;
  624. frame.origin.y=self.imageContent.frame.origin.y+self.imageContent.frame.size.height+5 +CGRectGetHeight(self.fileView.frame)+CGRectGetHeight(self.shareView.frame);
  625. frame.size.height=self.weibo.replyHeight+30+moreH;
  626. self.replyContent.frame=frame;
  627. frame=back.frame;
  628. frame.size.height=height+3+moreH;
  629. frame.origin.y=25;
  630. back.frame=frame;
  631. frame=tableReply.frame;
  632. frame.size.height=height+moreH;
  633. frame.origin.y=31;
  634. tableReply.frame=frame;
  635. if ([self.weibo.replys isKindOfClass:[NSArray class]]&&([self.weibo.replys count]>0 || [self.weibo.praises count]>0)) {
  636. locLabel.frame = CGRectMake(CGRectGetMaxX(mLogo.frame)+10, CGRectGetMaxY(back.frame)+12+CGRectGetMinY(self.replyContent.frame), JX_SCREEN_WIDTH -70, 14);
  637. }else {
  638. locLabel.frame = CGRectMake(CGRectGetMaxX(mLogo.frame)+10, CGRectGetMaxY(replyContent.frame)+2, JX_SCREEN_WIDTH -70, 14);
  639. }
  640. }
  641. back.hidden = height<=0;
  642. tableReply.hidden = height<=0;
  643. if(self.weibo.local){
  644. //为何要设为NO
  645. [self.btnReply setEnabled:NO];
  646. }else{
  647. [self.btnReply setEnabled:YES];
  648. }
  649. [self.tableReply reloadData];
  650. }
  651. -(int)fileTypeWithExt:(NSString *)fileExt{
  652. int fileType = 0;
  653. if ([fileExt isEqualToString:@"jpg"] || [fileExt isEqualToString:@"jpeg"] || [fileExt isEqualToString:@"png"] || [fileExt isEqualToString:@"gif"] || [fileExt isEqualToString:@"bmp"])
  654. fileType = 1;
  655. else if ([fileExt isEqualToString:@"amr"] || [fileExt isEqualToString:@"mp3"] || [fileExt isEqualToString:@"wav"])
  656. fileType = 2;
  657. else if ([fileExt isEqualToString:@"mp4"] || [fileExt isEqualToString:@"mov"])
  658. fileType = 3;
  659. else if ([fileExt isEqualToString:@"ppt"] || [fileExt isEqualToString:@"pptx"])
  660. fileType = 4;
  661. else if ([fileExt isEqualToString:@"xls"] || [fileExt isEqualToString:@"xlsx"])
  662. fileType = 5;
  663. else if ([fileExt isEqualToString:@"doc"] || [fileExt isEqualToString:@"docx"])
  664. fileType = 6;
  665. else if ([fileExt isEqualToString:@"zip"] || [fileExt isEqualToString:@"rar"])
  666. fileType = 7;
  667. else if ([fileExt isEqualToString:@"txt"])
  668. fileType = 8;
  669. else if ([fileExt isEqualToString:@"pdf"])
  670. fileType = 10;
  671. else
  672. fileType = 9;
  673. return fileType;
  674. }
  675. +(float)getHeightByContent:(WeiboData*)data
  676. {
  677. float height;
  678. if(data.shouldExtend){
  679. if(data.linesLimit){
  680. height=data.heightOflimit+23;
  681. }else{
  682. height=data.height+23;
  683. }
  684. }else{
  685. height=data.height;
  686. }
  687. if (data.location.length > 0) {
  688. height += 22;
  689. }
  690. if(data.numberOfLineLimit<data.numberOfLinesTotal){
  691. if ((data.images.count > 0 || data.larges.count > 0 || data.smalls.count > 0) || data.audios.count > 0 || data.videos.count > 0 || data.files.count > 0) {
  692. height += 15;
  693. }
  694. }
  695. if ([data.replys isKindOfClass:[NSArray class]]&&([data.replys count]>0 || [data.praises count]>0)&&!data.local) {
  696. int h = 0;
  697. if ([data.replys count] == 20) {
  698. // 评论数=20 显示更多,处理高度
  699. h = 23;
  700. }
  701. CGFloat rH = data.replyHeight;
  702. return 100.0+h+data.imageHeight+height+rH +data.fileHeight + data.shareHeight+data.videoHeight;
  703. } else {
  704. return 90.0+data.imageHeight+height +data.fileHeight + data.shareHeight+data.videoHeight;
  705. }
  706. }
  707. #pragma -mark 委托方法
  708. -(void)showImageControlFinishLoad:(HBShowImageControl*)control
  709. {
  710. CGRect frame=self.imageContent.frame;
  711. frame.size.height=control.frame.size.height;
  712. self.imageContent.frame=frame;
  713. }
  714. #pragma -mark 事件响应方法
  715. -(void)limitAction
  716. {
  717. self.weibo.linesLimit=!self.weibo.linesLimit;
  718. [self refresh];
  719. }
  720. #pragma -mark 回调方法
  721. -(void)lookImageAction:(HBShowImageControl*)control
  722. {
  723. }
  724. -(void)coreLabel:(HBCoreLabel*)coreLabel linkClick:(NSString*)linkStr
  725. {
  726. [g_notify postNotificationName:kCellTouchUrlNotifaction object:linkStr];
  727. }
  728. -(void)coreLabel:(HBCoreLabel *)coreLabel phoneClick:(NSString *)linkStr
  729. {
  730. [g_notify postNotificationName:kCellTouchPhoneNotifaction object:linkStr];
  731. }
  732. #pragma -mark tableReply delegate
  733. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  734. {
  735. WeiboReplyData * data=[self.weibo.replys objectAtIndex:indexPath.row];
  736. NSLog(@"------%d",data.height + 4);
  737. return data.height+4;
  738. }
  739. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  740. {
  741. NSInteger n = [self.weibo.replys count];
  742. return n;
  743. }
  744. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  745. {
  746. // NSString *CellIdentifier = [NSString stringWithFormat:@"WeiboReplyCell%d_%d",refreshCount,indexPath.row];
  747. NSString *CellIdentifier = [NSString stringWithFormat:@"WeiboReplyCell"];
  748. ReplyCell * cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  749. if(cell==nil){
  750. cell = [[ReplyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  751. }
  752. //清空cell里的数据
  753. cell.label = nil;
  754. cell.backgroundColor = [UIColor clearColor];
  755. if(indexPath.row>=self.weibo.replys.count)
  756. return cell;
  757. //回复区的文字Label
  758. cell.label = [[HBCoreLabel alloc]initWithFrame:CGRectMake(10, 4, JX_SCREEN_WIDTH, 27)];
  759. [cell addSubview:cell.label];
  760. cell.label.backgroundColor = [UIColor clearColor];
  761. WeiboReplyData * data=[self.weibo.replys objectAtIndex:indexPath.row];
  762. __weak HBCoreLabel * wlabel=cell.label;
  763. MatchParser * match=[data getMatch:^(MatchParser *parser, id data) {
  764. if (wlabel) {
  765. WeiboData * weibo=(WeiboData*)data;
  766. if (weibo.willDisplay) {
  767. dispatch_async(dispatch_get_main_queue(), ^{
  768. wlabel.match=parser;
  769. });
  770. }
  771. }
  772. } data:self.weibo];
  773. cell.label.match=match;
  774. cell.label.userInteractionEnabled=YES;
  775. CGRect frame=cell.label.frame;
  776. cell.backgroundColor=[UIColor clearColor];
  777. frame.size.height=data.height;
  778. cell.label.frame=frame;
  779. //设置回复被点击后颜色不变
  780. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  781. return cell;
  782. }
  783. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  784. {
  785. NSIndexPath * row = [NSIndexPath indexPathForRow:self.tag inSection:0];
  786. //获取数据,大Cell的数据
  787. // NSLog(@"%ld -----%ld",row.row,row.section);
  788. self.controller.selectWeiboCell = [self.tableViewP cellForRowAtIndexPath:row];
  789. self.controller.selectWeiboData = self.controller.selectWeiboCell.weibo;
  790. //小Cell里面的数据
  791. WeiboReplyData* p =[self.weibo.replys objectAtIndex:indexPath.row];
  792. if ([MY_USER_ID intValue] == [p.userId intValue]) {
  793. [g_App showAlert:@"是否删除评论" delegate:self];
  794. self.controller.deleteReply = (int)indexPath.row;
  795. return;
  796. }
  797. //回复者
  798. self.controller.replyDataTemp.userId = MY_USER_ID;
  799. self.controller.replyDataTemp.userNickName = g_server.myself.userNickname;
  800. //被回复者
  801. self.controller.replyDataTemp.toNickName = p.userNickName;
  802. self.controller.replyDataTemp.toUserId = p.userId;
  803. [self.controller doShowAddComment:[NSString stringWithFormat:@"%@%@",Localized(@"WeiboCell_Reply"),p.userNickName]];
  804. // NSLog(@"%ld",[p.userNickName length] + [g_server.myself.userNickname length]);
  805. // self.controller.replyDataTemp.body = p.body;
  806. }
  807. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  808. if (buttonIndex == 1) {
  809. WeiboReplyData* p = [self.weibo.replys objectAtIndex:self.controller.deleteReply];
  810. [g_server delComment:self.controller.selectWeiboData.messageId commentId:p.replyId toView:self.controller];
  811. }
  812. }
  813. //-(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  814. // [g_wait stop];
  815. // if([aDownload.action isEqualToString:act_CommentList]){
  816. // for(int i=0;i<[array1 count];i++){
  817. // WeiboReplyData * reply=[[WeiboReplyData alloc]init];
  818. // NSDictionary* dict = [array1 objectAtIndex:i];
  819. // reply.type=1;
  820. // [reply getDataFromDict:dict];
  821. // [reply setMatch];
  822. // [self.replys addObject:reply];
  823. // [reply release];
  824. // }
  825. // _refreshCount++;
  826. // [_table reloadData];
  827. // _footer.hidden = [array1 count]<jx_page_size;
  828. // }
  829. // if([aDownload.action isEqualToString:act_CommentDel]){
  830. // [replys removeObjectAtIndex:_deleted];
  831. //
  832. // NSIndexPath* row = [NSIndexPath indexPathForRow:_deleted inSection:0];
  833. // NSArray* rows=[NSArray arrayWithObject:row];
  834. // [_table beginUpdates];
  835. // [_table deleteRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationNone];
  836. // [_table endUpdates];
  837. // }
  838. //}
  839. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  840. [g_wait stop];
  841. if( [aDownload.action isEqualToString:act_UserGet] ){
  842. JXUserObject* p = [[JXUserObject alloc]init];
  843. [p getDataFromDict:dict];
  844. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  845. vc.user = p;
  846. vc.fromAddType = 6;
  847. vc = [vc init];
  848. [g_navigation pushViewController:vc animated:YES];
  849. [_pool addObject:vc];
  850. }
  851. if ([aDownload.action isEqualToString:act_CommentList]) {
  852. int moreHeight = 23;
  853. if (array1.count < 20) {
  854. self.weibo.replyHeight -= moreHeight;
  855. self.tableReply.tableFooterView = nil;
  856. moreHeight = 0;
  857. }else {
  858. self.tableReply.tableFooterView = _moreLabel;
  859. }
  860. CGFloat height = 0;
  861. for(int i=0;i<[array1 count];i++){
  862. WeiboReplyData * reply=[[WeiboReplyData alloc]init];
  863. NSDictionary* dict = [array1 objectAtIndex:i];
  864. reply.type=1;
  865. // reply.addHeight = 60;
  866. [reply getDataFromDict:dict];
  867. [reply setMatch];
  868. [self.weibo.replys addObject:reply];
  869. //计算加载更多增加的高度
  870. height += (reply.height +4);
  871. }
  872. self.weibo.replyHeight = self.weibo.replyHeight+height+moreHeight;
  873. // [self setWeibo:self.weibo];
  874. [self.tableReply reloadData];
  875. [self.controller setupTableViewHeight:height tag:self.tag];
  876. }
  877. //
  878. // if ([aDownload.action isEqualToString:act_CommentDel]) {
  879. //
  880. //// [self.tableReply reloadData];
  881. //
  882. // [self.controller.tableView reloadData];
  883. // }
  884. }
  885. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  886. [g_wait stop];
  887. return show_error;
  888. }
  889. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  890. [g_wait stop];
  891. return show_error;
  892. }
  893. -(void) didServerConnectStart:(JXConnection*)aDownload{
  894. // [g_wait start:Localized(@"WeiboCell_Sending")];
  895. [g_wait start:nil];
  896. }
  897. -(void)refresh{
  898. NSIndexPath* row = [NSIndexPath indexPathForRow:self.tag inSection:0];
  899. // NSArray* rows=[NSArray arrayWithObject:row];
  900. self.controller.refreshCellIndex = self.tag;
  901. // [self.tableViewP beginUpdates];
  902. // [self.tableViewP reloadRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationNone];
  903. // [self.tableViewP endUpdates];
  904. [self.tableViewP reloadData];
  905. self.controller.refreshCellIndex = -1;
  906. if (self.weibo.linesLimit && self.weibo.numberOfLinesTotal > 30) {
  907. [self.tableViewP scrollToRowAtIndexPath:row atScrollPosition:UITableViewScrollPositionTop animated:NO];
  908. }
  909. }
  910. -(void)setReplys:(NSArray *)replys{
  911. _replys = [NSArray arrayWithArray:replys];
  912. }
  913. -(NSArray *)getReplys{
  914. return _replys;
  915. }
  916. - (void)pushLikeVC {
  917. JXLikeListViewController *likeListVC = [JXLikeListViewController alloc];
  918. likeListVC.weibo = self.weibo;
  919. likeListVC = [likeListVC init];
  920. [g_navigation pushViewController:likeListVC animated:YES];
  921. }
  922. #pragma mark - 创建回复区的点赞区
  923. -(void)createTableHead{
  924. if([self.weibo.praises count]<=0){
  925. self.tableReply.tableHeaderView = nil;
  926. return;
  927. }
  928. // self.tableReply.tableHeaderView.hidden = NO;
  929. WeiboReplyData* p = [[WeiboReplyData alloc]init];
  930. p.type = reply_data_praise;
  931. p.body = [self.weibo getAllPraiseUsers];
  932. int y = 3;
  933. if([weibo.replys count]>0){
  934. y = 2;
  935. }
  936. #pragma mark 点赞Label长度
  937. UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(32, y, self.tableReply.frame.size.width - 40, 32)];
  938. label.backgroundColor = [UIColor clearColor];
  939. label.textColor = HEXCOLOR(0x576b95);
  940. label.font = g_factory.font14;
  941. label.numberOfLines = 0;
  942. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushLikeVC)];
  943. // [label addGestureRecognizer:tap];
  944. NSMutableArray *data = [[NSMutableArray alloc] init];
  945. for(int i = 0; i < self.weibo.praises.count; i++){
  946. WeiboReplyData* praises = [self.weibo.praises objectAtIndex:i];
  947. [data addObject:praises.userNickName];
  948. }
  949. if (data.count > 20) {
  950. [data removeObjectAtIndex:data.count-1];
  951. }
  952. [data addObject:[NSString stringWithFormat:@"%d%@",self.weibo.praiseCount,Localized(@"WeiboData_PerZan1")]];
  953. NSAttributedString * showAttString = [self getAttributeWith:data string:p.body orginFont:14 orginColor:HEXCOLOR(0x576b95) attributeFont:14 attributeColor:HEXCOLOR(0x576b95)];
  954. label.attributedText = showAttString;
  955. [label yb_addAttributeTapActionWithStrings:data tapClicked:^(UILabel *label, NSString *string, NSRange range, NSInteger index) {
  956. if (index == self.weibo.praises.count) {
  957. [self pushLikeVC];
  958. }else{
  959. WeiboReplyData *user = self.weibo.praises[index];
  960. JXUserInfoVC *userInfoVC = [JXUserInfoVC alloc];
  961. userInfoVC.userId = user.userId;
  962. userInfoVC.fromAddType = 6;
  963. userInfoVC = [userInfoVC init];
  964. [g_navigation pushViewController:userInfoVC animated:YES];
  965. }
  966. }];
  967. // [p getMatch];
  968. CGSize size = [p.body boundingRectWithSize:CGSizeMake(self.tableReply.frame.size.width - 40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font14} context:nil].size;
  969. size.height += 5;
  970. _heightPraise = size.height+5;
  971. CGRect frame=label.frame;
  972. frame.size.height=size.height;
  973. label.frame=frame;
  974. UIView* v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableReply.frame.size.width, _heightPraise)];
  975. [v addSubview:label];
  976. UIImageView* iv;
  977. if([weibo.replys count]>0){
  978. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0, _heightPraise-0.5, back.frame.size.width, LINE_WH)];
  979. line.backgroundColor = THE_LINE_COLOR;
  980. [v addSubview:line];
  981. }
  982. iv = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 15, 15)];
  983. iv.image = [UIImage imageNamed:@"heart_praise"];
  984. [v addSubview:iv];
  985. self.tableReply.tableHeaderView = v;
  986. }
  987. -(void)actionUser:(UIView*)sender{
  988. [_pool removeAllObjects];
  989. if([self.weibo.userId isEqualToString:CALL_CENTER_USERID])
  990. return;
  991. // [g_server getUser:self.weibo.userId toView:self];
  992. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  993. vc.userId = self.weibo.userId;
  994. vc.fromAddType = 6;
  995. vc = [vc init];
  996. [g_navigation pushViewController:vc animated:YES];
  997. [_pool addObject:vc];
  998. // _userVc = nil;
  999. // _userVc = [userInfoVC alloc];
  1000. // _userVc.userId = weibo.userId;
  1001. // [_userVc init];
  1002. // [g_window addSubview:_userVc.view];
  1003. }
  1004. - (void)getMoreData {
  1005. self.weibo.page ++;
  1006. [g_server listComment:self.weibo.messageId pageIndex:self.weibo.page pageSize:20 commentId:nil toView:self];
  1007. }
  1008. - (void)dealloc {
  1009. NSLog(@"WeiboCell.dealloc");
  1010. // if (_audioPlayer != nil) {
  1011. [_audioPlayer stop];
  1012. _audioPlayer = nil;
  1013. // }
  1014. }
  1015. - (NSAttributedString *)getAttributeWith:(id)sender
  1016. string:(NSString *)string
  1017. orginFont:(CGFloat)orginFont
  1018. orginColor:(UIColor *)orginColor
  1019. attributeFont:(CGFloat)attributeFont
  1020. attributeColor:(UIColor *)attributeColor
  1021. {
  1022. __block NSMutableAttributedString *totalStr = [[NSMutableAttributedString alloc] initWithString:string];
  1023. [totalStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:orginFont] range:NSMakeRange(0, string.length)];
  1024. [totalStr addAttribute:NSForegroundColorAttributeName value:orginColor range:NSMakeRange(0, string.length)];
  1025. if ([sender isKindOfClass:[NSArray class]]) {
  1026. __block NSString *oringinStr = string;
  1027. __weak typeof(self) weakSelf = self;
  1028. [sender enumerateObjectsUsingBlock:^(NSString * _Nonnull str, NSUInteger idx, BOOL * _Nonnull stop) {
  1029. NSRange range = [oringinStr rangeOfString:str];
  1030. [totalStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:attributeFont] range:range];
  1031. if (idx == weakSelf.weibo.praises.count) {
  1032. [totalStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:range];
  1033. }else {
  1034. [totalStr addAttribute:NSForegroundColorAttributeName value:attributeColor range:range];
  1035. }
  1036. oringinStr = [oringinStr stringByReplacingCharactersInRange:range withString:[weakSelf getStringWithRange:range]];
  1037. }];
  1038. }else if ([sender isKindOfClass:[NSString class]]) {
  1039. NSRange range = [string rangeOfString:sender];
  1040. [totalStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:attributeFont] range:range];
  1041. [totalStr addAttribute:NSForegroundColorAttributeName value:attributeColor range:range];
  1042. }
  1043. return totalStr;
  1044. }
  1045. - (NSString *)getStringWithRange:(NSRange)range
  1046. {
  1047. NSMutableString *string = [NSMutableString string];
  1048. for (int i = 0; i < range.length ; i++) {
  1049. [string appendString:@" "];
  1050. }
  1051. return string;
  1052. }
  1053. @end