2
0

WFCUSearchGroupTableViewCell.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // WFCUSearchGroupTableViewCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/13.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUSearchGroupTableViewCell.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import "UIFont+YH.h"
  11. #import "UIColor+YH.h"
  12. #import "WFCUImage.h"
  13. @interface WFCUSearchGroupTableViewCell()
  14. @property (strong, nonatomic) UIImageView *portrait;
  15. @property (strong, nonatomic) UILabel *name;
  16. @property (strong, nonatomic) UILabel *haveMember;
  17. @end
  18. @implementation WFCUSearchGroupTableViewCell
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. // Initialization code
  22. }
  23. - (void)layoutSubviews {
  24. [super layoutSubviews];
  25. CGFloat postionY = (self.frame.size.height - 40) / 2.0;
  26. self.portrait.frame = CGRectMake(16, postionY, 40, 40);
  27. self.name.frame = CGRectMake(10 + 40 + 20, postionY, [UIScreen mainScreen].bounds.size.width - (10 + 40 + 20), 20);
  28. postionY += 15 + 8;
  29. self.haveMember.frame = CGRectMake(10 + 40 + 20, postionY, [UIScreen mainScreen].bounds.size.width - (10 + 40 + 20), 19);
  30. }
  31. - (UIImageView *)portrait {
  32. if (!_portrait) {
  33. _portrait = [UIImageView new];
  34. _portrait.layer.cornerRadius = 4;
  35. _portrait.layer.masksToBounds = YES;
  36. [self.contentView addSubview:_portrait];
  37. }
  38. return _portrait;
  39. }
  40. - (UILabel *)name {
  41. if (!_name) {
  42. _name = [UILabel new];
  43. [_name setFont:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:15]];
  44. _name.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  45. [self.contentView addSubview:_name];
  46. }
  47. return _name;
  48. }
  49. - (UILabel *)haveMember {
  50. if (!_haveMember) {
  51. _haveMember = [UILabel new];
  52. [_haveMember setFont:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12]];
  53. _haveMember.textColor = [UIColor colorWithHexString:@"0xb3b3b3"];
  54. [self.contentView addSubview:_haveMember];
  55. }
  56. return _haveMember;
  57. }
  58. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  59. [super setSelected:selected animated:animated];
  60. // Configure the view for the selected state
  61. }
  62. - (void)setGroupSearchInfo:(WFCCGroupSearchInfo *)groupSearchInfo {
  63. _groupSearchInfo = groupSearchInfo;
  64. WFCCGroupInfo *groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:groupSearchInfo.groupInfo.target refresh:NO];
  65. self.haveMember.attributedText = nil;
  66. self.name.text = nil;
  67. if ((groupSearchInfo.marchType & GroupSearchMarchTypeMask_Member_Name) || (groupSearchInfo.marchType & GroupSearchMarchTypeMask_Member_Alias)) {
  68. NSMutableAttributedString *string;
  69. for (NSString *memberId in groupSearchInfo.marchedMemberNames) {
  70. if (groupSearchInfo.marchType & GroupSearchMarchTypeMask_Member_Alias) {
  71. WFCCGroupMember *member = [[WFCCIMService sharedWFCIMService] getGroupMember:groupSearchInfo.groupInfo.target memberId:memberId];
  72. if (member && [[member.alias lowercaseString] rangeOfString:[groupSearchInfo.keyword lowercaseString]].location != NSNotFound) {
  73. string = [[NSMutableAttributedString alloc] initWithString:member.alias];
  74. [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, string.length)];
  75. [string addAttribute:NSUnderlineStyleAttributeName value:@YES range:NSMakeRange(0, string.length)];
  76. break;
  77. }
  78. }
  79. if(string == nil && (groupSearchInfo.marchType & GroupSearchMarchTypeMask_Member_Name)) {
  80. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:memberId refresh:NO];
  81. if (userInfo && [[userInfo.displayName lowercaseString] rangeOfString:[groupSearchInfo.keyword lowercaseString]].location != NSNotFound) {
  82. string = [[NSMutableAttributedString alloc] initWithString:userInfo.displayName];
  83. [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, string.length)];
  84. [string addAttribute:NSUnderlineStyleAttributeName value:@YES range:NSMakeRange(0, string.length)];
  85. break;
  86. }
  87. }
  88. }
  89. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:WFCString(@"GroupMemberNameMatch")];
  90. if(string.length) {
  91. [attrStr appendAttributedString:string];
  92. if (groupSearchInfo.marchedMemberNames.count > 1) {
  93. [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:WFCString(@"Etc")]];
  94. }
  95. }
  96. self.haveMember.attributedText = attrStr;
  97. }
  98. if ((groupSearchInfo.marchType & GroupSearchMarchTypeMask_Group_Name) || (groupSearchInfo.marchType & GroupSearchMarchTypeMask_Group_Remark)) {
  99. NSString *groupName = groupSearchInfo.groupInfo.name;
  100. if(groupSearchInfo.groupInfo.remark.length) {
  101. if([groupSearchInfo.groupInfo.remark rangeOfString:groupSearchInfo.keyword].location != NSNotFound) {
  102. groupName = groupSearchInfo.groupInfo.remark;
  103. } else {
  104. groupName = [NSString stringWithFormat:@"%@(%@)", groupSearchInfo.groupInfo.remark, groupSearchInfo.groupInfo.name];
  105. }
  106. }
  107. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:groupName];
  108. NSRange range = [[groupName lowercaseString] rangeOfString:[groupSearchInfo.keyword lowercaseString]];
  109. if(range.location != NSNotFound) {
  110. [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:range];
  111. [string addAttribute:NSUnderlineStyleAttributeName value:@YES range:range];
  112. self.name.attributedText = string;
  113. }
  114. } else {
  115. if (groupInfo.displayName.length == 0) {
  116. self.name.text = WFCString(@"GroupChat");
  117. } else {
  118. self.name.text = [NSString stringWithFormat:@"%@(%d)", groupInfo.displayName, (int)groupInfo.memberCount];
  119. }
  120. }
  121. if (groupInfo.portrait.length) {
  122. [self.portrait sd_setImageWithURL:[NSURL URLWithString:[groupInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  123. } else {
  124. NSString *path = [WFCCUtilities getGroupGridPortrait:groupInfo.target width:80 generateIfNotExist:YES defaultUserPortrait:^UIImage *(NSString *userId) {
  125. return [WFCUImage imageNamed:@"PersonalChat"];
  126. }];
  127. if (path) {
  128. [self.portrait sd_setImageWithURL:[NSURL fileURLWithPath:path] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  129. }
  130. }
  131. }
  132. @end