123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //
- // YOUPAILCVideoChatMessageCell.m
- // LiveChat
- //
- // Created by 张灿 on 2018/10/15.
- // Copyright © 2018年 caicai. All rights reserved.
- //
- #import "YOUPAILCVideoChatMessageCell.h"
- #import "SNKNinePatchImageView.h"
- @interface YOUPAILCVideoChatMessageCell()
- //@property (nonatomic,strong)UIView* backView;
- //@property (nonatomic,strong)UILabel* contentL;
- @property (nonatomic,weak) SNKNinePatchImageView *youpaipbubbleImgV;
- @property (nonatomic, weak) UILabel *youpaipcontentL;
- @end
- @implementation YOUPAILCVideoChatMessageCell
- //static NSString* IMCallChatCellID = @"YOUPAILCVideoChatMessageCell";
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.transform = CGAffineTransformMakeScale(1, -1);
- self.backgroundColor = [UIColor clearColor];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- [self youpaifsetupView];
- }
- return self;
- }
- - (void)youpaifsetupView{
-
- SNKNinePatchImageView *bubbleImgV = [SNKNinePatchImageView new];
- bubbleImgV.imageScale = 2;
- bubbleImgV.userInteractionEnabled = YES;
- [self.contentView addSubview:bubbleImgV];
- self.youpaipbubbleImgV = bubbleImgV;
- UITapGestureRecognizer* tapGes =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentHandel:)];
- tapGes.numberOfTapsRequired = 1;
- [bubbleImgV addGestureRecognizer:tapGes];
- [bubbleImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0.0f);
- make.top.offset(6.0f);
- make.bottom.offset(0.0f);
- make.height.greaterThanOrEqualTo(38.0f);
- }];
-
- UILabel *contentL = [[UILabel alloc] init];
- contentL.textColor = [UIColor whiteColor];
- contentL.font = LCFont12;
- contentL.numberOfLines = 0;
- [self.contentView addSubview:contentL];
- self.youpaipcontentL = contentL;
- contentL.userInteractionEnabled = NO;
- [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.lessThanOrEqualTo(226.0f);
- }];
- [bubbleImgV addConstraintsWithPaddingView:contentL];
- }
- //送礼物+收礼物
- - (void)setYoupaipmsgModel:(YOUPAILCVideoChatMessageModel *)msgModel{
- _youpaipmsgModel = msgModel;
- if (msgModel.youpaiptype==3){//礼物
- NSString *contentStr = @"";
- UIColor *nickColor = [UIColor whiteColor];
- NSRange range = NSMakeRange(0, 0);
-
- if ([msgModel.youpaipfrom_uid isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- contentStr = [NSString stringWithFormat:@"%@ ",@"我"];
- range = NSMakeRange(0, contentStr.length);
- nickColor = HexColorFromRGB(0xFF8AEA);
- }else{
- contentStr = [NSString stringWithFormat:@"%@ ",msgModel.youpaipfrom_nickname];
- range = NSMakeRange(0, contentStr.length);
- nickColor = HexColorFromRGB(0xFFDD8D);
- }
- self.youpaipcontentL.textColor = HexColorFromRGB(0xFFDD86);
-
- NSDictionary* giftDict = [msgModel.youpaipcontent mj_JSONObject];
- NSString* name = [giftDict objectForKey:@"giftname"];
- NSString* giftcount = [giftDict objectForKey:@"giftcount"];
- NSString* giftName = @"";
- giftName = [NSString stringWithFormat:@"送了%@个%@",giftcount,name];
- contentStr = [NSString stringWithFormat:@"%@%@",contentStr,giftName];
-
- NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr];
- NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//设置行间距
- [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,attributedString.length)];
- [attributedString addAttribute:NSFontAttributeName value:LCFont14 range:NSMakeRange(0,attributedString.length)];
- [attributedString addAttribute:NSForegroundColorAttributeName value:nickColor range:range];
- [self.youpaipcontentL setAttributedText:attributedString];
- }else{
- NSString *contentStr = @"";
- UIColor *nickColor = [UIColor whiteColor];
- NSRange range = NSMakeRange(0, 0);
- if (msgModel.youpaiptype==2) {//文本
-
- if ([msgModel.youpaipfrom_uid isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- contentStr = [NSString stringWithFormat:@"%@: %@",@"我",msgModel.youpaipcontent];
- range = NSMakeRange(0, 2);
- nickColor = HexColorFromRGB(0xFE7575);
- }else{
- contentStr = [NSString stringWithFormat:@"%@: %@",msgModel.youpaipfrom_nickname,msgModel.youpaipcontent];
- range = NSMakeRange(0, msgModel.youpaipfrom_nickname.length + 1);
- nickColor = HexColorFromRGB(0x75EDFE);
- }
- self.youpaipcontentL.textColor = [UIColor whiteColor];
- }else if (msgModel.youpaiptype==1){//系统消息
- contentStr = [NSString stringWithFormat:@"系统消息: %@",msgModel.youpaipcontent];
- self.youpaipcontentL.textColor = HexColorFromRGB(0xFFACDB);
- }else if (msgModel.youpaiptype==6){//减免消息
- NSDictionary* reduceDict = [msgModel.youpaipcontent mj_JSONObject];
- NSString *reducetime = [reduceDict objectForKey:@"reducetime"];
- NSString *reducecost = [reduceDict objectForKey:@"reducecost"];
- NSString *text = [NSString stringWithFormat:@"系统消息: 减免了%@分钟,预计节省%@钻石",reducetime,reducecost];
- contentStr = text;
- self.youpaipcontentL.textColor = HexColorFromRGB(0xFFA68B);
- }
- NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr];
- NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//设置行间距
- [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,attributedString.length)];
- [attributedString addAttribute:NSFontAttributeName value:LCFont14 range:NSMakeRange(0,attributedString.length)];
- [attributedString addAttribute:NSForegroundColorAttributeName value:nickColor range:range];
- [self.youpaipcontentL setAttributedText:attributedString];
- }
- self.youpaipcontentL.lineBreakMode = NSLineBreakByCharWrapping;
-
- NSString *ext = [self youpaifgetExtByUserId:msgModel.youpaipfrom_uid];
- if (ext.length != 0) {
- NSData *data = [ext dataUsingEncoding:NSUTF8StringEncoding];
- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
- if ([dict.allKeys containsObject:@"bubble"]) {
- NSString *bubble = [NSString stringWithFormat:@"%@",[dict valueForKey:@"bubble"]];
- if (bubble.length != 0) {
-
- self.youpaipbubbleImgV.ninePatchImage = [SNKNinePatchImage ninePatchImageWithImageData:[LCSaveData getBubbleWithKey:[LCTools getImageUrlWithAddress:bubble].absoluteString] scale:2];
- }
- }
- }
- if (self.youpaipbubbleImgV.ninePatchImage == nil) {
- self.youpaipbubbleImgV.ninePatchImage = [SNKNinePatchImage ninePatchImageWithImageData:[LCSaveData getBubbleWithKey:[LCTools getImageUrlWithAddress:@"/v1.3/dress/bubble/lALPD3zUOqg7eJA7bg_110_59.png"].absoluteString] scale:2];
- }
- }
- - (void)contentHandel:(UITapGestureRecognizer*)tap{
- if (tap.state == UIGestureRecognizerStateEnded) {
- if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifcontentClicked:)]) {
- [self.youpaipdelegate youpaifcontentClicked:self.youpaipmsgModel];
- }
- }
- }
- - (NSString *)youpaifgetExtByUserId:(NSString *)userId{
- NIMUser *nimUser = [[[NIMSDK sharedSDK] userManager] userInfo:userId];
- return nimUser.userInfo.ext;
- }
- @end
|