WFCUConversationSearchTableViewCell.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/SDWebImage.h>
  12. #import "WFCUConfigManager.h"
  13. #import "WFCUImage.h"
  14. @implementation WFCUConversationSearchTableViewCell
  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. }
  22. - (void)updateUserInfo:(WFCCUserInfo *)userInfo {
  23. [self.potraitView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [WFCUImage imageNamed:@"PersonalChat"]];
  24. if (userInfo.friendAlias.length) {
  25. self.targetView.text = userInfo.friendAlias;
  26. } else if(userInfo.displayName.length > 0) {
  27. self.targetView.text = userInfo.displayName;
  28. } else {
  29. self.targetView.text = [NSString stringWithFormat:@"user<%@>", self.message.fromUser];
  30. }
  31. }
  32. - (void)setMessage:(WFCCMessage *)message {
  33. _message = message;
  34. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:message.fromUser refresh:NO];
  35. if(userInfo.userId.length == 0) {
  36. userInfo = [[WFCCUserInfo alloc] init];
  37. userInfo.userId = message.fromUser;
  38. }
  39. [self updateUserInfo:userInfo];
  40. NSString *strContent = message.digest;
  41. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:strContent];
  42. NSRange range = [strContent rangeOfString:self.keyword options:NSCaseInsensitiveSearch];
  43. [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:range];
  44. self.digestView.attributedText = attrStr;
  45. self.potraitView.layer.cornerRadius = 4.f;
  46. self.timeView.hidden = NO;
  47. self.timeView.text = [WFCUUtilities formatTimeLabel:message.serverTime];
  48. self.contentView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  49. }
  50. - (UIImageView *)potraitView {
  51. if (!_potraitView) {
  52. _potraitView = [[UIImageView alloc] initWithFrame:CGRectMake(19, 19, 30, 30)];
  53. _potraitView.clipsToBounds = YES;
  54. _potraitView.layer.cornerRadius = 2.f;
  55. [self.contentView addSubview:_potraitView];
  56. }
  57. return _potraitView;
  58. }
  59. - (UILabel *)targetView {
  60. if (!_targetView) {
  61. _targetView = [[UILabel alloc] initWithFrame:CGRectMake(16 + 28 + 16, 19, [UIScreen mainScreen].bounds.size.width - 68 - 68, 10)];
  62. _targetView.font = [UIFont systemFontOfSize:10];
  63. _targetView.textColor = [UIColor grayColor];
  64. [self.contentView addSubview:_targetView];
  65. }
  66. return _targetView;
  67. }
  68. - (UILabel *)digestView {
  69. if (!_digestView) {
  70. _digestView = [[UILabel alloc] initWithFrame:CGRectMake(16 + 28 + 16, 34, [UIScreen mainScreen].bounds.size.width - 60 - 16, 14)];
  71. _digestView.font = [UIFont systemFontOfSize:14];
  72. _digestView.lineBreakMode = NSLineBreakByTruncatingTail;
  73. [self.contentView addSubview:_digestView];
  74. }
  75. return _digestView;
  76. }
  77. - (UILabel *)timeView {
  78. if (!_timeView) {
  79. _timeView = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 52 - 8, 18, 52, 12)];
  80. _timeView.font = [UIFont systemFontOfSize:11];
  81. _timeView.textAlignment = NSTextAlignmentRight;
  82. _timeView.textColor = [UIColor grayColor];
  83. [self.contentView addSubview:_timeView];
  84. }
  85. return _timeView;
  86. }
  87. @end