WFCUGroupTableViewCell.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // GroupTableViewCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/13.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUGroupTableViewCell.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import "UIFont+YH.h"
  11. #import "UIColor+YH.h"
  12. #import "WFCUImage.h"
  13. @interface WFCUGroupTableViewCell()
  14. @property (strong, nonatomic) UIImageView *portrait;
  15. @property (strong, nonatomic) UILabel *name;
  16. @end
  17. @implementation WFCUGroupTableViewCell
  18. - (void)awakeFromNib {
  19. [super awakeFromNib];
  20. // Initialization code
  21. }
  22. - (void)layoutSubviews {
  23. [super layoutSubviews];
  24. _portrait.frame = CGRectMake(18, (self.frame.size.height - 40) / 2.0, 40, 40);
  25. _name.frame = CGRectMake(18 + 40 + 9, (self.frame.size.height - 17) / 2.0, [UIScreen mainScreen].bounds.size.width - (18 + 40 + 9), 17);
  26. }
  27. - (UIImageView *)portrait {
  28. if (!_portrait) {
  29. _portrait = [UIImageView new];
  30. _portrait.layer.cornerRadius = 4.0f;
  31. _portrait.layer.masksToBounds = YES;
  32. [self.contentView addSubview:_portrait];
  33. }
  34. return _portrait;
  35. }
  36. - (UILabel *)name {
  37. if (!_name) {
  38. _name = [UILabel new];
  39. _name.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  40. _name.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:17];
  41. [self.contentView addSubview:_name];
  42. }
  43. return _name;
  44. }
  45. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  46. [super setSelected:selected animated:animated];
  47. // Configure the view for the selected state
  48. }
  49. - (void)setGroupInfo:(WFCCGroupInfo *)groupInfo {
  50. _groupInfo = groupInfo;
  51. if (groupInfo.displayName.length == 0) {
  52. self.name.text = WFCString(@"GroupChat");
  53. } else {
  54. self.name.text = [NSString stringWithFormat:@"%@(%d)", groupInfo.displayName, (int)groupInfo.memberCount];
  55. }
  56. if (groupInfo.portrait.length) {
  57. [self.portrait sd_setImageWithURL:[NSURL URLWithString:[groupInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  58. } else {
  59. __weak typeof(self)ws = self;
  60. NSString *groupId = groupInfo.target;
  61. [[NSNotificationCenter defaultCenter] addObserverForName:@"GroupPortraitChanged" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  62. NSString *path = [note.userInfo objectForKey:@"path"];
  63. if ([ws.groupInfo.target isEqualToString:groupId] && [groupId isEqualToString:note.object]) {
  64. [ws.portrait sd_setImageWithURL:[NSURL fileURLWithPath:path] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  65. }
  66. }];
  67. NSString *path = [WFCCUtilities getGroupGridPortrait:groupInfo.target width:80 generateIfNotExist:YES defaultUserPortrait:^UIImage *(NSString *userId) {
  68. return [WFCUImage imageNamed:@"PersonalChat"];
  69. }];
  70. if (path) {
  71. [self.portrait sd_setImageWithURL:[NSURL fileURLWithPath:path] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  72. }
  73. }
  74. }
  75. @end