WFCUContactTableViewCell.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // ContactTableViewCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/28.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUContactTableViewCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <SDWebImage/SDWebImage.h>
  11. #import "UIColor+YH.h"
  12. #import "UIFont+YH.h"
  13. #import "WFCUConfigManager.h"
  14. @interface WFCUContactTableViewCell ()
  15. @end
  16. @implementation WFCUContactTableViewCell
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. }
  21. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  22. [super setSelected:selected animated:animated];
  23. // Configure the view for the selected state
  24. }
  25. - (void)layoutSubviews {
  26. [super layoutSubviews];
  27. if (self.isBig) {
  28. _portraitView.frame = CGRectMake(8, (self.frame.size.height - 52) / 2.0, 52, 52);
  29. _nameLabel.frame = CGRectMake(72, (self.frame.size.height - 20) / 2.0, [UIScreen mainScreen].bounds.size.width - 64, 20);
  30. _nameLabel.font = [UIFont systemFontOfSize:20];
  31. } else {
  32. _portraitView.frame = CGRectMake(16, (self.frame.size.height - 40) / 2.0, 40, 40);
  33. _nameLabel.frame = CGRectMake(16 + 40 + 11, (self.frame.size.height - 17) / 2.0, [UIScreen mainScreen].bounds.size.width - (16 + 40 + 11), 17);
  34. _nameLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  35. }
  36. }
  37. - (void)onUserInfoUpdated:(NSNotification *)notification {
  38. WFCCUserInfo *userInfo = notification.userInfo[@"userInfo"];
  39. if ([self.userId isEqualToString:userInfo.userId]) {
  40. [self updateUserInfo:userInfo];
  41. }
  42. }
  43. - (void)setUserId:(NSString *)userId {
  44. _userId = userId;
  45. [[NSNotificationCenter defaultCenter] removeObserver:self];
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUserInfoUpdated:) name:kUserInfoUpdated object:userId];
  47. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
  48. if(userInfo.userId.length == 0) {
  49. userInfo = [[WFCCUserInfo alloc] init];
  50. userInfo.userId = userId;
  51. }
  52. [self updateUserInfo:userInfo];
  53. }
  54. - (void)updateUserInfo:(WFCCUserInfo *)userInfo {
  55. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  56. if (userInfo.friendAlias.length) {
  57. self.nameLabel.text = userInfo.friendAlias;
  58. } else if (self.groupAlias.length) {
  59. self.nameLabel.text = self.groupAlias;
  60. } else if(userInfo.displayName.length > 0) {
  61. self.nameLabel.text = userInfo.displayName;
  62. } else {
  63. self.nameLabel.text = [NSString stringWithFormat:@"user<%@>", userInfo.userId];
  64. }
  65. }
  66. - (UIImageView *)portraitView {
  67. if (!_portraitView) {
  68. _portraitView = [UIImageView new];
  69. _portraitView.layer.masksToBounds = YES;
  70. _portraitView.layer.cornerRadius = 3.f;
  71. [self.contentView addSubview:_portraitView];
  72. }
  73. return _portraitView;
  74. }
  75. - (UILabel *)nameLabel {
  76. if (!_nameLabel) {
  77. _nameLabel = [UILabel new];
  78. _nameLabel.textColor = [WFCUConfigManager globalManager].textColor;
  79. [self.contentView addSubview:_nameLabel];
  80. }
  81. return _nameLabel;
  82. }
  83. - (void)dealloc {
  84. [[NSNotificationCenter defaultCenter] removeObserver:self];
  85. }
  86. @end