WFCUConversationSearchTableViewCell.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // ConversationSearchTableViewCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/8/29.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUConversationSearchTableViewCell.h"
  9. #import "WFCUUtilities.h"
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "SDWebImage.h"
  12. @implementation WFCUConversationSearchTableViewCell
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. // Initialization code
  16. }
  17. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  18. [super setSelected:selected animated:animated];
  19. }
  20. - (void)updateUserInfo:(WFCCUserInfo *)userInfo {
  21. [self.potraitView sd_setImageWithURL:[NSURL URLWithString:userInfo.portrait] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  22. if(userInfo.displayName.length > 0) {
  23. self.targetView.text = userInfo.displayName;
  24. } else {
  25. self.targetView.text = [NSString stringWithFormat:@"user<%@>", self.message.fromUser];
  26. }
  27. }
  28. - (void)setMessage:(WFCCMessage *)message {
  29. _message = message;
  30. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:message.fromUser refresh:NO];
  31. if(userInfo.userId.length == 0) {
  32. userInfo = [[WFCCUserInfo alloc] init];
  33. userInfo.userId = message.fromUser;
  34. }
  35. [self updateUserInfo:userInfo];
  36. NSString *strContent = message.content.digest;
  37. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:strContent];
  38. NSRange range = [strContent rangeOfString:self.keyword options:NSCaseInsensitiveSearch];
  39. [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:range];
  40. self.digestView.attributedText = attrStr;
  41. self.potraitView.layer.cornerRadius = 4.f;
  42. self.timeView.hidden = NO;
  43. self.timeView.text = [WFCUUtilities formatTimeLabel:message.serverTime];
  44. [self.contentView setBackgroundColor:[UIColor whiteColor]];
  45. }
  46. - (UIImageView *)potraitView {
  47. if (!_potraitView) {
  48. _potraitView = [[UIImageView alloc] initWithFrame:CGRectMake(19, 19, 30, 30)];
  49. _potraitView.clipsToBounds = YES;
  50. _potraitView.layer.cornerRadius = 2.f;
  51. [self.contentView addSubview:_potraitView];
  52. }
  53. return _potraitView;
  54. }
  55. - (UILabel *)targetView {
  56. if (!_targetView) {
  57. _targetView = [[UILabel alloc] initWithFrame:CGRectMake(16 + 28 + 16, 19, [UIScreen mainScreen].bounds.size.width - 68 - 68, 10)];
  58. _targetView.font = [UIFont systemFontOfSize:10];
  59. _targetView.textColor = [UIColor grayColor];
  60. [self.contentView addSubview:_targetView];
  61. }
  62. return _targetView;
  63. }
  64. - (UILabel *)digestView {
  65. if (!_digestView) {
  66. _digestView = [[UILabel alloc] initWithFrame:CGRectMake(16 + 28 + 16, 34, [UIScreen mainScreen].bounds.size.width - 60 - 16, 14)];
  67. _digestView.font = [UIFont systemFontOfSize:14];
  68. _digestView.lineBreakMode = NSLineBreakByTruncatingTail;
  69. [self.contentView addSubview:_digestView];
  70. }
  71. return _digestView;
  72. }
  73. - (UILabel *)timeView {
  74. if (!_timeView) {
  75. _timeView = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 52 - 8, 18, 52, 12)];
  76. _timeView.font = [UIFont systemFontOfSize:11];
  77. _timeView.textAlignment = NSTextAlignmentRight;
  78. _timeView.textColor = [UIColor grayColor];
  79. [self.contentView addSubview:_timeView];
  80. }
  81. return _timeView;
  82. }
  83. @end