RoomUserCell.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //
  2. // RoomUserCell.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/8/1.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "RoomUserCell.h"
  9. #import "RoomUserInfo.h"
  10. #import "RoomVoiceModel.h"
  11. #import <FLAnimatedImage/FLAnimatedImage.h>
  12. #import "SVGAHeader.h"
  13. @interface RoomUserCell ()
  14. {
  15. NSString *lastHeadImageUrl;
  16. }
  17. @property (weak, nonatomic) IBOutlet UIImageView *adminImageView;
  18. @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
  19. @property (weak, nonatomic) IBOutlet UIView *adminView;
  20. @property (weak, nonatomic) IBOutlet UIImageView *giftSexImageView;
  21. @property (weak, nonatomic) IBOutlet UILabel *giftLabel;
  22. @property (weak, nonatomic) IBOutlet UIView *giftView;
  23. @property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
  24. @property (weak, nonatomic) IBOutlet UILabel *linkLabel;
  25. @property (weak, nonatomic) IBOutlet UIImageView *borderImageView;
  26. @property (weak, nonatomic) IBOutlet UIView *breathView;
  27. @property (weak, nonatomic) IBOutlet UIImageView *muteImageView;
  28. @property(nonatomic, strong) SVGAHeader *svgaHeader;
  29. @property(nonatomic, strong) UIImageView *animateImageView;
  30. @property(nonatomic, strong) CAShapeLayer *shapeLayer;
  31. @property (weak, nonatomic) IBOutlet UIImageView *headImageView;
  32. @property (weak, nonatomic) IBOutlet QMUIButton *nameBtn;
  33. @property(nonatomic, strong) UIButton *glBtn;
  34. @end
  35. @implementation RoomUserCell
  36. {
  37. YYAnimatedImageView *yyimg;
  38. }
  39. - (void)awakeFromNib {
  40. [super awakeFromNib];
  41. // Initialization code
  42. self.nameLabel.font = [UIFont systemFontOfSize:11];
  43. self.nameLabel.textColor = kWhiteColor;
  44. self.giftView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.2];
  45. self.giftLabel.textColor = UIColor.whiteColor;
  46. self.giftView.userInteractionEnabled = YES;
  47. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(giftViewAction:)];
  48. [self.giftView addGestureRecognizer:tap];
  49. [self.headImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  50. make.center.equalTo(self.iconImageView);
  51. make.size.mas_equalTo(50*headdressRatio);
  52. }];
  53. self.svgaHeader = [[SVGAHeader alloc] init];
  54. self.svgaHeader.userInteractionEnabled = NO;
  55. [self.headImageView addSubview:self.svgaHeader];
  56. [self.svgaHeader mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.edges.equalTo(self.headImageView);
  58. }];
  59. self.nameLabel.hidden = YES;
  60. self.nameBtn.imagePosition = QMUIButtonImagePositionLeft;
  61. self.nameBtn.spacingBetweenImageAndTitle = 5;
  62. [self addSubview:self.glBtn];
  63. [self.glBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  64. make.top.mas_equalTo(55+5);
  65. make.centerX.mas_equalTo(0);
  66. make.width.mas_equalTo(30.5);
  67. make.height.mas_equalTo(12);
  68. }];
  69. self.contentView.clipsToBounds = NO;
  70. self.clipsToBounds = NO;
  71. self.breathView.clipsToBounds = NO;
  72. // self.glBtn.centerX = self.centerX;
  73. // self.glBtn.top = 55;
  74. CAGradientLayer *gl = [CAGradientLayer layer];
  75. gl.frame = CGRectMake(0,0,30.5,12);
  76. gl.startPoint = CGPointMake(0, 0);
  77. gl.endPoint = CGPointMake(1, 0);
  78. gl.colors = @[(__bridge id)[UIColor colorWithRed:255/255.0 green:204/255.0 blue:101/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:255/255.0 green:89/255.0 blue:152/255.0 alpha:1.0].CGColor];
  79. gl.locations = @[@(0.0),@(1.0f)];
  80. [_glBtn.layer insertSublayer:gl atIndex:0];
  81. // yyimg = [[YYAnimatedImageView alloc] init];
  82. // yyimg.image = [YYImage imageNamed:@"mic_pppp.webp"];
  83. //
  84. // [self.breathView addSubview:yyimg];
  85. // [yyimg mas_makeConstraints:^(MASConstraintMaker *make) {
  86. // make.center.equalTo(self.breathView);
  87. // make.size.equalTo(self.breathView);
  88. // }];
  89. }
  90. - (void)giftViewAction:(UITapGestureRecognizer *)tap{
  91. if (self.delegate && [self.delegate respondsToSelector:@selector(userCell:didClickGiftView:)]) {
  92. [self.delegate userCell:self didClickGiftView:tap.view];
  93. }
  94. }
  95. - (void)setModel:(RoomUserInfo *)model{
  96. _model = model;
  97. if (model.is_ban_voice.integerValue == 0) {
  98. self.muteImageView.hidden = !model.isMuted;
  99. }else{
  100. self.muteImageView.hidden = !model.is_ban_voice;
  101. }
  102. if(lastHeadImageUrl != model.headwear_url)
  103. {
  104. lastHeadImageUrl = model.headwear_url;
  105. [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.headwear_url]];
  106. }
  107. // if (model.face_img && model.face_img.length) {
  108. // if (!self.animateImageView.isAnimating) {
  109. // [self.contentView addSubview:self.animateImageView];
  110. // [self.animateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  111. // make.edges.equalTo(self.iconImageView);
  112. // }];
  113. // [self.animateImageView setAnimatedImage:[FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.face_img]]]];
  114. // [self performSelector:@selector(dismissGif) withObject:nil afterDelay:3];
  115. // }
  116. // }
  117. if (model.user_id.intValue) {
  118. if (model.isMuted || model.is_ban_voice.integerValue) {
  119. self.breathView.hidden = YES;
  120. [self stopVolumeAnimation];
  121. }else{
  122. if (model.volume > 10) {
  123. self.breathView.hidden = NO;
  124. } else {
  125. self.breathView.hidden = YES;
  126. }
  127. [self volumeAnimation];
  128. }
  129. }else{
  130. self.breathView.hidden = YES;
  131. [self stopVolumeAnimation];
  132. }
  133. }
  134. - (void)dismissGif{
  135. self.model.face_img = @"";
  136. // [self.animateImageView stopAnimating];
  137. [self.animateImageView removeFromSuperview];
  138. }
  139. - (void)setWheatModel:(Wheat_Type_List *)wheatModel{
  140. _wheatModel = wheatModel;
  141. // if(wheatModel.totalVolume > 10)
  142. // {
  143. //
  144. // }
  145. self.breathView.backgroundColor = kClearColor;
  146. if (wheatModel.even_wheat.user_id) {
  147. if (wheatModel.even_wheat.is_ban_voice) {
  148. self.breathView.hidden = YES;
  149. [self stopVolumeAnimation];
  150. }else{
  151. if (wheatModel.totalVolume > 10) {
  152. self.breathView.hidden = NO;
  153. } else {
  154. self.breathView.hidden = YES;
  155. }
  156. [self volumeAnimation];
  157. }
  158. }else{
  159. self.breathView.hidden = YES;
  160. // [self stopVolumeAnimation];
  161. }
  162. // self.breathView.hidden = YES;
  163. if (!_wheatModel.even_wheat.user_id) {
  164. // [self.iconImageView setImage:[UIImage imageNamed:wheatModel.type.integerValue == 1 ? @"upper_wheat" : @"apply"]];
  165. if (_model.location.intValue == 1 && self.is_open_guest) {
  166. [self.iconImageView setImage:[UIImage imageNamed:@"guest_haed"]];
  167. [self.linkLabel setText:ASLocalizedString(@"嘉宾位")];
  168. } else {
  169. [self.iconImageView setImage:[UIImage imageNamed:wheatModel.type == 1 ? @"mic_colck" : @"mic_up"]];
  170. [self.linkLabel setText:wheatModel.type == 0 ? ASLocalizedString(@"直接上麦") : ASLocalizedString(@"申请上麦")];
  171. }
  172. self.muteImageView.hidden = YES;
  173. }else{
  174. self.muteImageView.hidden = !wheatModel.even_wheat.is_ban_voice;
  175. [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:wheatModel.even_wheat.head_image] placeholderImage:kDefaultPreloadHeadImg];
  176. if (wheatModel.face_img && wheatModel.face_img.length) {
  177. [self.contentView addSubview:self.animateImageView];
  178. [self.animateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  179. make.edges.equalTo(self.iconImageView);
  180. }];
  181. [self.animateImageView sd_setImageWithURL:[NSURL URLWithString:SafeStr(wheatModel.face_img)]];
  182. [self performSelector:@selector(dismissGif) withObject:nil afterDelay:3];
  183. }
  184. }
  185. //
  186. if(lastHeadImageUrl != wheatModel.even_wheat.avatar_frame_url)
  187. {
  188. lastHeadImageUrl = wheatModel.even_wheat.avatar_frame_url;
  189. self.svgaHeader.headerUrl = wheatModel.even_wheat.avatar_frame_url;
  190. // [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.headwear_url]];
  191. }
  192. // self.headImageView
  193. self.adminImageView.hidden = !_model.is_admin.integerValue;
  194. if (wheatModel.even_wheat.nick_name) {
  195. [self.nameLabel setText:wheatModel.even_wheat.nick_name];
  196. [self.nameBtn setTitle:wheatModel.even_wheat.nick_name forState:UIControlStateNormal];
  197. }else{
  198. [self.nameBtn setTitle:[NSString stringWithFormat:@"%@",wheatModel.wheat_name] forState:UIControlStateNormal];
  199. }
  200. if (_model.is_vip.intValue) {
  201. [self.nameLabel setTextColor:kRedColor];
  202. [self.nameBtn setTitleColor:kRedColor forState:UIControlStateNormal];
  203. }else{
  204. // [self.nameLabel setTextColor:[[UIColor colorWithHexString:@"D0FFFF"] colorWithAlphaComponent:0.5]];
  205. self.nameLabel.textColor = kWhiteColor;
  206. [self.nameBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  207. }
  208. // if (self.is_open_guest) {
  209. // [self.nameBtn setImage:nil forState:UIControlStateNormal];
  210. //
  211. // }else{
  212. //
  213. // if (_model.is_admin.integerValue) {
  214. // [self.nameBtn setImage:[UIImage imageNamed:@"administrators"] forState:UIControlStateNormal];
  215. // } else {
  216. // [self.nameBtn setImage:nil forState:UIControlStateNormal];
  217. //
  218. // }
  219. // }
  220. if (_model.location.intValue == 1 && self.is_open_guest) {
  221. self.glBtn.hidden = NO;
  222. }else{
  223. self.glBtn.hidden = YES;
  224. }
  225. self.giftView.hidden = !_wheatModel.even_wheat.user_id;
  226. self.linkLabel.hidden = _model.user_id.integerValue;
  227. self.borderImageView.image = _model.user_id.integerValue ? [UIImage imageNamed:@"member_haed"] : nil;
  228. //显示信息
  229. self.giftSexImageView.contentMode = UIViewContentModeScaleAspectFit;
  230. self.giftSexImageView.image = [UIImage imageNamed: _model.sex.integerValue == 1 ? @"hart1" : @"hart1"];
  231. if(_wheatModel.even_wheat.gift_earnings == 0)
  232. {
  233. self.giftLabel.text = @"0";
  234. }
  235. else
  236. {
  237. self.giftLabel.text = [NSString stringWithFormat:@"%ld",_wheatModel.even_wheat.gift_earnings];
  238. }
  239. // self.giftLabel.text = _model.gift_earnings;
  240. // if (KGlobalVariable.appmodel.voice_charm_type.intValue == 1) {
  241. // self.giftLabel.text = [NSString formatStringFromSum:_model.gift_earnings.length ? _model.gift_earnings : @"0.00"];
  242. // }else{
  243. // self.giftLabel.text = [NSString formatStringFromSum:_model.gift_earnings.length ? _model.gift_earnings : @"0"];
  244. // }
  245. }
  246. - (UIImageView *)animateImageView{
  247. if (!_animateImageView) {
  248. // FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif"]]];
  249. _animateImageView = [[UIImageView alloc] init];
  250. // imageView.animatedImage = image;
  251. }
  252. return _animateImageView;
  253. }
  254. #pragma mark - 水波纹
  255. - (void)volumeAnimation{
  256. if (!_shapeLayer) {
  257. _shapeLayer = [CAShapeLayer layer];
  258. _shapeLayer.frame = CGRectMake(0, 0, self.breathView.width, self.breathView.height);
  259. _shapeLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, self.breathView.width, self.breathView.height)].CGPath;
  260. _shapeLayer.fillColor = [UIColor colorWithHexString:@"#02E0C3"].CGColor;
  261. _shapeLayer.opacity = 0.0;
  262. CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
  263. replicatorLayer.frame = CGRectMake(0, 0, self.breathView.width, self.breathView.height);
  264. replicatorLayer.instanceDelay = 0.8;
  265. replicatorLayer.instanceCount = 5;
  266. replicatorLayer.cornerRadius = 40;
  267. [replicatorLayer addSublayer:_shapeLayer];
  268. self.breathView.layer.cornerRadius = 40;
  269. self.breathView.clipsToBounds = YES;
  270. [self.breathView.layer addSublayer:replicatorLayer];
  271. CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
  272. animationGroup.animations = @[[self alphaAnimation],[self scaleAnimation]];
  273. animationGroup.duration = 3;
  274. animationGroup.autoreverses = NO;
  275. animationGroup.repeatCount = HUGE;
  276. //页面跳转再返回后,动画是否停止
  277. animationGroup.removedOnCompletion = NO;
  278. [_shapeLayer addAnimation:animationGroup forKey:@"animationGroup"];
  279. }
  280. }
  281. - (void)stopVolumeAnimation{
  282. [_shapeLayer removeAnimationForKey:@"animationGroup"];
  283. _shapeLayer = nil;
  284. }
  285. - (CABasicAnimation *)alphaAnimation{
  286. CABasicAnimation *alpha = [CABasicAnimation animationWithKeyPath:@"opacity"];
  287. alpha.fromValue = @(1.0);
  288. alpha.toValue = @(0.0);
  289. return alpha;
  290. }
  291. - (CABasicAnimation *)scaleAnimation{
  292. CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform"];
  293. scale.fromValue = [NSValue valueWithCATransform3D:CATransform3DScale(CATransform3DIdentity, 0.0, 0.0, 0.0)];
  294. scale.toValue = [NSValue valueWithCATransform3D:CATransform3DScale(CATransform3DIdentity, 1.5, 1.5, 0.0)];
  295. return scale;
  296. }
  297. - (UIButton *)glBtn{
  298. if (!_glBtn) {
  299. _glBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30.5, 12)];
  300. [_glBtn.titleLabel setFont:[UIFont systemFontOfSize:9]];
  301. [_glBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  302. [_glBtn setTitle:ASLocalizedString(@"嘉宾") forState:UIControlStateNormal];
  303. ViewRadius(_glBtn, 12/2.0);
  304. // [_glBtn setThemeGradientBgColor];
  305. _glBtn.hidden = YES;
  306. }
  307. return _glBtn;
  308. }
  309. @end