JXLinkCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // JXLinkCell.m
  3. // shiku_im
  4. //
  5. // Created by p on 2017/8/17.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "JXLinkCell.h"
  9. #import "ImageResize.h"
  10. @implementation JXLinkCell
  11. -(void)creatUI{
  12. _imageBackground =[[UIImageView alloc]initWithFrame:CGRectZero];
  13. [_imageBackground setBackgroundColor:[UIColor whiteColor]];
  14. _imageBackground.layer.cornerRadius = 6;
  15. _imageBackground.layer.masksToBounds = YES;
  16. _imageBackground.clipsToBounds = YES;
  17. [self.bubbleBg addSubview:_imageBackground];
  18. _headImageView = [[UIImageView alloc]init];
  19. _headImageView.contentMode = UIViewContentModeScaleToFill;
  20. [_imageBackground addSubview:_headImageView];
  21. _nameLabel = [[UILabel alloc]init];
  22. _nameLabel.font = g_factory.font15;
  23. _nameLabel.numberOfLines = 1;
  24. _nameLabel.textAlignment = NSTextAlignmentCenter;
  25. [_imageBackground addSubview:_nameLabel];
  26. }
  27. -(void)setCellData{
  28. [super setCellData];
  29. int n = imageItemHeight;
  30. if(self.msg.isMySend)
  31. {
  32. self.bubbleBg.frame=CGRectMake(CGRectGetMinX(self.headImage.frame)- kChatCellMaxWidth-CHAT_WIDTH_ICON, INSETS, kChatCellMaxWidth, n+INSETS -4);
  33. _imageBackground.frame = self.bubbleBg.bounds;
  34. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_blue"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  35. }
  36. else
  37. {
  38. self.bubbleBg.frame=CGRectMake(CGRectGetMaxX(self.headImage.frame) + CHAT_WIDTH_ICON, INSETS2(self.msg.isGroup), kChatCellMaxWidth, n+INSETS -4);
  39. _imageBackground.frame = self.bubbleBg.bounds;
  40. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_white"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  41. }
  42. if (self.msg.isShowTime) {
  43. CGRect frame = self.bubbleBg.frame;
  44. frame.origin.y = self.bubbleBg.frame.origin.y + 40;
  45. self.bubbleBg.frame = frame;
  46. }
  47. [self setMaskLayer:_imageBackground];
  48. _headImageView.frame = CGRectMake(0, 0, CGRectGetWidth(_imageBackground.frame), n-25);
  49. _nameLabel.frame = CGRectMake(5,n-25, CGRectGetWidth(_imageBackground.frame)-5*2, 25);
  50. SBJsonParser * parser = [[SBJsonParser alloc] init] ;
  51. id content = [parser objectWithString:self.msg.content];
  52. if ([(NSDictionary *)content objectForKey:@"title"]) {
  53. _nameLabel.text = [NSString stringWithFormat:@"[%@] %@",Localized(@"JXLink"),[(NSDictionary *)content objectForKey:@"title"]];
  54. }
  55. NSString *imgStr = [(NSDictionary *)content objectForKey:@"img"];
  56. CGFloat fl = (_headImageView.frame.size.width/_headImageView.frame.size.height);
  57. if (imgStr.length > 0) {
  58. [_headImageView sd_setImageWithURL:[NSURL URLWithString:imgStr] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  59. _headImageView.image = [ImageResize image:image fillSize:CGSizeMake((_headImageView.frame.size.height+200)*fl, _headImageView.frame.size.height+200)];
  60. }];
  61. // [_headImageView sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"Default_Gray"] options:SDWebImageRetryFailed];
  62. }else {
  63. _headImageView.image = [UIImage imageNamed:@"Default_Gray"];
  64. }
  65. if(!self.msg.isMySend)
  66. [self drawIsRead];
  67. }
  68. //未读红点
  69. -(void)drawIsRead{
  70. if (self.msg.isMySend) {
  71. return;
  72. }
  73. if([self.msg.isRead boolValue]){
  74. self.readImage.hidden = YES;
  75. }
  76. else{
  77. if(self.readImage==nil){
  78. self.readImage=[[UIButton alloc]init];
  79. [self.contentView addSubview:self.readImage];
  80. // [self.readImage release];
  81. }
  82. [self.readImage setImage:[UIImage imageNamed:@"new_tips"] forState:UIControlStateNormal];
  83. self.readImage.hidden = NO;
  84. self.readImage.frame = CGRectMake(self.bubbleBg.frame.origin.x+self.bubbleBg.frame.size.width+7, self.bubbleBg.frame.origin.y+13, 8, 8);
  85. self.readImage.center = CGPointMake(self.readImage.center.x, self.bubbleBg.center.y);
  86. }
  87. }
  88. -(void)didTouch:(UIButton*)button{
  89. [self.msg sendAlreadyReadMsg];
  90. if (self.msg.isGroup) {
  91. self.msg.isRead = [NSNumber numberWithInt:1];
  92. [self.msg updateIsRead:nil msgId:self.msg.messageId];
  93. }
  94. if(!self.msg.isMySend){
  95. [self drawIsRead];
  96. }
  97. [g_notify postNotificationName:kCellSystemLinkNotifaction object:self.msg];
  98. }
  99. + (float)getChatCellHeight:(JXMessageObject *)msg {
  100. if ([msg.chatMsgHeight floatValue] > 1) {
  101. return [msg.chatMsgHeight floatValue];
  102. }
  103. float n = 0;
  104. if (msg.isGroup && !msg.isMySend) {
  105. if (msg.isShowTime) {
  106. n = imageItemHeight+20*2 + 40;
  107. }else {
  108. n = imageItemHeight+20*2;
  109. }
  110. n += GROUP_CHAT_INSET;
  111. }else {
  112. if (msg.isShowTime) {
  113. n = imageItemHeight+10*2 + 40;
  114. }else {
  115. n = imageItemHeight+10*2;
  116. }
  117. }
  118. msg.chatMsgHeight = [NSString stringWithFormat:@"%f",n];
  119. if (!msg.isNotUpdateHeight) {
  120. [msg updateChatMsgHeight];
  121. }
  122. return n;
  123. }
  124. @end