JXShareCell.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // JXShareCell.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/11/3.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXShareCell.h"
  9. @implementation JXShareCell
  10. -(void)creatUI{
  11. _imageBackground =[[UIImageView alloc]initWithFrame:CGRectZero];
  12. [_imageBackground setBackgroundColor:[UIColor clearColor]];
  13. _imageBackground.layer.cornerRadius = 6;
  14. _imageBackground.layer.masksToBounds = YES;
  15. [self.bubbleBg addSubview:_imageBackground];
  16. _title = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, _imageBackground.frame.size.width - 20,20)];
  17. _title.font = [UIFont systemFontOfSize:16.0];
  18. _title.numberOfLines = 2;
  19. _title.text = @"哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈";
  20. [_imageBackground addSubview:_title];
  21. _shareImage =[[UIImageView alloc] initWithFrame:CGRectMake(self.bubbleBg.frame.size.width - 5 - 50, CGRectGetMaxY(_title.frame) + 5, 50, 50)];
  22. _shareImage.backgroundColor = [UIColor grayColor];
  23. [_imageBackground addSubview:_shareImage];
  24. _subTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(_title.frame) + 5, self.bubbleBg.frame.size.width - 50 - 20, 50)];
  25. _subTitle.font = [UIFont systemFontOfSize:14.0];
  26. _subTitle.numberOfLines = 3;
  27. _subTitle.textColor = [UIColor lightGrayColor];
  28. _subTitle.text = @"呵呵呵呵呵呵呵呵呵呵哈哈哈哈哈哈哈哈哈哈呵呵呵呵呵额呵呵呵呵呵呵";
  29. [_imageBackground addSubview:_subTitle];
  30. _lineView = [[UIView alloc] init];
  31. _lineView.backgroundColor = THE_LINE_COLOR;
  32. [_imageBackground addSubview:_lineView];
  33. _skIcon = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 15, 15)];
  34. _skIcon.image = [UIImage imageNamed:@"ALOGO_1200"];
  35. [_imageBackground addSubview:_skIcon];
  36. _skLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_skIcon.frame) + 5, 10, 100, 30)];
  37. _skLabel.text = APP_NAME;
  38. _skLabel.font = SYSFONT(14);
  39. _skLabel.textColor = [UIColor grayColor];
  40. [_imageBackground addSubview:_skLabel];
  41. }
  42. -(void)setCellData{
  43. [super setCellData];
  44. NSDictionary * msgDict = [[[SBJsonParser alloc]init]objectWithString:self.msg.objectId];
  45. _title.text = [msgDict objectForKey:@"title"];
  46. _subTitle.text = [msgDict objectForKey:@"subTitle"];
  47. if ([msgDict objectForKey:@"imageUrl"]) {
  48. [_shareImage sd_setImageWithURL:[NSURL URLWithString:[msgDict objectForKey:@"imageUrl"]] placeholderImage:[UIImage imageNamed:@""]];
  49. }else {
  50. [_shareImage sd_setImageWithURL:[NSURL URLWithString:[msgDict objectForKey:@"appIcon"]] placeholderImage:[UIImage imageNamed:@""]];
  51. }
  52. _skLabel.text = [msgDict objectForKey:@"appName"];
  53. [_skIcon sd_setImageWithURL:[NSURL URLWithString:[msgDict objectForKey:@"appIcon"]] placeholderImage:[UIImage imageNamed:@"ALOGO_1200"]];
  54. if(self.msg.isMySend)
  55. {
  56. self.bubbleBg.frame=CGRectMake(CGRectGetMinX(self.headImage.frame)- kChatCellMaxWidth - CHAT_WIDTH_ICON, INSETS, kChatCellMaxWidth, 125);
  57. _imageBackground.frame = self.bubbleBg.bounds;
  58. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_blue"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  59. }
  60. else
  61. {
  62. self.bubbleBg.frame=CGRectMake(CGRectGetMaxX(self.headImage.frame) + CHAT_WIDTH_ICON, INSETS2(self.msg.isGroup), kChatCellMaxWidth, 125);
  63. _imageBackground.frame = self.bubbleBg.bounds;
  64. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_white"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  65. }
  66. CGFloat x = self.msg.isMySend ? (kChatCellMaxWidth / 32.25) : (kChatCellMaxWidth / 17.2);
  67. CGSize size = [_title.text boundingRectWithSize:CGSizeMake(self.bubbleBg.frame.size.width - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: _title.font} context:nil].size;
  68. _title.frame = CGRectMake(x, _title.frame.origin.y, _imageBackground.frame.size.width - 20, 20);
  69. size = [_subTitle.text boundingRectWithSize:CGSizeMake(self.bubbleBg.frame.size.width - 50 - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: _subTitle.font} context:nil].size;
  70. _subTitle.frame = CGRectMake(x, CGRectGetMaxY(_title.frame) + 5, _imageBackground.frame.size.width - 50 - 30, 55);
  71. _shareImage.frame = CGRectMake(CGRectGetMaxX(_subTitle.frame) + 5, CGRectGetMaxY(_title.frame) + 5, 50, 50);
  72. _lineView.frame = CGRectMake(0, CGRectGetMaxY(_shareImage.frame) + 10, _imageBackground.frame.size.width, LINE_WH);
  73. _skIcon.frame = CGRectMake(x, CGRectGetMaxY(_lineView.frame) + 7, 15, 15);
  74. _skLabel.frame = CGRectMake(_skLabel.frame.origin.x, CGRectGetMaxY(_shareImage.frame) + 10, 200, 30);
  75. if (self.msg.isShowTime) {
  76. CGRect frame = self.bubbleBg.frame;
  77. frame.origin.y = self.bubbleBg.frame.origin.y + 40;
  78. self.bubbleBg.frame = frame;
  79. }
  80. [self setMaskLayer:_imageBackground];
  81. if(!self.msg.isMySend)
  82. [self drawIsRead];
  83. }
  84. //未读红点
  85. -(void)drawIsRead{
  86. if (self.msg.isMySend) {
  87. return;
  88. }
  89. if([self.msg.isRead boolValue]){
  90. self.readImage.hidden = YES;
  91. }
  92. else{
  93. if(self.readImage==nil){
  94. self.readImage=[[UIButton alloc]init];
  95. [self.contentView addSubview:self.readImage];
  96. // [self.readImage release];
  97. }
  98. [self.readImage setImage:[UIImage imageNamed:@"new_tips"] forState:UIControlStateNormal];
  99. self.readImage.hidden = NO;
  100. self.readImage.frame = CGRectMake(self.bubbleBg.frame.origin.x+self.bubbleBg.frame.size.width+7, self.bubbleBg.frame.origin.y+13, 8, 8);
  101. self.readImage.center = CGPointMake(self.readImage.center.x, self.bubbleBg.center.y);
  102. }
  103. }
  104. -(void)didTouch:(UIButton*)button{
  105. [self.msg sendAlreadyReadMsg];
  106. if (self.msg.isGroup) {
  107. self.msg.isRead = [NSNumber numberWithInt:1];
  108. [self.msg updateIsRead:nil msgId:self.msg.messageId];
  109. }
  110. if(!self.msg.isMySend){
  111. [self drawIsRead];
  112. }
  113. [g_notify postNotificationName:kCellShareNotification object:self.msg];
  114. }
  115. + (float)getChatCellHeight:(JXMessageObject *)msg {
  116. if ([msg.chatMsgHeight floatValue] > 1) {
  117. return [msg.chatMsgHeight floatValue];
  118. }
  119. float n = 0;
  120. if (msg.isGroup && !msg.isMySend) {
  121. if (msg.isShowTime) {
  122. n = 125 + 20 + 40 + INSETS * 2;
  123. }else {
  124. n = 125 + 20 + INSETS * 2;
  125. }
  126. n += GROUP_CHAT_INSET;
  127. }else {
  128. if (msg.isShowTime) {
  129. n = 125 + 40 + INSETS * 2;
  130. }else {
  131. n = 125 + INSETS * 2;
  132. }
  133. }
  134. msg.chatMsgHeight = [NSString stringWithFormat:@"%f",n];
  135. if (!msg.isNotUpdateHeight) {
  136. [msg updateChatMsgHeight];
  137. }
  138. return n;
  139. }
  140. @end