NIMSessionListCell.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // NTESSessionListCell.m
  3. // NIMDemo
  4. //
  5. // Created by chris on 15/2/10.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMSessionListCell.h"
  9. #import "NIMAvatarImageView.h"
  10. #import "UIView+NIM.h"
  11. #import "NIMKitUtil.h"
  12. #import "NIMBadgeView.h"
  13. #import "NTESSessionUtil.h"
  14. @implementation NIMSessionListCell
  15. #define AvatarWidth 52 //消息列表页面头像的大小
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  17. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  18. if (self) {
  19. _avatarImageView = [[NIMAvatarImageView alloc] initWithFrame:CGRectMake(0, 0,52, 52)];
  20. _avatarImageView.cornerRadius = 26;
  21. _avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
  22. [self.contentView addSubview:_avatarImageView];
  23. _nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  24. _nameLabel.textColor = LZ273145Color;
  25. _nameLabel.font = [UIFont systemFontOfSize:15.f];
  26. [self.contentView addSubview:_nameLabel];
  27. _vipV = [[UIImageView alloc] init];
  28. [self.contentView addSubview:_vipV];
  29. [_vipV mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.equalTo(self.nameLabel.mas_right).offset(5.0f);
  31. make.centerY.equalTo(self.nameLabel);
  32. }];
  33. _anchorTagImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_anchor_vlog"]];
  34. _anchorTagImgV.hidden = YES;
  35. [self.contentView addSubview:_anchorTagImgV];
  36. [_anchorTagImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.right.equalTo(self.avatarImageView.mas_right).offset(0.0f);
  38. make.bottom.equalTo(self.avatarImageView.mas_bottom).offset(0.0f);
  39. make.size.mas_offset(CGSizeMake(14.0f, 14.0f));
  40. }];
  41. _intimateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  42. [_intimateBtn setImage:[UIImage imageNamed:@"vqu_images_im_intimate"] forState:UIControlStateNormal];
  43. _intimateBtn.userInteractionEnabled = NO;
  44. [_intimateBtn setTitleColor:LZFE66A4Color forState:UIControlStateNormal];
  45. _intimateBtn.titleLabel.font = LCFont(10.0f);
  46. _intimateBtn.hidden = YES;
  47. [_intimateBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
  48. [self.contentView addSubview:_intimateBtn];
  49. [_intimateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.right.bottom.offset(-12.0f);
  51. make.height.offset(15.0f);
  52. }];
  53. _officialImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_anchor_official"]];
  54. _officialImgV.hidden = YES;
  55. _officialImgV.nim_size = CGSizeMake(26.0f, 15.0f);
  56. [self.contentView addSubview:_officialImgV];
  57. _messageLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  58. // _messageLabel.backgroundColor = [UIColor whiteColor];
  59. _messageLabel.font = [UIFont systemFontOfSize:12.f];
  60. _messageLabel.textColor = LZA3AABEColor;
  61. [self.contentView addSubview:_messageLabel];
  62. _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  63. // _timeLabel.backgroundColor = [UIColor whiteColor];
  64. _timeLabel.font = [UIFont systemFontOfSize:11.f];
  65. _timeLabel.textColor = LZA3AABEColor;
  66. [self.contentView addSubview:_timeLabel];
  67. _badgeView = [NIMBadgeView viewWithBadgeTip:@""];
  68. _badgeView.CirclegroundColor = HexColorFromRGB(0xFF3B30);
  69. _badgeView.badgeBackgroundColor = HexColorFromRGB(0xFF3B30);
  70. [self.contentView addSubview:_badgeView];
  71. // UIView *viewLine =[UIView new];
  72. // [self.contentView addSubview:viewLine];
  73. // [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
  74. // make.right.mas_equalTo(0);
  75. // make.left.mas_equalTo(20);
  76. // make.bottom.mas_equalTo(0);
  77. // make.height.mas_equalTo(1);
  78. // }];
  79. // viewLine.backgroundColor =HexColorFromRGB(0x28262D);
  80. }
  81. //v1.5.6 适配暗黑 云信消息列表
  82. [self.contentView setBackgroundColor:[UIColor whiteColor]];
  83. return self;
  84. }
  85. #define NameLabelMaxWidth 160.f
  86. #define MessageLabelMaxWidth 200.f
  87. - (void)refresh:(NIMRecentSession*)recent{
  88. BOOL isTop =[NTESSessionUtil recentSessionIsMark:recent type:NTESRecentSessionMarkTypeTop];
  89. if (isTop) {
  90. self.contentView.backgroundColor = [UIColor whiteColor];
  91. }else{
  92. self.contentView.backgroundColor = [UIColor whiteColor];
  93. }
  94. // if ([recent.session.sessionId isEqualToString:[LCSaveData getSysId]] || [recent.session.sessionId isEqualToString:[LCSaveData getServerId]] ) {
  95. // self.nameLabel.textColor = LZ273145Color;
  96. // }else{
  97. // self.nameLabel.textColor = LZ273145Color;
  98. // }
  99. // NSLog(@"%@",[LCSaveData getServiceIdArr]);
  100. if ([recent.session.sessionId isEqualToString:[LCSaveData getSysId]] ||
  101. [recent.session.sessionId isEqualToString:@"11"] ||
  102. [[LCSaveData getServiceIdArr] containsObject:recent.session.sessionId]) {
  103. self.officialImgV.hidden = NO;
  104. }else{
  105. self.officialImgV.hidden = YES;
  106. }
  107. self.nameLabel.nim_width = self.nameLabel.nim_width > NameLabelMaxWidth ? NameLabelMaxWidth : self.nameLabel.nim_width;
  108. self.messageLabel.nim_width = self.messageLabel.nim_width > MessageLabelMaxWidth ? MessageLabelMaxWidth : self.messageLabel.nim_width;
  109. if (recent.unreadCount) {
  110. self.badgeView.hidden = NO;
  111. self.badgeView.badgeValue = @(recent.unreadCount).stringValue;
  112. }else{
  113. self.badgeView.hidden = YES;
  114. }
  115. }
  116. - (void)layoutSubviews{
  117. [super layoutSubviews];
  118. //Session List
  119. NSInteger sessionListAvatarLeft = 15;
  120. NSInteger sessionListNameTop = 15;
  121. NSInteger sessionListNameLeftToAvatar = 15;
  122. NSInteger sessionListMessageLeftToAvatar = 15;
  123. NSInteger sessionListMessageBottom = 15;
  124. NSInteger sessionListTimeRight = 15;
  125. NSInteger sessionListTimeTop = 15;
  126. NSInteger sessionBadgeTimeBottom = 15;
  127. NSInteger sessionBadgeTimeRight = 15;
  128. _avatarImageView.nim_left = sessionListAvatarLeft;
  129. _avatarImageView.nim_centerY = self.nim_height * .5f;
  130. _nameLabel.nim_top = sessionListNameTop;
  131. _nameLabel.nim_left = _avatarImageView.nim_right + sessionListNameLeftToAvatar;
  132. _messageLabel.nim_bottom = self.nim_height - sessionListMessageBottom;
  133. _timeLabel.nim_right = self.nim_width - sessionListTimeRight;
  134. _timeLabel.nim_top = sessionListTimeTop;
  135. _badgeView.nim_right = _avatarImageView.nim_right;
  136. _badgeView.nim_top = _avatarImageView.nim_top;
  137. _officialImgV.nim_left = _avatarImageView.nim_right + sessionListMessageLeftToAvatar;
  138. _officialImgV.nim_bottom = self.nim_height - sessionListMessageBottom;
  139. if (_officialImgV.hidden) {
  140. _messageLabel.nim_left = _avatarImageView.nim_right + sessionListMessageLeftToAvatar;
  141. }else{
  142. _messageLabel.nim_left = _officialImgV.nim_right + 4.0f;
  143. }
  144. }
  145. @end