JXMergeRelayCell.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // JXMergeRelayCell.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/7/5.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXMergeRelayCell.h"
  9. @implementation JXMergeRelayCell
  10. - (void)awakeFromNib {
  11. [super awakeFromNib];
  12. // Initialization code
  13. }
  14. -(void)creatUI{
  15. _imageBackground =[[UIImageView alloc]initWithFrame:CGRectZero];
  16. [_imageBackground setBackgroundColor:[UIColor whiteColor]];
  17. _imageBackground.layer.cornerRadius = 6;
  18. // _imageBackground.image = [UIImage imageNamed:@"white"];
  19. _imageBackground.layer.masksToBounds = YES;
  20. _imageBackground.clipsToBounds = YES;
  21. [self.bubbleBg addSubview:_imageBackground];
  22. }
  23. -(void)setCellData{
  24. [super setCellData];
  25. [_imageBackground.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  26. _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, kChatCellMaxWidth, 20)];
  27. _titleLabel.font = g_factory.font15;
  28. _titleLabel.numberOfLines = 1;
  29. _titleLabel.text = self.msg.objectId;
  30. [_imageBackground addSubview:_titleLabel];
  31. SBJsonParser * parser = [[SBJsonParser alloc] init] ;
  32. NSArray *content = [parser objectWithString:self.msg.content];
  33. CGFloat y = CGRectGetMaxY(_titleLabel.frame) + 5;
  34. for (NSInteger i = 0; i < (content.count <= 3 ? content.count : 3); i ++) {
  35. NSString *str = content[i];
  36. SBJsonParser * parser = [[SBJsonParser alloc] init] ;
  37. NSDictionary *dict = [parser objectWithString:str];
  38. JXMessageObject *msg = [[JXMessageObject alloc] init];
  39. [msg fromDictionary:dict];
  40. JXEmoji *label = [[JXEmoji alloc] initWithFrame:CGRectMake(10, y, kChatCellMaxWidth, 15)];
  41. label.font = [UIFont systemFontOfSize:10.0];
  42. label.faceWidth = 14;
  43. label.faceHeight = 14;
  44. label.textColor = [UIColor lightGrayColor];
  45. if (self.msg.isGroup) {
  46. memberData *data = [self.room getMember:g_myself.userId];
  47. if (!self.room.allowSendCard && [data.role intValue] != 1 && [data.role intValue] != 2) {
  48. msg.fromUserName = [msg.fromUserName substringToIndex:[msg.fromUserName length]-1];
  49. msg.fromUserName = [msg.fromUserName stringByAppendingString:@"*"];
  50. }
  51. }
  52. label.text = [NSString stringWithFormat:@"%@: %@", msg.fromUserName, [msg getLastContent]];
  53. [_imageBackground addSubview:label];
  54. y = CGRectGetMaxY(label.frame) + 5;
  55. }
  56. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, y, kChatCellMaxWidth, LINE_WH)];
  57. lineView.backgroundColor = THE_LINE_COLOR;
  58. [_imageBackground addSubview:lineView];
  59. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, y + 5, kChatCellMaxWidth, 15)];
  60. label.textColor = [UIColor lightGrayColor];
  61. label.font = [UIFont systemFontOfSize:11.0];
  62. label.text = Localized(@"JX_ChatRecord");
  63. [_imageBackground addSubview:label];
  64. int n = CGRectGetMaxY(label.frame);
  65. if(self.msg.isMySend)
  66. {
  67. self.bubbleBg.frame=CGRectMake(CGRectGetMinX(self.headImage.frame)- kChatCellMaxWidth - CHAT_WIDTH_ICON, INSETS, kChatCellMaxWidth, n+INSETS -4);
  68. _imageBackground.frame = self.bubbleBg.bounds;
  69. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_blue"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  70. }
  71. else
  72. {
  73. self.bubbleBg.frame=CGRectMake(CGRectGetMaxX(self.headImage.frame) + CHAT_WIDTH_ICON, INSETS2(self.msg.isGroup), kChatCellMaxWidth, n+INSETS -4);
  74. _imageBackground.frame = self.bubbleBg.bounds;
  75. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_white"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  76. }
  77. if (self.msg.isShowTime) {
  78. CGRect frame = self.bubbleBg.frame;
  79. frame.origin.y = self.bubbleBg.frame.origin.y + 40;
  80. self.bubbleBg.frame = frame;
  81. }
  82. [self setMaskLayer:_imageBackground];
  83. if(!self.msg.isMySend)
  84. [self drawIsRead];
  85. }
  86. //未读红点
  87. -(void)drawIsRead{
  88. if (self.msg.isMySend) {
  89. return;
  90. }
  91. if([self.msg.isRead boolValue]){
  92. self.readImage.hidden = YES;
  93. }
  94. else{
  95. if(self.readImage==nil){
  96. self.readImage=[[UIButton alloc]init];
  97. [self.contentView addSubview:self.readImage];
  98. // [self.readImage release];
  99. }
  100. [self.readImage setImage:[UIImage imageNamed:@"new_tips"] forState:UIControlStateNormal];
  101. self.readImage.hidden = NO;
  102. self.readImage.frame = CGRectMake(self.bubbleBg.frame.origin.x+self.bubbleBg.frame.size.width+7, self.bubbleBg.frame.origin.y+13, 8, 8);
  103. self.readImage.center = CGPointMake(self.readImage.center.x, self.bubbleBg.center.y);
  104. }
  105. }
  106. -(void)didTouch:(UIButton*)button{
  107. [self.msg sendAlreadyReadMsg];
  108. if (self.msg.isGroup) {
  109. self.msg.isRead = [NSNumber numberWithInt:1];
  110. [self.msg updateIsRead:nil msgId:self.msg.messageId];
  111. }
  112. if(!self.msg.isMySend){
  113. [self drawIsRead];
  114. }
  115. [g_notify postNotificationName:kCellSystemMergeRelayNotifaction object:self.msg];
  116. }
  117. + (float)getChatCellHeight:(JXMessageObject *)msg {
  118. if ([msg.chatMsgHeight floatValue] > 1) {
  119. return [msg.chatMsgHeight floatValue];
  120. }
  121. float n = 0;
  122. SBJsonParser * parser = [[SBJsonParser alloc] init] ;
  123. NSArray *content = [parser objectWithString:msg.content];
  124. if (msg.isGroup && !msg.isMySend) {
  125. if (msg.isShowTime) {
  126. n = 55 + 20 * (content.count <= 3 ? content.count : 3) + 20*2 + 40;
  127. }else {
  128. n = 55 + 20 * (content.count <= 3 ? content.count : 3) +20*2;
  129. }
  130. n += GROUP_CHAT_INSET;
  131. }else {
  132. if (msg.isShowTime) {
  133. n = 55 + 20 * (content.count <= 3 ? content.count : 3) +10*2 + 40;
  134. }else {
  135. n = 55 + 20 * (content.count <= 3 ? content.count : 3) +10*2;
  136. }
  137. }
  138. msg.chatMsgHeight = [NSString stringWithFormat:@"%f",n];
  139. if (!msg.isNotUpdateHeight) {
  140. [msg updateChatMsgHeight];
  141. }
  142. return n;
  143. }
  144. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  145. [super setSelected:selected animated:animated];
  146. // Configure the view for the selected state
  147. }
  148. @end