WFCUPortraitCollectionViewCell.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // WFCUPortraitCollectionViewCell.m
  3. // WFChatUIKit
  4. //
  5. // Created by dali on 2020/1/20.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #if WFCU_SUPPORT_VOIP
  9. #import "WFCUPortraitCollectionViewCell.h"
  10. #import <SDWebImage/SDWebImage.h>
  11. @interface WFCUPortraitCollectionViewCell ()
  12. @property (nonatomic, strong)UIImageView *portraitView;
  13. @property (nonatomic, strong)UILabel *nameLabel;
  14. @property (nonatomic, strong)UIImageView *stateLabel;
  15. @property (nonatomic, strong)UIImageView *speakingView;
  16. @end
  17. @implementation WFCUPortraitCollectionViewCell
  18. - (void)setUserInfo:(WFCCUserInfo *)userInfo {
  19. _userInfo = userInfo;
  20. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"PersonalChat"]];
  21. self.nameLabel.text = userInfo.displayName;
  22. _speakingView.hidden = YES;
  23. [[NSNotificationCenter defaultCenter] removeObserver:self];
  24. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVolumeUpdated:) name:@"wfavVolumeUpdated" object:userInfo.userId];
  25. }
  26. - (void)onVolumeUpdated:(NSNotification *)notification {
  27. NSInteger volume = [notification.userInfo[@"volume"] integerValue];
  28. if (volume > 1000) {
  29. self.speakingView.hidden = NO;
  30. [self bringSubviewToFront:self.speakingView];
  31. } else {
  32. self.speakingView.hidden = YES;
  33. }
  34. }
  35. -(void)setProfile:(WFAVParticipantProfile *)profile {
  36. _profile = profile;
  37. if (profile.state == kWFAVEngineStateConnected || profile.state == kWFAVEngineStateIdle) {
  38. [self.stateLabel stopAnimating];
  39. self.stateLabel.hidden = YES;
  40. } else {
  41. [self.stateLabel startAnimating];
  42. self.stateLabel.hidden = NO;
  43. }
  44. }
  45. - (UIImageView *)portraitView {
  46. if (!_portraitView) {
  47. _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.itemSize, self.itemSize)];
  48. _portraitView.layer.masksToBounds = YES;
  49. _portraitView.layer.cornerRadius = 2.f;
  50. [self addSubview:_portraitView];
  51. }
  52. return _portraitView;
  53. }
  54. - (UIImageView *)speakingView {
  55. if (!_speakingView) {
  56. _speakingView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.itemSize - 20, 20, 20)];
  57. _speakingView.layer.masksToBounds = YES;
  58. _speakingView.layer.cornerRadius = 2.f;
  59. _speakingView.image = [UIImage imageNamed:@"speaking"];
  60. [self addSubview:_speakingView];
  61. }
  62. return _speakingView;
  63. }
  64. - (UILabel *)nameLabel {
  65. if (!_nameLabel) {
  66. _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.itemSize, self.itemSize, self.labelSize)];
  67. _nameLabel.font = [UIFont systemFontOfSize:self.labelSize - 4];
  68. _nameLabel.textColor = [UIColor whiteColor];
  69. _nameLabel.textAlignment = NSTextAlignmentCenter;
  70. [self addSubview:_nameLabel];
  71. }
  72. return _nameLabel;
  73. }
  74. - (UIImageView *)stateLabel {
  75. if (!_stateLabel) {
  76. _stateLabel = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.itemSize, self.itemSize)];
  77. _stateLabel.animationImages = @[[UIImage imageNamed:@"connect_ani1"],[UIImage imageNamed:@"connect_ani2"],[UIImage imageNamed:@"connect_ani3"]];
  78. _stateLabel.animationDuration = 1.f;
  79. _stateLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
  80. [self addSubview:_stateLabel];
  81. }
  82. return _stateLabel;
  83. }
  84. - (void)dealloc {
  85. [[NSNotificationCenter defaultCenter] removeObserver:self];
  86. }
  87. @end
  88. #endif