JXLocationCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // JXLocationCell.m
  3. // shiku_im
  4. //
  5. // Created by Apple on 16/10/10.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXLocationCell.h"
  9. #import "JXLocationVC.h"
  10. //#import "JXClickSendedLocationVC.h"
  11. @implementation JXLocationCell
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. // Initialization code
  15. }
  16. -(void)creatUI{
  17. _imageBackground =[[UIImageView alloc]initWithFrame:CGRectZero];
  18. [_imageBackground setBackgroundColor:[UIColor whiteColor]];
  19. _imageBackground.layer.cornerRadius = 6;
  20. _imageBackground.layer.masksToBounds = YES;
  21. [self.bubbleBg addSubview:_imageBackground];
  22. _mapImageView =[[UIImageView alloc]initWithFrame:CGRectZero];
  23. [_mapImageView setBackgroundColor:[UIColor clearColor]];
  24. // _mapImageView.layer.cornerRadius = 6;
  25. _mapImageView.layer.masksToBounds = YES;
  26. _mapImageView.contentMode = UIViewContentModeScaleToFill;
  27. [_imageBackground addSubview:_mapImageView];
  28. //
  29. _addressLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  30. _addressLabel.numberOfLines = 1;
  31. _addressLabel.textAlignment = NSTextAlignmentCenter;
  32. _addressLabel.font = g_factory.font15;
  33. [_imageBackground addSubview:_addressLabel];
  34. }
  35. -(void)setCellData{
  36. [super setCellData];
  37. int n = imageItemHeight;
  38. if(self.msg.isMySend)
  39. {
  40. self.bubbleBg.frame=CGRectMake(CGRectGetMinX(self.headImage.frame)- kChatCellMaxWidth - CHAT_WIDTH_ICON, INSETS, kChatCellMaxWidth, n+INSETS -4);
  41. _imageBackground.frame = self.bubbleBg.bounds;
  42. }
  43. else
  44. {
  45. self.bubbleBg.frame=CGRectMake(CGRectGetMaxX(self.headImage.frame) + CHAT_WIDTH_ICON, INSETS2(self.msg.isGroup), kChatCellMaxWidth, n+INSETS -4);
  46. _imageBackground.frame = self.bubbleBg.bounds;
  47. }
  48. if (self.msg.isShowTime) {
  49. CGRect frame = self.bubbleBg.frame;
  50. frame.origin.y = self.bubbleBg.frame.origin.y + 40;
  51. self.bubbleBg.frame = frame;
  52. }
  53. [self setMaskLayer:_imageBackground];
  54. _mapImageView.frame = CGRectMake(0, 0, CGRectGetWidth(_imageBackground.frame), n-25);
  55. _addressLabel.frame = CGRectMake(5,n-25, CGRectGetWidth(_imageBackground.frame)-5*2, 25);
  56. NSURL* url;
  57. if(self.msg.isMySend && isFileExist(self.msg.fileName)){
  58. url = [NSURL fileURLWithPath:self.msg.fileName];
  59. // _imageBackground.image = [UIImage imageWithContentsOfFile:self.msg.fileName];
  60. }else{
  61. url = [NSURL URLWithString:self.msg.content];
  62. // [_imageBackground sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"发送位置.png"]];
  63. }
  64. if (url) {
  65. [_mapImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"发送位置.png"]];
  66. // [_mapImageView sd_setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  67. // _mapImageView.image = image;
  68. // }];
  69. }else{
  70. // _imageBackground.image = [UIImage imageNamed:@"发送位置.png"];
  71. }
  72. if ([self.msg.objectId length]>0) {
  73. NSString * address = self.msg.objectId;
  74. // NSRange addRange = [address rangeOfString:Localized(@"selectProvinceVC_City")];
  75. // if (addRange.length) {
  76. // NSString * showAddress = [address substringFromIndex:(addRange.location+addRange.length)];
  77. _addressLabel.text = address;
  78. // }
  79. }
  80. if(!self.msg.isMySend)
  81. [self drawIsRead];
  82. }
  83. //未读红点
  84. -(void)drawIsRead{
  85. if (self.msg.isMySend) {
  86. return;
  87. }
  88. if([self.msg.isRead boolValue]){
  89. self.readImage.hidden = YES;
  90. }
  91. else{
  92. if(self.readImage==nil){
  93. self.readImage=[[UIButton alloc]init];
  94. [self.contentView addSubview:self.readImage];
  95. // [self.readImage release];
  96. }
  97. [self.readImage setImage:[UIImage imageNamed:@"new_tips"] forState:UIControlStateNormal];
  98. self.readImage.hidden = NO;
  99. self.readImage.frame = CGRectMake(self.bubbleBg.frame.origin.x+self.bubbleBg.frame.size.width+7, self.bubbleBg.frame.origin.y+13, 8, 8);
  100. self.readImage.center = CGPointMake(self.readImage.center.x, self.bubbleBg.center.y);
  101. }
  102. }
  103. -(void)didTouch:(UIButton*)button{
  104. [self.msg sendAlreadyReadMsg];
  105. if (self.msg.isGroup) {
  106. self.msg.isRead = [NSNumber numberWithInt:1];
  107. [self.msg updateIsRead:nil msgId:self.msg.messageId];
  108. }
  109. if(!self.msg.isMySend){
  110. [self drawIsRead];
  111. }
  112. [g_notify postNotificationName:kCellLocationNotifaction object:self.msg];
  113. }
  114. + (float)getChatCellHeight:(JXMessageObject *)msg {
  115. if ([msg.chatMsgHeight floatValue] > 1) {
  116. return [msg.chatMsgHeight floatValue];
  117. }
  118. float n = 0;
  119. if (msg.isGroup && !msg.isMySend) {
  120. if (msg.isShowTime) {
  121. n = imageItemHeight+20*2 + 40;
  122. }else {
  123. n = imageItemHeight+20*2;
  124. }
  125. n += GROUP_CHAT_INSET;
  126. }else {
  127. if (msg.isShowTime) {
  128. n = imageItemHeight+10*2 + 40;
  129. }else {
  130. n = imageItemHeight+10*2;
  131. }
  132. }
  133. msg.chatMsgHeight = [NSString stringWithFormat:@"%f",n];
  134. if (!msg.isNotUpdateHeight) {
  135. [msg updateChatMsgHeight];
  136. }
  137. return n;
  138. }
  139. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  140. [super setSelected:selected animated:animated];
  141. // Configure the view for the selected state
  142. }
  143. @end