JXFileCell.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // JXFileCell.m
  3. // shiku_im
  4. //
  5. // Created by Apple on 16/10/10.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXFileCell.h"
  9. #import "JXMyFile.h"
  10. @interface JXFileCell ()
  11. @property (nonatomic, strong) UIImageView *fileImage;
  12. @property (nonatomic, strong) UIView *lineView;
  13. @property (nonatomic, strong) UILabel *title;
  14. @property (nonatomic, strong) UIProgressView *progressView;
  15. @end
  16. @implementation JXFileCell
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. }
  21. - (void)creatUI{
  22. _imageBackground =[[UIImageView alloc]initWithFrame:CGRectZero];
  23. [_imageBackground setBackgroundColor:[UIColor clearColor]];
  24. _imageBackground.layer.cornerRadius = 6;
  25. _imageBackground.layer.masksToBounds = YES;
  26. [self.bubbleBg addSubview:_imageBackground];
  27. // [_imageBackground release];
  28. _fileImage = [[UIImageView alloc]init];
  29. _fileImage.frame = CGRectMake(15,15, 50, 50);
  30. _fileImage.userInteractionEnabled = NO;
  31. _fileImage.image = [UIImage imageNamed:@"im_file"];
  32. [_imageBackground addSubview:_fileImage];
  33. _fileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_fileImage.frame) + 10,_fileImage.frame.origin.y, kChatCellMaxWidth - CGRectGetMaxX(_fileImage.frame) - 20, 50)];
  34. _fileNameLabel.numberOfLines = 0;
  35. _fileNameLabel.lineBreakMode = NSLineBreakByCharWrapping;
  36. _fileNameLabel.backgroundColor = [UIColor clearColor];
  37. _fileNameLabel.font = g_factory.font15;
  38. [_imageBackground addSubview:_fileNameLabel];
  39. _lineView = [[UIView alloc] init];
  40. _lineView.backgroundColor = THE_LINE_COLOR;
  41. [_imageBackground addSubview:_lineView];
  42. _progressView = [[UIProgressView alloc] init];
  43. _progressView.progressTintColor = [UIColor greenColor];
  44. _progressView.progressViewStyle = UIProgressViewStyleDefault;
  45. _progressView.hidden = YES;
  46. [_imageBackground addSubview:_progressView];
  47. _title = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 30)];
  48. _title.text = Localized(@"JX_File");
  49. _title.font = SYSFONT(13);
  50. _title.textColor = [UIColor grayColor];
  51. [_imageBackground addSubview:_title];
  52. // [_fileNameLabel release];
  53. }
  54. -(void)setCellData{
  55. [super setCellData];
  56. int n = imageItemHeight;
  57. if(self.msg.isMySend)
  58. {
  59. self.bubbleBg.frame=CGRectMake(CGRectGetMinX(self.headImage.frame)-kChatCellMaxWidth-CHAT_WIDTH_ICON, INSETS, kChatCellMaxWidth, n+INSETS -4);
  60. _imageBackground.frame = self.bubbleBg.bounds;
  61. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_blue"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  62. }
  63. else
  64. {
  65. self.bubbleBg.frame=CGRectMake(CGRectGetMaxX(self.headImage.frame) + CHAT_WIDTH_ICON, INSETS2(self.msg.isGroup), kChatCellMaxWidth, n+INSETS -4);
  66. _imageBackground.frame = self.bubbleBg.bounds;
  67. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_white"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  68. }
  69. _lineView.frame = CGRectMake(0, _imageBackground.frame.size.height - 30, _imageBackground.frame.size.width, LINE_WH);
  70. _progressView.frame = CGRectMake(2, _imageBackground.frame.size.height - 30, _imageBackground.frame.size.width-2, LINE_WH);
  71. _title.frame = CGRectMake(15, _imageBackground.frame.size.height - 30, 200, 30);
  72. // _fileNameLabel.frame = CGRectMake(_fileNameLabel.frame.origin.x, _fileNameLabel.frame.origin.y, _fileNameLabel.frame.size.width, _lineView.frame.origin.y - _fileNameLabel.frame.origin.y - 10);
  73. if (self.msg.isShowTime) {
  74. CGRect frame = self.bubbleBg.frame;
  75. frame.origin.y = self.bubbleBg.frame.origin.y + 40;
  76. self.bubbleBg.frame = frame;
  77. }
  78. [self setMaskLayer:_imageBackground];
  79. if (self.msg.fileName.length > 0) {
  80. _fileNameLabel.text = [NSString stringWithFormat:@"%@",[self.msg.fileName lastPathComponent]];
  81. }
  82. // if (JX_SCREEN_WIDTH >320) {
  83. // if (self.msg.content.length > 0) {
  84. // _fileNameLabel.text = [NSString stringWithFormat:@" %@:%@...",Localized(@"JX_File"),[[self.msg.content lastPathComponent] substringToIndex:15]];
  85. // }
  86. // }else{
  87. // if (self.msg.content.length > 0) {
  88. // _fileNameLabel.text = [NSString stringWithFormat:@" %@:%@...",Localized(@"JX_File"),[[self.msg.content lastPathComponent] substringToIndex:9]];
  89. // }
  90. // }
  91. if(!self.msg.isMySend)
  92. [self drawIsRead];
  93. }
  94. //未读红点
  95. -(void)drawIsRead{
  96. if (self.msg.isMySend) {
  97. return;
  98. }
  99. if([self.msg.isRead boolValue]){
  100. self.readImage.hidden = YES;
  101. }
  102. else{
  103. if(self.readImage==nil){
  104. self.readImage=[[UIButton alloc]init];
  105. [self.contentView addSubview:self.readImage];
  106. // [self.readImage release];
  107. }
  108. [self.readImage setImage:[UIImage imageNamed:@"new_tips"] forState:UIControlStateNormal];
  109. self.readImage.hidden = NO;
  110. self.readImage.frame = CGRectMake(self.bubbleBg.frame.origin.x+self.bubbleBg.frame.size.width+7, self.bubbleBg.frame.origin.y+13, 8, 8);
  111. self.readImage.center = CGPointMake(self.readImage.center.x, self.bubbleBg.center.y);
  112. }
  113. }
  114. - (void)updateFileLoadProgress {
  115. dispatch_async(dispatch_get_main_queue(), ^{
  116. if ([self.fileDict isEqualToString:self.msg.messageId]) {
  117. _progressView.hidden = NO;
  118. // UI更新代码
  119. if (self.loadProgress >= 1) {
  120. [_progressView setProgress:0.99 animated:YES];
  121. }
  122. else {
  123. [_progressView setProgress:self.loadProgress animated:YES];
  124. }
  125. // _progressView.hidden = self.loadProgress >= 1;
  126. }
  127. });
  128. }
  129. - (void)sendMessageToUser {
  130. [_progressView setProgress:1 animated:YES];
  131. _progressView.hidden = YES;
  132. }
  133. + (float)getChatCellHeight:(JXMessageObject *)msg {
  134. if ([msg.chatMsgHeight floatValue] > 1) {
  135. return [msg.chatMsgHeight floatValue];
  136. }
  137. float n = 0;
  138. if (msg.isGroup && !msg.isMySend) {
  139. if (msg.isShowTime) {
  140. n = imageItemHeight+20*2 + 40;
  141. }else {
  142. n = imageItemHeight+20*2;
  143. }
  144. n += GROUP_CHAT_INSET;
  145. }else {
  146. if (msg.isShowTime) {
  147. n = imageItemHeight+10*2 + 40;
  148. }else {
  149. n = imageItemHeight+10*2;
  150. }
  151. }
  152. msg.chatMsgHeight = [NSString stringWithFormat:@"%f",n];
  153. if (!msg.isNotUpdateHeight) {
  154. [msg updateChatMsgHeight];
  155. }
  156. return n;
  157. }
  158. -(void)didTouch:(UIButton*)button{
  159. // JXMyFile* vc = [[JXMyFile alloc]init];
  160. // [g_window addSubview:vc.view];
  161. [self.msg sendAlreadyReadMsg];
  162. if (self.msg.isGroup) {
  163. self.msg.isRead = [NSNumber numberWithInt:1];
  164. [self.msg updateIsRead:nil msgId:self.msg.messageId];
  165. }
  166. if(!self.msg.isMySend){
  167. self.msg.isRead = [NSNumber numberWithInt:1];
  168. [self drawIsRead];
  169. }
  170. [g_notify postNotificationName:kCellSystemFileNotifaction object:self.msg];
  171. }
  172. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  173. [super setSelected:selected animated:animated];
  174. // Configure the view for the selected state
  175. }
  176. @end