WBStatusCell.m 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. //
  2. // WBFeedCell.m
  3. // YYKitExample
  4. //
  5. // Created by ibireme on 15/9/5.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "WBStatusCell.h"
  9. #import "YYControl.h"
  10. #import "WBUserInfoModel.h"
  11. @implementation WBStatusProfileView {
  12. BOOL _trackingTouch;
  13. }
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. if (frame.size.width == 0 && frame.size.height == 0) {
  16. frame.size.width = kScreenW;
  17. frame.size.height = kWBCellProfileHeight;
  18. }
  19. self = [super initWithFrame:frame];
  20. self.exclusiveTouch = YES;
  21. @weakify(self);
  22. _avatarView = [UIImageView new];
  23. _avatarView.size = CGSizeMake(40, 40);
  24. _avatarView.origin = CGPointMake(kWBCellPadding, kWBCellPadding + 3);
  25. _avatarView.contentMode = UIViewContentModeScaleAspectFill;
  26. _avatarView.clipsToBounds = YES;
  27. _avatarView.layer.cornerRadius = 20;
  28. [self addSubview:_avatarView];
  29. _nameLabel = [YYLabel new];
  30. _nameLabel.size = CGSizeMake(kWBCellNameWidth, 20);
  31. _nameLabel.left = _avatarView.right + kWBCellNamePaddingLeft;
  32. _nameLabel.top = _avatarView.top;
  33. _nameLabel.displaysAsynchronously = YES;
  34. _nameLabel.ignoreCommonProperties = YES;
  35. _nameLabel.fadeOnAsynchronouslyDisplay = NO;
  36. _nameLabel.fadeOnHighlight = NO;
  37. _nameLabel.lineBreakMode = NSLineBreakByClipping;
  38. _nameLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
  39. _nameLabel.centerY = _avatarView.centerY;
  40. [self addSubview:_nameLabel];
  41. //把self.topBtn放到_nameLabel后面
  42. _topBtn = [UIButton new];
  43. _topBtn.size = CGSizeMake(28, 18);
  44. ViewRadius(_topBtn, 3);
  45. [_topBtn setTitle:ASLocalizedString(@"置顶") forState:UIControlStateNormal];
  46. _topBtn.right = self.width - kWBCellPadding;
  47. _topBtn.centerY = _nameLabel.centerY;
  48. _topBtn.backgroundColor = [UIColor colorWithHexString:@"#C03E53"];
  49. _topBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  50. // _topBtn.hidden = YES;
  51. [self addSubview:_topBtn];
  52. _sourceLabel = [YYLabel new];
  53. _sourceLabel.frame = CGRectMake(0, 0, 1, 20);
  54. _sourceLabel.right = self.width - kWBCellPadding;
  55. _sourceLabel.centerY = _nameLabel.centerY;
  56. _sourceLabel.textAlignment = NSTextAlignmentRight;
  57. _sourceLabel.displaysAsynchronously = YES;
  58. _sourceLabel.ignoreCommonProperties = YES;
  59. _sourceLabel.fadeOnAsynchronouslyDisplay = NO;
  60. _sourceLabel.fadeOnHighlight = NO;
  61. _sourceLabel.highlightTapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
  62. if ([weak_self.cell.delegate respondsToSelector:@selector(cell:didClickInLabel:textRange:)]) {
  63. [weak_self.cell.delegate cell:weak_self.cell didClickInLabel:(YYLabel *)containerView textRange:range];
  64. }
  65. };
  66. _sourceLabel.hidden = YES;
  67. [self addSubview:_sourceLabel];
  68. _timeLabel = [YYLabel new];
  69. _timeLabel.frame = CGRectMake(0, 0, 1, 20);
  70. _timeLabel.left = _nameLabel.left;
  71. _timeLabel.top = _nameLabel.bottom + 5;
  72. _timeLabel.textAlignment = NSTextAlignmentRight;
  73. _timeLabel.displaysAsynchronously = YES;
  74. _timeLabel.ignoreCommonProperties = YES;
  75. _timeLabel.fadeOnAsynchronouslyDisplay = NO;
  76. _timeLabel.fadeOnHighlight = NO;
  77. _timeLabel.highlightTapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
  78. if ([weak_self.cell.delegate respondsToSelector:@selector(cell:didClickInLabel:textRange:)]) {
  79. [weak_self.cell.delegate cell:weak_self.cell didClickInLabel:(YYLabel *)containerView textRange:range];
  80. }
  81. };
  82. [self addSubview:_timeLabel];
  83. // _sexView = [[CommonSexView alloc]initWithFrame:CGRectMake(_nameLabel.left, _nameLabel.bottom + 5, 15, 15)];
  84. // _levelView = [[CommonLevelView alloc]initWithFrame:CGRectMake(_sexView.right+5, _nameLabel.bottom + 5-0.5, 38, 16)];
  85. //
  86. // _locationView = [[CommonLocationView alloc]initWithFrame:CGRectMake(_sexView.right + 5, _nameLabel.bottom + 5, 60, 20)];
  87. // _statusView = [[CommonStatusView alloc]initWithFrame:CGRectMake(_locationView.right + 5, _nameLabel.bottom + 5, 55, 20)];
  88. //关注按钮
  89. _moreBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
  90. _moreBtn.right = self.width - kWBCellPadding;
  91. _moreBtn.centerY = _avatarView.centerY;
  92. [_moreBtn setTitle:ASLocalizedString(@"关注") forState:UIControlStateNormal];
  93. [_moreBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  94. _moreBtn.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
  95. [_moreBtn setBackgroundImage:[UIImage imageNamed:@"dynamic_follow_bg"] forState:UIControlStateNormal];
  96. _moreBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -13);
  97. __weak __typeof(self)weakSelf = self;
  98. [_moreBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  99. __strong __typeof(weakSelf)strongSelf = weakSelf;
  100. if (strongSelf.cell.delegate && [strongSelf.cell.delegate respondsToSelector:@selector(cell:didClickMore:)]) {
  101. [strongSelf.cell.delegate cell:strongSelf.cell didClickMore:sender];
  102. }
  103. }];
  104. _moreBtn.hidden = YES;
  105. [self addSubview:_moreBtn];
  106. // [self addSubview:_sexView];
  107. // [self addSubview:_levelView];
  108. // [self addSubview:_locationView];
  109. // [self addSubview:_statusView];
  110. return self;
  111. }
  112. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  113. _trackingTouch = NO;
  114. UITouch *t = touches.anyObject;
  115. CGPoint p = [t locationInView:_avatarView];
  116. if (CGRectContainsPoint(_avatarView.bounds, p)) {
  117. _trackingTouch = YES;
  118. }
  119. p = [t locationInView:_nameLabel];
  120. if (CGRectContainsPoint(_nameLabel.bounds, p) && _nameLabel.textLayout.textBoundingRect.size.width > p.x) {
  121. _trackingTouch = YES;
  122. }
  123. if (!_trackingTouch) {
  124. [super touchesBegan:touches withEvent:event];
  125. }
  126. }
  127. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  128. if (!_trackingTouch) {
  129. [super touchesEnded:touches withEvent:event];
  130. } else {
  131. if ([_cell.delegate respondsToSelector:@selector(cell:didClickUser:)]) {
  132. [_cell.delegate cell:_cell didClickUser:_cell.statusView.layout.status];
  133. }
  134. }
  135. }
  136. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
  137. if (!_trackingTouch) {
  138. [super touchesCancelled:touches withEvent:event];
  139. }
  140. }
  141. @end
  142. @implementation WBStatusCardView {
  143. BOOL _isRetweet;
  144. WBStatusLayout *_layout;
  145. }
  146. - (instancetype)initWithFrame:(CGRect)frame {
  147. if (frame.size.width == 0 && frame.size.height == 0){
  148. frame.size.width = kScreenW;
  149. frame.origin.x = kWBCellPadding;
  150. }
  151. self = [super initWithFrame:frame];
  152. self.exclusiveTouch = YES;
  153. _imageView = [UIImageView new];
  154. _imageView.clipsToBounds = YES;
  155. _imageView.contentMode = UIViewContentModeScaleAspectFill;
  156. _badgeImageView = [UIImageView new];
  157. _badgeImageView.clipsToBounds = YES;
  158. _badgeImageView.contentMode = UIViewContentModeScaleAspectFit;
  159. _label = [YYLabel new];
  160. _label.textVerticalAlignment = YYTextVerticalAlignmentCenter;
  161. _label.numberOfLines = 3;
  162. _label.ignoreCommonProperties = YES;
  163. _label.displaysAsynchronously = YES;
  164. _label.fadeOnAsynchronouslyDisplay = NO;
  165. _label.fadeOnHighlight = NO;
  166. _button = [UIButton buttonWithType:UIButtonTypeCustom];
  167. _playerView = [[CLPlayerView alloc] init];
  168. _playerView.backgroundColor = kClearColor;
  169. _playerView.layer.cornerRadius = 4;
  170. _playerView.layer.masksToBounds = YES;
  171. _playerView.maskView.playButton.hidden = YES;
  172. _playerView.configure.mute = YES;
  173. _playerView.configure.repeatPlay = YES;
  174. _playerView.isFullScreen = NO;
  175. _playerView.configure.mute = YES;
  176. _playerView.configure.isLandscape = YES;
  177. _playerView.configure.videoFillMode = VideoFillModeResizeAspectFill;
  178. [self addSubview:_imageView];
  179. [self addSubview:_badgeImageView];
  180. [self addSubview:_label];
  181. [self addSubview:_playerView];
  182. [self addSubview:_button];
  183. self.backgroundColor = kWBCellInnerViewColor;
  184. self.layer.borderWidth = CGFloatFromPixel(1);
  185. self.layer.borderColor = [UIColor colorWithWhite:0.000 alpha:0.070].CGColor;
  186. return self;
  187. }
  188. - (void)setWithLayout:(WBStatusLayout *)layout isRetweet:(BOOL)isRetweet {
  189. _layout = layout;
  190. if (!StrValid(layout.status.video)) return;
  191. CGFloat len1_3 = (kWBCellContentWidth + kWBCellPaddingPic) / 3 - kWBCellPaddingPic;
  192. len1_3 = CGFloatPixelRound(len1_3);
  193. self.height = 184;// kScreenW * 16 / 18;
  194. /*
  195. badge: 25,25 左上角 (42)
  196. image: 70,70 方形
  197. 100, 70 矩形
  198. btn: 60,70
  199. lineheight 20
  200. padding 10
  201. */
  202. self.width = 135;// kScreenW / 2;
  203. _badgeImageView.hidden = YES;
  204. _label.hidden = YES;
  205. _imageView.frame = self.bounds;
  206. [_imageView setImageWithURL:[NSURL URLWithString:layout.status.cover_url] options:kNilOptions];
  207. _button.hidden = YES;
  208. _button.frame = self.bounds;
  209. [_button setTitle:nil forState:UIControlStateNormal];
  210. [_button cancelImageRequestForState:UIControlStateNormal];
  211. [_button setImage:[UIImage imageNamed:@"aio_record_play_nor"] forState:UIControlStateNormal];
  212. //[WBStatusHelper imageNamed:@"multimedia_videocard_play"]
  213. [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  214. self.backgroundColor = isRetweet ? [UIColor clearColor] : kWBCellInnerViewColor;
  215. _playerView.url =[NSURL URLWithString:layout.status.video];
  216. _playerView.frame = self.bounds;
  217. [_playerView updateWithConfigure:^(CLPlayerViewConfigure *configure) {
  218. UITapGestureRecognizer *tapPlayerView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonAction:)];
  219. [_playerView.maskView addGestureRecognizer:tapPlayerView];
  220. //播放
  221. [_playerView playVideo];
  222. }];
  223. }
  224. - (void)buttonAction:(UIButton *)sender{
  225. // [_playerView playVideo];
  226. if ([_cell.delegate respondsToSelector:@selector(cell:didClickVideo:)]) {
  227. [_cell.delegate cell:_cell didClickVideo:_layout.status.video];
  228. }
  229. }
  230. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  231. self.backgroundColor = kWBCellInnerViewHighlightColor;
  232. }
  233. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  234. self.backgroundColor = _isRetweet ? [UIColor whiteColor] : kWBCellInnerViewColor;
  235. if ([_cell.delegate respondsToSelector:@selector(cellDidClickCard:)]) {
  236. [_cell.delegate cellDidClickCard:_cell];
  237. }
  238. }
  239. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
  240. self.backgroundColor = _isRetweet ? [UIColor whiteColor] : kWBCellInnerViewColor;
  241. }
  242. @end
  243. @interface WBStatusLocationView ()
  244. @property(nonatomic, strong) QMUIButton *locationBtn;
  245. @property(nonatomic, strong) UIButton *topicBtn;
  246. @end
  247. @implementation WBStatusLocationView
  248. - (instancetype)initWithFrame:(CGRect)frame{
  249. if (self = [super initWithFrame:frame]) {
  250. self.exclusiveTouch = YES;
  251. [self addSubview:self.locationBtn];
  252. [self addSubview:self.topicBtn];
  253. }
  254. return self;
  255. }
  256. - (QMUIButton *)locationBtn{
  257. if (!_locationBtn) {
  258. _locationBtn = [[QMUIButton alloc]initWithFrame:CGRectMake(10, 0, 100, 20)];
  259. _locationBtn.imagePosition = QMUIButtonImagePositionLeft;
  260. // [_locationBtn setImage:[UIImage imageNamed:@"位置_icon"] forState:UIControlStateNormal];
  261. _locationBtn.spacingBetweenImageAndTitle = 5;
  262. [_locationBtn sizeToFit];
  263. _locationBtn.height = 20;
  264. [_locationBtn setTitleColor:[UIColor colorWithHexString:@"#AAAAAA"] forState:UIControlStateNormal];
  265. [_locationBtn.titleLabel setFont:[UIFont systemFontOfSize:11]];
  266. }
  267. return _locationBtn;
  268. }
  269. - (UIButton *)topicBtn{
  270. if (!_topicBtn) {
  271. _topicBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.locationBtn.right + 10, 0, 100, 30)];
  272. [_topicBtn setTitleColor:[UIColor colorWithHexString:@"333333"] forState:UIControlStateNormal];
  273. _topicBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  274. __weak __typeof(self)weakSelf = self;
  275. [_topicBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  276. __strong __typeof(weakSelf)strongSelf = weakSelf;
  277. if (strongSelf.cell.delegate && [strongSelf.cell.delegate respondsToSelector:@selector(cell:didClickTopic:)]) {
  278. [strongSelf.cell.delegate cell:strongSelf.cell didClickTopic:strongSelf.cell.statusView.layout.status.theme];
  279. }
  280. }];
  281. }
  282. return _topicBtn;
  283. }
  284. - (void)setWithLayout:(WBStatusLayout *)layout{
  285. self.locationBtn.hidden = !layout.status.address.length;
  286. self.topicBtn.hidden = !layout.status.theme.length;
  287. if (layout.status.address.length) {
  288. [self.locationBtn setTitle:SafeStr(layout.status.address) forState:UIControlStateNormal];
  289. [self.locationBtn sizeToFit];
  290. self.locationBtn.height = 20;
  291. }
  292. if (layout.status.theme.length) {
  293. [self.topicBtn setTitle:[NSString stringWithFormat:@"#%@#",layout.status.theme] forState:UIControlStateNormal];
  294. [self.topicBtn sizeToFit];
  295. if (layout.status.address.length) {
  296. self.topicBtn.left = self.locationBtn.right + 10;
  297. }else{
  298. self.topicBtn.left = 10;
  299. }
  300. self.topicBtn.width = self.topicBtn.width + 10;
  301. self.topicBtn.height = 30;
  302. }
  303. self.topicBtn.hidden = YES;
  304. }
  305. @end
  306. @implementation WBStatusCommentBtn
  307. - (instancetype)initWithFrame:(CGRect)frame{
  308. if (self = [super initWithFrame:frame]) {
  309. self.userInteractionEnabled = NO;
  310. // self.backgroundColor = kWhiteColor;
  311. self.layer.cornerRadius = 20;
  312. self.layer.borderColor = [UIColor colorWithHexString:@"cccccc"].CGColor;
  313. self.layer.borderWidth = 1;
  314. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  315. titleLabel.text = NSLocalizedString(@"感觉不错,评论一下",nil);
  316. titleLabel.font = [UIFont systemFontOfSize:15];
  317. titleLabel.textColor = [UIColor colorWithHexString:@"cccccc"];
  318. [self addSubview:titleLabel];
  319. UILabel *sendLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  320. sendLabel.text = NSLocalizedString(@"发送",nil);
  321. sendLabel.textAlignment = NSTextAlignmentRight;
  322. sendLabel.font = [UIFont systemFontOfSize:15];
  323. sendLabel.textColor = [UIColor colorWithHexString:@"cccccc"];
  324. [self addSubview:sendLabel];
  325. UIView *lineView = [[UIView alloc]initWithFrame:CGRectZero];
  326. lineView.right = self.width - 100;
  327. lineView.backgroundColor = [UIColor colorWithHexString:@"cccccc"];
  328. [self addSubview:lineView];
  329. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  330. make.top.right.bottom.equalTo(self);
  331. make.left.equalTo(self).offset(20);
  332. }];
  333. [sendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  334. make.top.left.bottom.equalTo(self);
  335. make.right.equalTo(self).offset(-20);
  336. }];
  337. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  338. make.height.equalTo(self);
  339. make.width.mas_equalTo(@(1));
  340. make.right.equalTo(self).offset(-70);
  341. make.top.equalTo(self);
  342. }];
  343. }
  344. return self;
  345. }
  346. @end
  347. @implementation WBStatusTimeView
  348. - (instancetype)initWithFrame:(CGRect)frame{
  349. if (self = [super initWithFrame:frame]) {
  350. _timeLabel = [YYLabel new];
  351. _timeLabel.frame = CGRectMake(0, 0, 1, 20);
  352. _timeLabel.textAlignment = NSTextAlignmentRight;
  353. _timeLabel.displaysAsynchronously = YES;
  354. _timeLabel.ignoreCommonProperties = YES;
  355. _timeLabel.fadeOnAsynchronouslyDisplay = NO;
  356. _timeLabel.fadeOnHighlight = NO;
  357. _timeLabel.hidden = YES;
  358. [self addSubview:_timeLabel];
  359. }
  360. return self;
  361. }
  362. @end
  363. @implementation WBStatusToolbarView
  364. - (instancetype)initWithFrame:(CGRect)frame {
  365. frame.size.width = kScreenW;
  366. frame.size.height = kWBCellToolbarHeight;
  367. self = [super initWithFrame:frame];
  368. self.exclusiveTouch = YES;
  369. _likeSubviews = [NSMutableArray array];
  370. _praiseBtn = [[QMUIButton alloc]initWithFrame:CGRectMake(0, 0, 1, 40)];
  371. _praiseBtn.left = 15;
  372. [_praiseBtn setImagePosition:QMUIButtonImagePositionLeft];
  373. [_praiseBtn setSpacingBetweenImageAndTitle:7];
  374. [_praiseBtn.titleLabel setFont:[UIFont systemFontOfSize:11]];
  375. [_praiseBtn setImage:[UIImage imageNamed:@"mg_dy_likes"] forState:UIControlStateNormal];
  376. [_praiseBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
  377. [_praiseBtn setTitle:@"0" forState:UIControlStateNormal];
  378. _commentBtn = [[QMUIButton alloc]initWithFrame:CGRectMake(0, 0, 1, 40)];
  379. _commentBtn.left = _praiseBtn.right + 15;
  380. [_commentBtn setImagePosition:QMUIButtonImagePositionLeft];
  381. [_commentBtn setSpacingBetweenImageAndTitle:7];
  382. [_commentBtn.titleLabel setFont:[UIFont systemFontOfSize:11]];
  383. [_commentBtn setImage:[UIImage imageNamed:@"mg_dy_comment"] forState:UIControlStateNormal];
  384. [_commentBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
  385. [_commentBtn setTitle:@"0" forState:UIControlStateNormal];
  386. @weakify(self);
  387. [_commentBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) {
  388. WBStatusCell *cell = weak_self.cell;
  389. if ([cell.delegate respondsToSelector:@selector(cellDidClickComment:)]) {
  390. [cell.delegate cellDidClickComment:cell];
  391. }
  392. }];
  393. [_praiseBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) {
  394. WBStatusCell *cell = weak_self.cell;
  395. if ([cell.delegate respondsToSelector:@selector(cellDidClickLike:)]) {
  396. [cell.delegate cellDidClickLike:cell];
  397. }
  398. }];
  399. [self addSubview:_praiseBtn];
  400. [self addSubview:_commentBtn];
  401. return self;
  402. }
  403. - (void)setWithLayout:(WBStatusLayout *)layout {
  404. [_praiseBtn setImage:layout.status.is_like.integerValue ? [self likeImage] : [self unlikeImage] forState:UIControlStateNormal];
  405. [_praiseBtn setTitle:[NSString stringWithFormat:@"%@",layout.status.praise] forState:UIControlStateNormal];
  406. [_commentBtn setTitle:layout.status.comments forState:UIControlStateNormal];
  407. [_praiseBtn setSize:[_praiseBtn sizeThatFits:CGSizeMake(MAXFLOAT, 40)]];
  408. _praiseBtn.height = 40;
  409. _praiseBtn.width = _praiseBtn.width + 10;
  410. _praiseBtn.left = 15;
  411. _praiseBtn.centerY = self.height / 2;
  412. [_commentBtn setSize:[_commentBtn sizeThatFits:CGSizeMake(MAXFLOAT, 40)]];
  413. _commentBtn.height = 40;
  414. _commentBtn.width = _commentBtn.width + 10;
  415. _commentBtn.left = _praiseBtn.right + 15;
  416. _commentBtn.centerY = self.height / 2;
  417. _commentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  418. _praiseBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  419. }
  420. - (UIImage *)likeImage {
  421. static UIImage *img;
  422. static dispatch_once_t onceToken;
  423. dispatch_once(&onceToken, ^{
  424. img = [UIImage imageNamed:@"mg_dy_likes_select"];
  425. });
  426. return img;
  427. }
  428. - (UIImage *)unlikeImage {
  429. static UIImage *img;
  430. static dispatch_once_t onceToken;
  431. dispatch_once(&onceToken, ^{
  432. img = [UIImage imageNamed:@"mg_dy_likes"];
  433. });
  434. return img;
  435. }
  436. - (void)setLiked:(BOOL)liked withAnimation:(BOOL)animation {
  437. WBStatusLayout *layout = _cell.statusView.layout;
  438. UIImage *image = liked ? [self likeImage] : [self unlikeImage];
  439. int newCount = [layout.status.praise intValue];
  440. // like_count.intValue;
  441. newCount = liked ? newCount + 1 : newCount - 1;
  442. if (newCount < 0) newCount = 0;
  443. if (liked && newCount < 1) newCount = 1;
  444. NSString *newCountDesc = newCount > 0 ? [WBStatusHelper shortedNumberDesc:newCount] : @"0";
  445. UIFont *font = [UIFont systemFontOfSize:kWBCellToolbarFontSize];
  446. YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(kScreenW, kWBCellToolbarHeight)];
  447. container.maximumNumberOfRows = 1;
  448. NSMutableAttributedString *likeText = [[NSMutableAttributedString alloc] initWithString:newCountDesc];
  449. likeText.font = font;
  450. likeText.color = liked ? kWBCellToolbarTitleHighlightColor : kWBCellToolbarTitleColor;
  451. YYTextLayout *textLayout = [YYTextLayout layoutWithContainer:container text:likeText];
  452. layout.status.is_like = liked ? @"1" : @"0";
  453. layout.status.praise = [NSString stringWithFormat:@"%d",newCount];
  454. layout.toolbarLikeTextLayout = textLayout;
  455. [_praiseBtn setTitle:[NSString stringWithFormat:@"%@",layout.status.praise] forState:UIControlStateNormal];
  456. [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  457. _praiseBtn.imageView.layer.transformScale = 1.7;
  458. } completion:^(BOOL finished) {
  459. [_praiseBtn setImage:image forState:UIControlStateNormal];
  460. [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  461. _praiseBtn.imageView.layer.transformScale = 0.9;
  462. } completion:^(BOOL finished) {
  463. [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  464. _praiseBtn.imageView.layer.transformScale = 1;
  465. } completion:^(BOOL finished) {
  466. }];
  467. }];
  468. }];
  469. }
  470. @end
  471. @implementation WBStatusView {
  472. BOOL _touchRetweetView;
  473. }
  474. - (instancetype)initWithFrame:(CGRect)frame {
  475. if (frame.size.width == 0 && frame.size.height == 0) {
  476. frame.size.width = kScreenW;
  477. frame.size.height = 1;
  478. }
  479. self = [super initWithFrame:frame];
  480. self.backgroundColor = [UIColor clearColor];
  481. self.exclusiveTouch = YES;
  482. @weakify(self);
  483. _contentView = [UIView new];
  484. _contentView.width = kScreenW;
  485. _contentView.height = 1;
  486. _contentView.backgroundColor = [UIColor clearColor];
  487. static UIImage *topLineBG, *bottomLineBG;
  488. static dispatch_once_t onceToken;
  489. dispatch_once(&onceToken, ^{
  490. topLineBG = [UIImage imageWithSize:CGSizeMake(1, 3) drawBlock:^(CGContextRef context) {
  491. CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
  492. CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 0.8, [UIColor colorWithWhite:0 alpha:0.08].CGColor);
  493. CGContextAddRect(context, CGRectMake(-2, 3, 4, 4));
  494. CGContextFillPath(context);
  495. }];
  496. bottomLineBG = [UIImage imageWithSize:CGSizeMake(1, 3) drawBlock:^(CGContextRef context) {
  497. CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
  498. CGContextSetShadowWithColor(context, CGSizeMake(0, 0.4), 2, [UIColor colorWithWhite:0 alpha:0.08].CGColor);
  499. CGContextAddRect(context, CGRectMake(-2, -2, 4, 2));
  500. CGContextFillPath(context);
  501. }];
  502. });
  503. UIImageView *topLine = [[UIImageView alloc] initWithImage:topLineBG];
  504. topLine.left = 15;
  505. topLine.width = _contentView.width - 15 * 2;
  506. topLine.bottom = 0;
  507. topLine.height = 1;
  508. topLine.image = [UIImage imageNamed:@"dynaminclistcell_linebg"];
  509. // topLine.hidden = YES;
  510. // topLine.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
  511. topLine.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
  512. [_contentView addSubview:topLine];
  513. UIImageView *bottomLine = [[UIImageView alloc] initWithImage:bottomLineBG];
  514. bottomLine.top = _contentView.height;
  515. bottomLine.left = 12;
  516. bottomLine.width = _contentView.width - 12 * 2;
  517. bottomLine.hidden = YES;
  518. bottomLine.height = 2;
  519. bottomLine.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
  520. bottomLine.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
  521. [_contentView addSubview:bottomLine];
  522. [self addSubview:_contentView];
  523. _profileView = [WBStatusProfileView new];
  524. [_contentView addSubview:_profileView];
  525. _textLabel = [YYLabel new];
  526. _textLabel.left = kWBCellPadding;
  527. _textLabel.width = kWBCellContentWidth;
  528. _textLabel.textVerticalAlignment = YYTextVerticalAlignmentTop;
  529. _textLabel.displaysAsynchronously = YES;
  530. _textLabel.ignoreCommonProperties = YES;
  531. _textLabel.fadeOnAsynchronouslyDisplay = NO;
  532. _textLabel.fadeOnHighlight = NO;
  533. _textLabel.highlightTapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
  534. if ([weak_self.cell.delegate respondsToSelector:@selector(cell:didClickInLabel:textRange:)]) {
  535. [weak_self.cell.delegate cell:weak_self.cell didClickInLabel:(YYLabel *)containerView textRange:range];
  536. }
  537. };
  538. [_contentView addSubview:_textLabel];
  539. // _audioBtn = [[NSBundle mainBundle] loadNibNamed:@"BogoDynamicAudioButton" owner:nil options:nil].lastObject;
  540. // _audioBtn.frame = CGRectMake(10, 0, 148, 40);
  541. // _audioBtn.hidden = YES;
  542. // _audioBtn.deleteBtn.hidden = YES;
  543. // [_audioBtn addTapBlock:^(UIButton *btn) {
  544. // if (weak_self.cell.delegate && [weak_self.cell.delegate respondsToSelector:@selector(cell:didClickAudio:)]) {
  545. // [weak_self.cell.delegate cell:self didClickAudio:btn];
  546. // }
  547. // }];
  548. // [self addSubview:_audioBtn];
  549. NSMutableArray *picViews = [NSMutableArray new];
  550. for (int i = 0; i < 9; i++) {
  551. YYControl *imageView = [YYControl new];
  552. imageView.size = CGSizeMake(100, 100);
  553. imageView.hidden = YES;
  554. imageView.clipsToBounds = YES;
  555. imageView.layer.cornerRadius = 5;
  556. imageView.backgroundColor = kWBCellHighlightColor;
  557. imageView.exclusiveTouch = YES;
  558. imageView.touchBlock = ^(YYControl *view, YYGestureRecognizerState state, NSSet *touches, UIEvent *event) {
  559. if (![weak_self.cell.delegate respondsToSelector:@selector(cell:didClickImageAtIndex:)]) return;
  560. if (state == YYGestureRecognizerStateEnded) {
  561. UITouch *touch = touches.anyObject;
  562. CGPoint p = [touch locationInView:view];
  563. if (CGRectContainsPoint(view.bounds, p)) {
  564. [weak_self.cell.delegate cell:weak_self.cell didClickImageAtIndex:i];
  565. }
  566. }
  567. };
  568. UIView *badge = [UIImageView new];
  569. badge.userInteractionEnabled = NO;
  570. badge.contentMode = UIViewContentModeScaleAspectFit;
  571. badge.size = CGSizeMake(56 / 2, 36 / 2);
  572. badge.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
  573. badge.right = imageView.width;
  574. badge.bottom = imageView.height;
  575. badge.hidden = YES;
  576. [imageView addSubview:badge];
  577. [picViews addObject:imageView];
  578. [_contentView addSubview:imageView];
  579. }
  580. _picViews = picViews;
  581. _locationView = [WBStatusLocationView new];
  582. [_contentView addSubview:_locationView];
  583. _cardView = [WBStatusCardView new];
  584. _cardView.tag = 100;
  585. _cardView.hidden = YES;
  586. _cardView.layer.cornerRadius = 4;
  587. _cardView.layer.masksToBounds = YES;
  588. [_contentView addSubview:_cardView];
  589. _timeView = [WBStatusTimeView new];
  590. [_contentView addSubview:_timeView];
  591. _toolbarView = [WBStatusToolbarView new];
  592. [_contentView addSubview:_toolbarView];
  593. // _commentBtn = [WBStatusCommentBtn new];
  594. // [_contentView addSubview:_commentBtn];
  595. //删除按钮
  596. _deleteBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
  597. _deleteBtn.right = self.width - kWBCellPadding;
  598. [_deleteBtn setTitle:ASLocalizedString(@"删除") forState:UIControlStateNormal];
  599. [_deleteBtn setTitleColor:[UIColor colorWithHexString:@"#8C90E9"] forState:UIControlStateNormal];
  600. _deleteBtn.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
  601. // [_deleteBtn setBackgroundImage:[UIImage imageNamed:@"img_dynamic_focus_bg"] forState:UIControlStateNormal];
  602. __weak __typeof(self)weakSelf = self;
  603. [_deleteBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  604. __strong __typeof(weakSelf)strongSelf = weakSelf;
  605. if (strongSelf.cell.delegate && [strongSelf.cell.delegate respondsToSelector:@selector(cell:didClickDeleteBtn:)]) {
  606. [strongSelf.cell.delegate cell:strongSelf.cell didClickDeleteBtn:sender];
  607. }
  608. }];
  609. _deleteBtn.hidden = YES;
  610. [_contentView addSubview:_deleteBtn];
  611. _lineView = [UIView new];
  612. _lineView.backgroundColor = [UIColor colorWithHexString:@"#E6E6E6"];
  613. // [_contentView addSubview:_lineView];
  614. return self;
  615. }
  616. - (void)setIsfollow:(BOOL)isfollow{
  617. _isfollow=isfollow;
  618. // _profileView.moreBtn.hidden=isfollow;
  619. _profileView.moreBtn.hidden = YES;
  620. }
  621. - (void)setLayout:(WBStatusLayout *)layout {
  622. _layout = layout;
  623. self.height = layout.height;
  624. _contentView.top = layout.marginTop;
  625. _contentView.height = layout.height - layout.marginTop - layout.marginBottom;
  626. CGFloat top = 0;
  627. _profileView.nameLabel.textLayout = layout.nameTextLayout;
  628. [_profileView.nameLabel sizeToFit];
  629. _profileView.topBtn.left = _profileView.nameLabel.right + 3;
  630. _profileView.topBtn.hidden = layout.status.is_top.intValue == 0;
  631. _profileView.sourceLabel.textLayout = layout.sourceTextLayout;
  632. _profileView.timeLabel.textLayout = layout.sourceTextLayout;
  633. // _profileView.sexView.hidden = self.cell.isShowMore;
  634. // _profileView.levelView.hidden = self.cell.isShowMore;
  635. // _profileView.locationView.hidden = self.cell.isShowMore;
  636. // if (![layout.status.userInfo.id isEqualToString:[IMAPlatform sharedInstance].host.userId]) {
  637. _profileView.sourceLabel.hidden = YES;
  638. [_profileView.sourceLabel setSize:[_profileView.sourceLabel sizeThatFits:CGSizeMake(MAXFLOAT, MAXFLOAT)]];
  639. _profileView.sourceLabel.right = self.width - kWBCellPadding;
  640. _profileView.sourceLabel.centerY = _profileView.nameLabel.centerY;
  641. // }else{
  642. // _profileView.sourceLabel.hidden = YES;
  643. [_profileView.timeLabel setSize:[_profileView.timeLabel sizeThatFits:CGSizeMake(MAXFLOAT, MAXFLOAT)]];
  644. _profileView.timeLabel.left = _profileView.nameLabel.left;
  645. _profileView.timeLabel.top = _profileView.nameLabel.bottom + 5;
  646. // }
  647. _timeView.timeLabel.textLayout = layout.sourceTextLayout;
  648. [_timeView.timeLabel setSize:[_profileView.timeLabel sizeThatFits:CGSizeMake(MAXFLOAT, MAXFLOAT)]];
  649. [_timeView setSize:[_profileView.timeLabel sizeThatFits:CGSizeMake(MAXFLOAT, MAXFLOAT)]];
  650. [_profileView.sexView setSex:BogoMale age:@16];
  651. _profileView.statusView.left = _profileView.sexView.right + 10;
  652. _profileView.statusView.hidden = YES;
  653. _profileView.height = layout.profileHeight;
  654. _profileView.top = top;
  655. top += layout.profileHeight;
  656. // _audioBtn.top = top + 15;
  657. // _audioBtn.height = 40;
  658. // top += layout.status.audio.length ? 55 : 5;
  659. // _audioBtn.hidden = YES;
  660. // !layout.status.audio.length;
  661. // _audioBtn.timeLabel.text = [NSString stringWithFormat:@"%@s",layout.status.audio_duration];
  662. // _audioBtn.imgView.animationRepeatCount = layout.status.audio_duration.integerValue * 2;
  663. _textLabel.top = top;
  664. _textLabel.height = layout.textHeight;
  665. _textLabel.textLayout = layout.textLayout;
  666. top += layout.textHeight;
  667. if (_textLabel.height == 0) {
  668. top += kWBCellPadding;
  669. }
  670. _retweetBackgroundView.hidden = YES;
  671. _retweetTextLabel.hidden = YES;
  672. // _cardView.hidden = YES;
  673. if (layout.picHeight == 0) {
  674. [self _hideImageViews];
  675. }
  676. if (layout.picHeight > 0) {
  677. [self _setImageViewWithTop:top isRetweet:NO];
  678. }
  679. if (layout.cardHeight > 0) {
  680. _cardView.top = top;
  681. _cardView.hidden = NO;
  682. [_cardView setWithLayout:layout isRetweet:NO];
  683. }else{
  684. _cardView.hidden = YES;
  685. }
  686. [_locationView setWithLayout:layout];
  687. if (StrValid(layout.status.address)) {
  688. CGSize locationSize = [_locationView sizeThatFits:CGSizeMake(MAXFLOAT, 20)];
  689. [_locationView setSize:CGSizeMake(locationSize.width, 20)];
  690. _locationView.hidden = NO;
  691. }else{
  692. _locationView.hidden = YES;
  693. }
  694. /// 圆角头像
  695. if (layout.status.no_name.intValue == 1 && ![layout.status.uid isEqualToString:[BGIMLoginManager sharedInstance].loginParam.identifier]) {
  696. _profileView.avatarView.image = [UIImage imageNamed:@"匿名头像"];
  697. _profileView.moreBtn.hidden = YES;
  698. }else{
  699. if (layout.status.is_focus.integerValue != 1 && ![layout.status.uid isEqualToString:[BGIMLoginManager sharedInstance].loginParam.identifier]) {
  700. _profileView.moreBtn.hidden = NO;
  701. }else{
  702. _profileView.moreBtn.hidden = YES;
  703. }
  704. [_profileView.avatarView setImageWithURL:[NSURL URLWithString:layout.status.head_image] //profileImageURL
  705. placeholder:nil
  706. options:kNilOptions
  707. manager:nil
  708. progress:nil
  709. transform:nil
  710. completion:nil];// 圆角头像manager,内置圆角处理
  711. }
  712. if ([layout.status.uid isEqualToString:[BGIMLoginManager sharedInstance].loginParam.identifier]) {
  713. self.deleteBtn.hidden = NO;
  714. }else{
  715. self.deleteBtn.hidden = YES;
  716. }
  717. _toolbarView.bottom = _contentView.height - 10;
  718. _timeView.top = _toolbarView.top;
  719. _timeView.left = 15;
  720. _locationView.centerY = _timeView.centerY;
  721. _deleteBtn.centerY = _toolbarView.centerY;
  722. _locationView.left = _timeView.right;
  723. [_toolbarView setWithLayout:layout];
  724. }
  725. - (void)_hideImageViews {
  726. for (UIImageView *imageView in _picViews) {
  727. imageView.hidden = YES;
  728. }
  729. }
  730. - (void)_setImageViewWithTop:(CGFloat)imageTop isRetweet:(BOOL)isRetweet {
  731. CGFloat len1_3 = (kWBCellContentWidth + kWBCellPaddingPic) / 3 - kWBCellPaddingPic;
  732. len1_3 = CGFloatPixelRound(len1_3);
  733. CGSize picSize = CGSizeMake(len1_3, len1_3);
  734. NSArray *pics = _layout.status.picUrls;
  735. int picsCount = (int)pics.count;
  736. for (int i = 0; i < 9; i++) {
  737. UIView *imageView = _picViews[i];
  738. if (i >= picsCount) {
  739. [imageView.layer cancelCurrentImageRequest];
  740. imageView.hidden = YES;
  741. } else {
  742. CGPoint origin = {0};
  743. switch (picsCount) {
  744. case 1: {
  745. origin.x = kWBCellPadding;
  746. origin.y = imageTop;
  747. } break;
  748. case 4: {
  749. origin.x = kWBCellPadding + (i % 2) * (picSize.width + kWBCellPaddingPic);
  750. origin.y = imageTop + (int)(i / 2) * (picSize.height + kWBCellPaddingPic);
  751. } break;
  752. default: {
  753. origin.x = kWBCellPadding + (i % 3) * (picSize.width + kWBCellPaddingPic);
  754. origin.y = imageTop + (int)(i / 3) * (picSize.height + kWBCellPaddingPic);
  755. } break;
  756. }
  757. imageView.frame = (CGRect){.origin = origin, .size = picSize};
  758. imageView.hidden = NO;
  759. [imageView.layer removeAnimationForKey:@"contents"];
  760. NSString *pic = pics[i];
  761. // UIView *badge = imageView.subviews.firstObject;
  762. // switch (pic.largest.badgeType) {
  763. // case WBPictureBadgeTypeNone: {
  764. // if (badge.layer.contents) {
  765. // badge.layer.contents = nil;
  766. // badge.hidden = YES;
  767. // }
  768. // } break;
  769. // case WBPictureBadgeTypeLong: {
  770. // badge.layer.contents = (__bridge id)([WBStatusHelper imageNamed:@"timeline_image_longimage"].CGImage);
  771. // badge.hidden = NO;
  772. // } break;
  773. // case WBPictureBadgeTypeGIF: {
  774. // badge.layer.contents = (__bridge id)([WBStatusHelper imageNamed:@"timeline_image_gif"].CGImage);
  775. // badge.hidden = NO;
  776. // } break;
  777. // }
  778. @weakify(imageView);
  779. [imageView.layer setImageWithURL:[NSURL URLWithString:pic]
  780. placeholder:nil
  781. options:YYWebImageOptionAvoidSetImage
  782. completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) {
  783. @strongify(imageView);
  784. if (!imageView) return;
  785. if (image && stage == YYWebImageStageFinished) {
  786. int width = len1_3;
  787. int height = len1_3;
  788. CGFloat scale = (height / width) / (imageView.height / imageView.width);
  789. if (scale < 0.99 || isnan(scale)) { // 宽图把左右两边裁掉
  790. imageView.contentMode = UIViewContentModeScaleAspectFill;
  791. imageView.layer.contentsRect = CGRectMake(0, 0, 1, 1);
  792. } else { // 高图只保留顶部
  793. imageView.contentMode = UIViewContentModeScaleAspectFill;
  794. imageView.layer.contentsRect = CGRectMake(0, 0, 1, (float)width / height);
  795. }
  796. ((YYControl *)imageView).image = image;
  797. if (from != YYWebImageFromMemoryCacheFast) {
  798. CATransition *transition = [CATransition animation];
  799. transition.duration = 0.15;
  800. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  801. transition.type = kCATransitionFade;
  802. [imageView.layer addAnimation:transition forKey:@"contents"];
  803. }
  804. }
  805. }];
  806. }
  807. }
  808. }
  809. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  810. UITouch *touch = touches.anyObject;
  811. CGPoint p = [touch locationInView:_retweetBackgroundView];
  812. BOOL insideRetweet = CGRectContainsPoint(_retweetBackgroundView.bounds, p);
  813. if (!_retweetBackgroundView.hidden && insideRetweet) {
  814. [(_retweetBackgroundView) performSelector:@selector(setBackgroundColor:) withObject:kWBCellHighlightColor afterDelay:0.15];
  815. _touchRetweetView = YES;
  816. } else {
  817. [(_contentView) performSelector:@selector(setBackgroundColor:) withObject:kWBCellHighlightColor afterDelay:0.15];
  818. _touchRetweetView = NO;
  819. }
  820. }
  821. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  822. [self touchesRestoreBackgroundColor];
  823. if (_touchRetweetView) {
  824. if ([_cell.delegate respondsToSelector:@selector(cellDidClickRetweet:)]) {
  825. [_cell.delegate cellDidClickRetweet:_cell];
  826. }
  827. } else {
  828. UITouch *touch = touches.anyObject;
  829. if (CGRectContainsPoint(self.locationView.topicBtn.frame, [touch locationInView:self.locationView])) {
  830. if (self.cell.delegate && [self.cell.delegate respondsToSelector:@selector(cell:didClickTopic:)]) {
  831. [self.cell.delegate cell:self.cell didClickTopic:self.cell.statusView.layout.status.theme];
  832. }
  833. }else{
  834. if ([_cell.delegate respondsToSelector:@selector(cellDidClick:)]) {
  835. [_cell.delegate cellDidClick:_cell];
  836. }
  837. }
  838. }
  839. }
  840. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
  841. [self touchesRestoreBackgroundColor];
  842. }
  843. - (void)touchesRestoreBackgroundColor {
  844. [NSObject cancelPreviousPerformRequestsWithTarget:_retweetBackgroundView selector:@selector(setBackgroundColor:) object:kWBCellHighlightColor];
  845. [NSObject cancelPreviousPerformRequestsWithTarget:_contentView selector:@selector(setBackgroundColor:) object:kWBCellHighlightColor];
  846. _contentView.backgroundColor = [UIColor clearColor];
  847. _retweetBackgroundView.backgroundColor = kWBCellInnerViewColor;
  848. }
  849. @end
  850. @implementation WBStatusCell
  851. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  852. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  853. _statusView = [WBStatusView new];
  854. _statusView.cell = self;
  855. _statusView.profileView.cell = self;
  856. _statusView.cardView.cell = self;
  857. _statusView.toolbarView.cell = self;
  858. _statusView.locationView.cell = self;
  859. [self.contentView addSubview:_statusView];
  860. return self;
  861. }
  862. - (void)prepareForReuse {
  863. // ignore
  864. }
  865. - (void)setLayout:(WBStatusLayout *)layout {
  866. _layout = layout;
  867. self.height = layout.height;
  868. self.contentView.height = layout.height;
  869. _statusView.layout = layout;
  870. }
  871. - (void)setIsfollow:(BOOL)isfollow{
  872. _isfollow=isfollow;
  873. _statusView.isfollow=isfollow;
  874. }
  875. @end