ChatMsgListCell.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //
  2. // ChatMsgListCell.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/2.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "ChatMsgListCell.h"
  9. #import "NSDate+Extension.h"
  10. #import "UIImage+GH.h"
  11. @interface ChatMsgListCell()
  12. @property (copy,nonatomic) NSMutableArray *chatDistoryArray;
  13. @end
  14. @implementation ChatMsgListCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. // Initialization code
  18. }
  19. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  20. [super setSelected:selected animated:animated];
  21. // Configure the view for the selected state
  22. }
  23. + (CGFloat)configCell0Height{
  24. return 50;
  25. }
  26. + (CGFloat)configCell1Height{
  27. return 90;
  28. }
  29. + (CGFloat)configCell2Height{
  30. return 69;
  31. }
  32. + (CGFloat)configCell3Height{
  33. return 76;
  34. }
  35. + (CGFloat)configCell4Height{
  36. return 40;
  37. }
  38. + (CGFloat)configCell5Height{
  39. return 76;
  40. }
  41. + (ChatMsgListCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  42. static NSString *cellIdentifer = @"ChatMsgListCell0";
  43. ChatMsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  44. if (cell == nil) {
  45. cell = [[[NSBundle mainBundle] loadNibNamed:@"ChatMsgListCell" owner:nil options:nil] objectAtIndex:0];
  46. }
  47. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  48. cell.cell0SearchBgView.layer.masksToBounds = YES;
  49. cell.cell0SearchBgView.layer.cornerRadius = 36/2.0;
  50. cell.cell0SearchBgView.layer.borderWidth = 0.5;
  51. cell.cell0SearchBgView.layer.borderColor = RGB(204, 204, 204).CGColor;
  52. cell.cell0MengCengView.hidden = YES;
  53. return cell;
  54. }
  55. + (ChatMsgListCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  56. static NSString *cellIdentifer = @"ChatMsgListCell1";
  57. ChatMsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  58. if (cell == nil) {
  59. cell = [[[NSBundle mainBundle] loadNibNamed:@"ChatMsgListCell" owner:nil options:nil] objectAtIndex:1];
  60. }
  61. cell.rightImg.hidden = NO;
  62. cell.cell1RightIntoBtn.hidden = NO;
  63. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  64. return cell;
  65. }
  66. + (ChatMsgListCell *)configCell2:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  67. static NSString *cellIdentifer = @"ChatMsgListCell2";
  68. ChatMsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  69. if (cell == nil) {
  70. cell = [[[NSBundle mainBundle] loadNibNamed:@"ChatMsgListCell" owner:nil options:nil] objectAtIndex:2];
  71. }
  72. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  73. cell.cell2RightArrowImgView.hidden = NO;
  74. cell.enterBtn.hidden = YES;
  75. return cell;
  76. }
  77. + (ChatMsgListCell *)configCell3:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  78. static NSString *cellIdentifer = @"ChatMsgListCell3";
  79. ChatMsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  80. if (cell == nil) {
  81. cell = [[[NSBundle mainBundle] loadNibNamed:@"ChatMsgListCell" owner:nil options:nil] objectAtIndex:3];
  82. }
  83. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  84. cell.cell3RedBgView.layer.masksToBounds = YES;
  85. cell.cell3RedBgView.layer.cornerRadius = 16/2.0;
  86. cell.cell3MengCengView.hidden = YES;
  87. return cell;
  88. }
  89. + (ChatMsgListCell *)configCell4:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  90. static NSString *cellIdentifer = @"ChatMsgListCell4";
  91. ChatMsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  92. if (cell == nil) {
  93. cell = [[[NSBundle mainBundle] loadNibNamed:@"ChatMsgListCell" owner:nil options:nil] objectAtIndex:4];
  94. }
  95. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  96. return cell;
  97. }
  98. + (ChatMsgListCell *)configCell5:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  99. static NSString *cellIdentifer = @"ChatMsgListCell5";
  100. ChatMsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  101. if (cell == nil) {
  102. cell = [[[NSBundle mainBundle] loadNibNamed:@"ChatMsgListCell" owner:nil options:nil] objectAtIndex:5];
  103. }
  104. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  105. cell.cell5RedBgView.layer.masksToBounds = YES;
  106. cell.cell5RedBgView.layer.cornerRadius = 16/2.0;
  107. return cell;
  108. }
  109. + (ChatMsgListCell *)configCell6:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  110. static NSString *cellIdentifer = @"ChatMsgListCell6";
  111. ChatMsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  112. if (cell == nil) {
  113. cell = [[[NSBundle mainBundle] loadNibNamed:@"ChatMsgListCell" owner:nil options:nil] objectAtIndex:6];
  114. }
  115. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  116. cell.cell2RightArrowImgView.hidden = YES;
  117. return cell;
  118. }
  119. - (void)setCell2DataWithModel:(NoticeModel *)model
  120. {
  121. self.cell2TitleLabel.text = model.FolderName;
  122. self.cell2TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.UReadTopicCount];
  123. }
  124. - (void)setCell2MsgWithModel:(ChatMsgWorkModel *)model
  125. {
  126. self.cell2TitleLabel.text = model.Name;
  127. self.cell2TimeLabel.text = [NSDate getTimeStringAutoShort2:[self isNullWithString:model.LastModifiedDate]];
  128. }
  129. - (void)setCell3DataWithModel:(ChatMsgListImModel *)model
  130. {
  131. WS(weakSelf);
  132. [SDWebImageManager.sharedManager loadImageWithURL:[NSURL URLWithString:model.AvatarUrl] options:SDWebImageAvoidAutoSetImage progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
  133. } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
  134. weakSelf.cell3UserImgView.image = [UIImage cutImageWithImage:image];
  135. }];
  136. self.cell3TitleLabel.text = model.Name;
  137. NSString * infoText = [self getUserInfoInDocument:[NSString stringWithFormat:@"%ld",(long)model.ImId]];
  138. if (infoText.length > 0) {
  139. self.cell3IntroLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"[草稿]%@",infoText]];
  140. self.cell3IntroLabel.attributedText = [self.cell3IntroLabel subhighlightString:@"[草稿]" color:[UIColor redColor]];
  141. }else{
  142. self.cell3IntroLabel.attributedText = model.ChatText;
  143. }
  144. if (model.redNum > 0 && !model.IsDisturb) {
  145. self.cell3RedBgView.hidden = NO;
  146. self.cell3RedNumLabel.text = [NSString stringWithFormat:@"%ld",(long)model.redNum];
  147. }else{
  148. self.cell3RedBgView.hidden = YES;
  149. }
  150. self.IsTopView.hidden = !model.IsTop;
  151. self.cell3TimeLabel.text = [NSDate getTimeStringAutoShort2:model.LastModifiedDate];
  152. }
  153. - (void)setCell5DataWithModel:(ChatMsgListImModel *)model
  154. {
  155. WS(weakSelf);
  156. [SDWebImageManager.sharedManager loadImageWithURL:[NSURL URLWithString:model.AvatarUrl] options:SDWebImageAvoidAutoSetImage progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
  157. } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
  158. weakSelf.cell5UserImgView.image = [UIImage cutImageWithImage:image];
  159. }];
  160. self.cell5TitleLabel.text = model.Name;
  161. NSString * infoText = [self getUserInfoInDocument:[NSString stringWithFormat:@"%ld",(long)model.ImId]];
  162. if (infoText.length > 0) {
  163. self.cell5IntroLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"[草稿]%@",infoText]];
  164. self.cell5IntroLabel.attributedText = [self.cell3IntroLabel subhighlightString:@"[草稿]" color:[UIColor redColor]];
  165. }else{
  166. self.cell5IntroLabel.attributedText = model.ChatText;
  167. }
  168. self.cell5RedBgView.hidden = YES;
  169. self.cell5TimeLabel.text = @"";
  170. self.IsTopView.hidden = !model.IsTop;
  171. self.cell5SelectBtn.selected = model.isSelected;
  172. }
  173. - (NSString *)isNullWithString:(id)value
  174. {
  175. if ([value isKindOfClass:[NSNull class]]) {
  176. return @"";
  177. }else{
  178. if ([value isKindOfClass:[NSString class]]) {
  179. return value;
  180. }else{
  181. return [value stringValue];
  182. }
  183. }
  184. }
  185. - (void)layoutSubviews
  186. {
  187. for (UIView *supView in self.subviews){
  188. if ([supView isKindOfClass:NSClassFromString(@"UITableViewCellReorderControl")]){
  189. for (UIView *view in supView.subviews)
  190. {
  191. if ([view isKindOfClass: [UIImageView class]])
  192. {
  193. UIImageView * imagV = (UIImageView *)view;
  194. [imagV setFrame:CGRectMake(0, 0, 22, 18)];
  195. imagV.center = supView.center;
  196. imagV.contentMode = UIViewContentModeCenter;
  197. imagV.image = [UIImage imageNamed: @"list_sort"];
  198. UILabel * label = [UILabel new];
  199. label.backgroundColor = UIColorHex(#EAEAEA);
  200. [supView addSubview:label];
  201. [label setFrame:CGRectMake(0, supView.frame.size.height - 0.5, supView.frame.size.width, 0.5)];
  202. }else{
  203. [view removeFromSuperview];
  204. }
  205. }
  206. }
  207. if ([supView isKindOfClass:NSClassFromString(@"_UITableViewCellSeparatorView")]){
  208. }
  209. }
  210. [super layoutSubviews];
  211. }
  212. - (NSString *)getUserInfoInDocument:(NSString *)ImId{
  213. self.chatDistoryArray = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")];
  214. for (NSMutableDictionary * dict in self.chatDistoryArray) {
  215. if ([[dict objectForKey:@"ImId"] isEqualToString:ImId]) {
  216. NSString * text = [dict objectForKey:@"text"];
  217. return text;
  218. }
  219. }
  220. return @"";
  221. }
  222. @end