YOUPAILCVideoChatMessageCell.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // YOUPAILCVideoChatMessageCell.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/10/15.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCVideoChatMessageCell.h"
  9. #import "SNKNinePatchImageView.h"
  10. @interface YOUPAILCVideoChatMessageCell()
  11. //@property (nonatomic,strong)UIView* backView;
  12. //@property (nonatomic,strong)UILabel* contentL;
  13. @property (nonatomic,weak) SNKNinePatchImageView *youpaipbubbleImgV;
  14. @property (nonatomic, weak) UILabel *youpaipcontentL;
  15. @end
  16. @implementation YOUPAILCVideoChatMessageCell
  17. //static NSString* IMCallChatCellID = @"YOUPAILCVideoChatMessageCell";
  18. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  19. {
  20. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  21. if (self) {
  22. self.transform = CGAffineTransformMakeScale(1, -1);
  23. self.backgroundColor = [UIColor clearColor];
  24. self.selectionStyle = UITableViewCellSelectionStyleNone;
  25. [self youpaifsetupView];
  26. }
  27. return self;
  28. }
  29. - (void)youpaifsetupView{
  30. SNKNinePatchImageView *bubbleImgV = [SNKNinePatchImageView new];
  31. bubbleImgV.imageScale = 2;
  32. bubbleImgV.userInteractionEnabled = YES;
  33. [self.contentView addSubview:bubbleImgV];
  34. self.youpaipbubbleImgV = bubbleImgV;
  35. UITapGestureRecognizer* tapGes =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentHandel:)];
  36. tapGes.numberOfTapsRequired = 1;
  37. [bubbleImgV addGestureRecognizer:tapGes];
  38. [bubbleImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.offset(0.0f);
  40. make.top.offset(6.0f);
  41. make.bottom.offset(0.0f);
  42. make.height.greaterThanOrEqualTo(38.0f);
  43. }];
  44. UILabel *contentL = [[UILabel alloc] init];
  45. contentL.textColor = [UIColor whiteColor];
  46. contentL.font = LCFont12;
  47. contentL.numberOfLines = 0;
  48. [self.contentView addSubview:contentL];
  49. self.youpaipcontentL = contentL;
  50. contentL.userInteractionEnabled = NO;
  51. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.width.lessThanOrEqualTo(226.0f);
  53. }];
  54. [bubbleImgV addConstraintsWithPaddingView:contentL];
  55. }
  56. //送礼物+收礼物
  57. - (void)setYoupaipmsgModel:(YOUPAILCVideoChatMessageModel *)msgModel{
  58. _youpaipmsgModel = msgModel;
  59. if (msgModel.youpaiptype==3){//礼物
  60. NSString *contentStr = @"";
  61. UIColor *nickColor = [UIColor whiteColor];
  62. NSRange range = NSMakeRange(0, 0);
  63. if ([msgModel.youpaipfrom_uid isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  64. contentStr = [NSString stringWithFormat:@"%@ ",@"我"];
  65. range = NSMakeRange(0, contentStr.length);
  66. nickColor = HexColorFromRGB(0xFF8AEA);
  67. }else{
  68. contentStr = [NSString stringWithFormat:@"%@ ",msgModel.youpaipfrom_nickname];
  69. range = NSMakeRange(0, contentStr.length);
  70. nickColor = HexColorFromRGB(0xFFDD8D);
  71. }
  72. self.youpaipcontentL.textColor = HexColorFromRGB(0xFFDD86);
  73. NSDictionary* giftDict = [msgModel.youpaipcontent mj_JSONObject];
  74. NSString* name = [giftDict objectForKey:@"giftname"];
  75. NSString* giftcount = [giftDict objectForKey:@"giftcount"];
  76. NSString* giftName = @"";
  77. giftName = [NSString stringWithFormat:@"送了%@个%@",giftcount,name];
  78. contentStr = [NSString stringWithFormat:@"%@%@",contentStr,giftName];
  79. NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr];
  80. NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  81. [paragraphStyle setLineSpacing:4];//设置行间距
  82. [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,attributedString.length)];
  83. [attributedString addAttribute:NSFontAttributeName value:LCFont14 range:NSMakeRange(0,attributedString.length)];
  84. [attributedString addAttribute:NSForegroundColorAttributeName value:nickColor range:range];
  85. [self.youpaipcontentL setAttributedText:attributedString];
  86. }else{
  87. NSString *contentStr = @"";
  88. UIColor *nickColor = [UIColor whiteColor];
  89. NSRange range = NSMakeRange(0, 0);
  90. if (msgModel.youpaiptype==2) {//文本
  91. if ([msgModel.youpaipfrom_uid isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  92. contentStr = [NSString stringWithFormat:@"%@: %@",@"我",msgModel.youpaipcontent];
  93. range = NSMakeRange(0, 2);
  94. nickColor = HexColorFromRGB(0xFE7575);
  95. }else{
  96. contentStr = [NSString stringWithFormat:@"%@: %@",msgModel.youpaipfrom_nickname,msgModel.youpaipcontent];
  97. range = NSMakeRange(0, msgModel.youpaipfrom_nickname.length + 1);
  98. nickColor = HexColorFromRGB(0x75EDFE);
  99. }
  100. self.youpaipcontentL.textColor = [UIColor whiteColor];
  101. }else if (msgModel.youpaiptype==1){//系统消息
  102. contentStr = [NSString stringWithFormat:@"系统消息: %@",msgModel.youpaipcontent];
  103. self.youpaipcontentL.textColor = HexColorFromRGB(0xFFACDB);
  104. }else if (msgModel.youpaiptype==6){//减免消息
  105. NSDictionary* reduceDict = [msgModel.youpaipcontent mj_JSONObject];
  106. NSString *reducetime = [reduceDict objectForKey:@"reducetime"];
  107. NSString *reducecost = [reduceDict objectForKey:@"reducecost"];
  108. NSString *text = [NSString stringWithFormat:@"系统消息: 减免了%@分钟,预计节省%@钻石",reducetime,reducecost];
  109. contentStr = text;
  110. self.youpaipcontentL.textColor = HexColorFromRGB(0xFFA68B);
  111. }
  112. NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr];
  113. NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  114. [paragraphStyle setLineSpacing:4];//设置行间距
  115. [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,attributedString.length)];
  116. [attributedString addAttribute:NSFontAttributeName value:LCFont14 range:NSMakeRange(0,attributedString.length)];
  117. [attributedString addAttribute:NSForegroundColorAttributeName value:nickColor range:range];
  118. [self.youpaipcontentL setAttributedText:attributedString];
  119. }
  120. self.youpaipcontentL.lineBreakMode = NSLineBreakByCharWrapping;
  121. NSString *ext = [self youpaifgetExtByUserId:msgModel.youpaipfrom_uid];
  122. if (ext.length != 0) {
  123. NSData *data = [ext dataUsingEncoding:NSUTF8StringEncoding];
  124. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
  125. if ([dict.allKeys containsObject:@"bubble"]) {
  126. NSString *bubble = [NSString stringWithFormat:@"%@",[dict valueForKey:@"bubble"]];
  127. if (bubble.length != 0) {
  128. self.youpaipbubbleImgV.ninePatchImage = [SNKNinePatchImage ninePatchImageWithImageData:[LCSaveData getBubbleWithKey:[LCTools getImageUrlWithAddress:bubble].absoluteString] scale:2];
  129. }
  130. }
  131. }
  132. if (self.youpaipbubbleImgV.ninePatchImage == nil) {
  133. self.youpaipbubbleImgV.ninePatchImage = [SNKNinePatchImage ninePatchImageWithImageData:[LCSaveData getBubbleWithKey:[LCTools getImageUrlWithAddress:@"/v1.3/dress/bubble/lALPD3zUOqg7eJA7bg_110_59.png"].absoluteString] scale:2];
  134. }
  135. }
  136. - (void)contentHandel:(UITapGestureRecognizer*)tap{
  137. if (tap.state == UIGestureRecognizerStateEnded) {
  138. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifcontentClicked:)]) {
  139. [self.youpaipdelegate youpaifcontentClicked:self.youpaipmsgModel];
  140. }
  141. }
  142. }
  143. - (NSString *)youpaifgetExtByUserId:(NSString *)userId{
  144. NIMUser *nimUser = [[[NIMSDK sharedSDK] userManager] userInfo:userId];
  145. return nimUser.userInfo.ext;
  146. }
  147. @end