WFCUConversationSettingMemberCell.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // ConversationSettingMemberCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/11/3.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUConversationSettingMemberCell.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "WFCUConfigManager.h"
  12. #import "UIFont+YH.h"
  13. #import "UIColor+YH.h"
  14. #import "WFCUImage.h"
  15. @interface WFCUConversationSettingMemberCell ()
  16. @property(nonatomic, strong) NSObject *model;
  17. @end
  18. @implementation WFCUConversationSettingMemberCell
  19. - (id)initWithFrame:(CGRect)frame {
  20. self = [super initWithFrame:frame];
  21. if (self) {
  22. self.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  23. }
  24. return self;
  25. }
  26. - (void)layoutSubviews {
  27. [super layoutSubviews];
  28. self.headerImageView.frame = CGRectMake(2, 2, self.frame.size.width - 4, self.frame.size.width - 4);
  29. self.nameLabel.frame = CGRectMake(0, self.frame.size.width + 3, self.frame.size.width, 11);
  30. self.domainLabel.frame = CGRectMake(0, self.frame.size.width + 3 + 14, self.frame.size.width, 11);
  31. }
  32. - (UILabel *)nameLabel {
  33. if (!_nameLabel) {
  34. _nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  35. _nameLabel.textColor = [WFCUConfigManager globalManager].textColor;
  36. _nameLabel.textAlignment = NSTextAlignmentCenter;
  37. _nameLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:11];
  38. [[self contentView] addSubview:_nameLabel];
  39. }
  40. return _nameLabel;
  41. }
  42. - (UILabel *)domainLabel {
  43. if (!_domainLabel) {
  44. _domainLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  45. _domainLabel.textColor = [WFCUConfigManager globalManager].textColor;
  46. _domainLabel.textAlignment = NSTextAlignmentCenter;
  47. _domainLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:11];
  48. [[self contentView] addSubview:_domainLabel];
  49. }
  50. return _domainLabel;
  51. }
  52. - (UIImageView *)headerImageView {
  53. if (!_headerImageView) {
  54. _headerImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
  55. _headerImageView.autoresizingMask =
  56. UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  57. _headerImageView.contentMode = UIViewContentModeScaleAspectFill;
  58. _headerImageView.clipsToBounds = YES;
  59. _headerImageView.layer.borderWidth = 1;
  60. _headerImageView.layer.borderColor = [UIColor whiteColor].CGColor;
  61. _headerImageView.layer.cornerRadius = 8;
  62. _headerImageView.layer.masksToBounds = YES;
  63. _headerImageView.backgroundColor = [UIColor clearColor];
  64. _headerImageView.layer.edgeAntialiasingMask =
  65. kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge |
  66. kCALayerTopEdge;
  67. [[self contentView] addSubview:_headerImageView];
  68. }
  69. return _headerImageView;
  70. }
  71. - (void)setModel:(NSObject *)model withType:(WFCCConversationType)type {
  72. self.contentView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  73. self.model = model;
  74. WFCCUserInfo *userInfo;
  75. WFCCGroupMember *groupMember;
  76. WFCCChannelInfo *channelInfo;
  77. NSString *domainId = nil;
  78. if (type == Group_Type) {
  79. groupMember = (WFCCGroupMember *)model;
  80. userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:groupMember.memberId inGroup:groupMember.groupId refresh:NO];
  81. if([WFCCUtilities isExternalTarget:groupMember.memberId]) {
  82. domainId = [WFCCUtilities getExternalDomain:groupMember.memberId];
  83. }
  84. } else if(type == Single_Type) {
  85. userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:(NSString *)model refresh:NO];
  86. if([WFCCUtilities isExternalTarget:(NSString *)model]) {
  87. domainId = [WFCCUtilities getExternalDomain:(NSString *)model];
  88. }
  89. } else if(type == Channel_Type) {
  90. channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:(NSString *)model refresh:NO];
  91. if([WFCCUtilities isExternalTarget:(NSString *)model]) {
  92. domainId = [WFCCUtilities getExternalDomain:(NSString *)model];
  93. }
  94. } else if(type == SecretChat_Type) {
  95. NSString *userId = [[WFCCIMService sharedWFCIMService] getSecretChatInfo:(NSString *)model].userId;
  96. userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
  97. } else {
  98. return;
  99. }
  100. if (type == Channel_Type) {
  101. [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:[channelInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  102. self.nameLabel.text = channelInfo.name;
  103. } else {
  104. [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  105. if (userInfo.friendAlias.length) {
  106. self.nameLabel.text = userInfo.friendAlias;
  107. } else if(userInfo.groupAlias.length) {
  108. self.nameLabel.text = userInfo.groupAlias;
  109. } else if(userInfo.displayName.length) {
  110. self.nameLabel.text = userInfo.displayName;
  111. } else {
  112. self.nameLabel.text = nil;
  113. }
  114. }
  115. self.nameLabel.hidden = NO;
  116. if(domainId) {
  117. self.domainLabel.hidden = NO;
  118. self.domainLabel.attributedText = [WFCCUtilities getExternal:domainId withName:nil withColor:[WFCUConfigManager globalManager].externalNameColor withSize:10];
  119. } else {
  120. self.domainLabel.hidden = YES;
  121. }
  122. }
  123. - (void)resetLayout:(CGFloat)nameLabelHeight
  124. insideMargin:(CGFloat)insideMargin {
  125. }
  126. @end