ChatMsgListCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 80;
  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)setCellSearchModel:(ChatSearchModel *)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.cell3UserImgView.image = [UIImage cutImageWithImage:image];
  159. }];
  160. self.cell3TitleLabel.text = model.Name;
  161. NSString * infoText = [self getUserInfoInDocument:[NSString stringWithFormat:@"%ld",(long)model.ImId]];
  162. if (infoText.length > 0) {
  163. self.cell3IntroLabel.hidden = NO;
  164. self.cell3IntroLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"[草稿]%@",infoText]];
  165. self.cell3IntroLabel.attributedText = [self.cell3IntroLabel subhighlightString:@"[草稿]" color:[UIColor redColor]];
  166. }else{
  167. self.cell3IntroLabel.hidden = YES;
  168. }
  169. self.cell3RedBgView.hidden = YES;
  170. self.IsTopView.hidden = YES;
  171. self.cell3TimeLabel.text = [NSDate getTimeStringAutoShort2:model.LastModifiedDate];
  172. }
  173. - (void)setCell5DataWithModel:(ChatMsgListImModel *)model
  174. {
  175. WS(weakSelf);
  176. [SDWebImageManager.sharedManager loadImageWithURL:[NSURL URLWithString:model.AvatarUrl] options:SDWebImageAvoidAutoSetImage progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
  177. } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
  178. weakSelf.cell5UserImgView.image = [UIImage cutImageWithImage:image];
  179. }];
  180. self.cell5TitleLabel.text = model.Name;
  181. NSString * infoText = [self getUserInfoInDocument:[NSString stringWithFormat:@"%ld",(long)model.ImId]];
  182. if (infoText.length > 0) {
  183. self.cell5IntroLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"[草稿]%@",infoText]];
  184. self.cell5IntroLabel.attributedText = [self.cell3IntroLabel subhighlightString:@"[草稿]" color:[UIColor redColor]];
  185. }else{
  186. self.cell5IntroLabel.attributedText = model.ChatText;
  187. }
  188. self.cell5RedBgView.hidden = YES;
  189. self.cell5TimeLabel.text = @"";
  190. self.IsTopView.hidden = !model.IsTop;
  191. self.cell5SelectBtn.selected = model.isSelected;
  192. }
  193. - (NSString *)isNullWithString:(id)value
  194. {
  195. if ([value isKindOfClass:[NSNull class]]) {
  196. return @"";
  197. }else{
  198. if ([value isKindOfClass:[NSString class]]) {
  199. return value;
  200. }else{
  201. return [value stringValue];
  202. }
  203. }
  204. }
  205. - (void)layoutSubviews
  206. {
  207. for (UIView *supView in self.subviews){
  208. if ([supView isKindOfClass:NSClassFromString(@"UITableViewCellReorderControl")]){
  209. for (UIView *view in supView.subviews)
  210. {
  211. if ([view isKindOfClass: [UIImageView class]])
  212. {
  213. UIImageView * imagV = (UIImageView *)view;
  214. [imagV setFrame:CGRectMake(0, 0, 22, 18)];
  215. imagV.center = supView.center;
  216. imagV.contentMode = UIViewContentModeCenter;
  217. imagV.image = [UIImage imageNamed: @"list_sort"];
  218. UIView * label = [UIView new];
  219. label.backgroundColor = UIColorHex(0xEEEEEE);
  220. [supView addSubview:label];
  221. [label setFrame:CGRectMake(0, supView.frame.size.height - 0.5, supView.frame.size.width, 0.5)];
  222. }else{
  223. [view removeFromSuperview];
  224. }
  225. }
  226. }
  227. if ([supView isKindOfClass:NSClassFromString(@"_UITableViewCellSeparatorView")]){
  228. }
  229. }
  230. [super layoutSubviews];
  231. }
  232. - (NSString *)getUserInfoInDocument:(NSString *)ImId{
  233. self.chatDistoryArray = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")];
  234. for (NSMutableDictionary * dict in self.chatDistoryArray) {
  235. if ([[dict objectForKey:@"ImId"] isEqualToString:ImId]) {
  236. NSString * text = [dict objectForKey:@"text"];
  237. return text;
  238. }
  239. }
  240. return @"";
  241. }
  242. @end