JXCardCell.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // JXCardCell.m
  3. // shiku_im
  4. //
  5. // Created by Apple on 16/10/10.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXCardCell.h"
  9. #import "JXMessageObject.h"
  10. #import "JXServer.h"
  11. #import "AppDelegate.h"
  12. @implementation JXCardCell
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. // Initialization code
  16. }
  17. -(void)creatUI{
  18. _imageBackground =[[UIImageView alloc]initWithFrame:CGRectZero];
  19. [_imageBackground setBackgroundColor:[UIColor clearColor]];
  20. _imageBackground.layer.cornerRadius = 6;
  21. _imageBackground.layer.masksToBounds = YES;
  22. [self.bubbleBg addSubview:_imageBackground];
  23. // [_imageBackground release];
  24. //
  25. _cardHeadImage = [[UIImageView alloc]init];
  26. _cardHeadImage.frame = CGRectMake(15,15, 50, 50);
  27. _cardHeadImage.userInteractionEnabled = NO;
  28. [_imageBackground addSubview:_cardHeadImage];
  29. _nameLabel = [[UILabel alloc]init];
  30. _nameLabel.frame = CGRectMake(CGRectGetMaxX(_cardHeadImage.frame) + 10,25, 100, 30);
  31. _nameLabel.font = g_factory.font15;
  32. _nameLabel.userInteractionEnabled = NO;
  33. [_imageBackground addSubview:_nameLabel];
  34. _lineView = [[UIView alloc] init];
  35. _lineView.backgroundColor = THE_LINE_COLOR;
  36. [_imageBackground addSubview:_lineView];
  37. _title = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 30)];
  38. _title.text = Localized(@"JX_BusinessCard");
  39. _title.font = SYSFONT(13);
  40. _title.textColor = [UIColor grayColor];
  41. [_imageBackground addSubview:_title];
  42. }
  43. -(void)setCellData{
  44. [super setCellData];
  45. int n = imageItemHeight;
  46. if(self.msg.isMySend)
  47. {
  48. self.bubbleBg.frame=CGRectMake(CGRectGetMinX(self.headImage.frame)- kChatCellMaxWidth-CHAT_WIDTH_ICON, INSETS, kChatCellMaxWidth, n+INSETS -4);
  49. _imageBackground.frame = self.bubbleBg.bounds;
  50. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_blue"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  51. }
  52. else
  53. {
  54. self.bubbleBg.frame=CGRectMake(CGRectGetMaxX(self.headImage.frame) + CHAT_WIDTH_ICON, INSETS2(self.msg.isGroup), kChatCellMaxWidth, n+INSETS -4);
  55. _imageBackground.frame = self.bubbleBg.bounds;
  56. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_white"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  57. }
  58. _lineView.frame = CGRectMake(0, _imageBackground.frame.size.height - 30, _imageBackground.frame.size.width, LINE_WH);
  59. _title.frame = CGRectMake(15, _imageBackground.frame.size.height - 30, 200, 30);
  60. if (self.msg.isShowTime) {
  61. CGRect frame = self.bubbleBg.frame;
  62. frame.origin.y = self.bubbleBg.frame.origin.y + 40;
  63. self.bubbleBg.frame = frame;
  64. }
  65. [self setMaskLayer:_imageBackground];
  66. [g_server getHeadImageSmall:self.msg.objectId userName:self.msg.content imageView:_cardHeadImage];
  67. _nameLabel.text = self.msg.content;
  68. if(!self.msg.isMySend)
  69. [self drawIsRead];
  70. }
  71. //未读红点
  72. -(void)drawIsRead{
  73. if (self.msg.isMySend) {
  74. return;
  75. }
  76. if([self.msg.isRead boolValue]){
  77. self.readImage.hidden = YES;
  78. }
  79. else{
  80. if(self.readImage==nil){
  81. self.readImage=[[UIButton alloc]init];
  82. [self.contentView addSubview:self.readImage];
  83. // [self.readImage release];
  84. }
  85. [self.readImage setImage:[UIImage imageNamed:@"new_tips"] forState:UIControlStateNormal];
  86. self.readImage.hidden = NO;
  87. self.readImage.frame = CGRectMake(self.bubbleBg.frame.origin.x+self.bubbleBg.frame.size.width+7, self.bubbleBg.frame.origin.y+13, 8, 8);
  88. self.readImage.center = CGPointMake(self.readImage.center.x, self.bubbleBg.center.y);
  89. }
  90. }
  91. -(void)didTouch:(UIButton*)button{
  92. [self.msg sendAlreadyReadMsg];
  93. if (self.msg.isGroup) {
  94. self.msg.isRead = [NSNumber numberWithInt:1];
  95. [self.msg updateIsRead:nil msgId:self.msg.messageId];
  96. }
  97. if(!self.msg.isMySend){
  98. [self drawIsRead];
  99. }
  100. [g_notify postNotificationName:kCellShowCardNotifaction object:self.msg];
  101. }
  102. + (float)getChatCellHeight:(JXMessageObject *)msg {
  103. if ([msg.chatMsgHeight floatValue] > 1) {
  104. return [msg.chatMsgHeight floatValue];
  105. }
  106. float n = 0;
  107. if (msg.isGroup && !msg.isMySend) {
  108. if (msg.isShowTime) {
  109. n = imageItemHeight+20*2 + 40;
  110. }else {
  111. n = imageItemHeight+20*2;
  112. }
  113. n += GROUP_CHAT_INSET;
  114. }else {
  115. if (msg.isShowTime) {
  116. n = imageItemHeight+10*2 + 40;
  117. }else {
  118. n = imageItemHeight+10*2;
  119. }
  120. }
  121. msg.chatMsgHeight = [NSString stringWithFormat:@"%f",n];
  122. if (!msg.isNotUpdateHeight) {
  123. [msg updateChatMsgHeight];
  124. }
  125. return n;
  126. }
  127. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  128. [super setSelected:selected animated:animated];
  129. // Configure the view for the selected state
  130. }
  131. @end