123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- //
- // YOUPAILCMessageTxtContentView.m
- // LiveChat
- //
- // Created by 张灿 on 2018/9/22.
- // Copyright © 2018年 caicai. All rights reserved.
- //
- #import "YOUPAILCMessageTxtContentView.h"
- #import "YOUPAILCMessageTxtAttachment.h"
- #import "NIMKitInfoFetchOption.h"
- @interface YOUPAILCMessageTxtContentView()
- @property(nonatomic,strong)UIView* backView;
- @property(nonatomic,strong)UILabel* topTitle;
- @property(nonatomic,strong)UILabel* timeTitle;
- @property(nonatomic,strong)UIView* botmView;
- @property(nonatomic,assign)CGFloat currentY;
- @end
- @implementation YOUPAILCMessageTxtContentView
- - (instancetype)initSessionMessageContentView{
- self = [super initSessionMessageContentView];
- if (self) {
- self.opaque = YES;
- UIView* testView = [[UIView alloc] initWithFrame:CGRectZero];
- testView.backgroundColor = [UIColor clearColor];
- UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)];
- [testView addGestureRecognizer:tap];
- self.backView = testView;
- self.bubbleImageView.hidden = YES;
- [self addSubview:testView];
-
- // UILabel* topTitle = [[UILabel alloc]initWithFrame:CGRectMake(14.0f, 0, KScreenWidth-28.0f, 20)];
- // self.topTitle = topTitle;
- // topTitle.font = [UIFont systemFontOfSize:18];
- // topTitle.textColor = LCTextBlack;
- // [self.backView addSubview:topTitle];
- //
- //// UILabel* timeTitle = [[UILabel alloc]initWithFrame:CGRectMake(20, 40, KScreenWidth-70, 20)];
- //// self.timeTitle = timeTitle;
- //// timeTitle.font = [UIFont systemFontOfSize:15];
- //// timeTitle.textColor = LCTextGray;
- //// [self.backView addSubview:timeTitle];
- //
- // UIView* botmView = [[UIView alloc]initWithFrame:CGRectZero];
- // botmView.backgroundColor = [UIColor clearColor];
- // self.botmView = botmView;
- // botmView.hidden = YES;
- // [self.backView addSubview:botmView];
- // UIView* lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-28, 0.5)];
- // lineView.backgroundColor = HexColorFromRGB(0x28262D);
- // [botmView addSubview:lineView];
- //
- // UILabel* btnLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-70, 44)];
- // btnLabel.textAlignment = NSTextAlignmentLeft;
- // btnLabel.font = [UIFont systemFontOfSize:12];
- // btnLabel.textColor = HexColorFromRGB(0x9F9DA5);
- // btnLabel.text = @"详情 >";
- // [botmView addSubview:btnLabel];
- }
- return self;
- }
- - (void)refresh:(NIMMessageModel *)data{
- [super refresh:data];
- NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject;
- id attachment = customObject.attachment;
- if ([attachment isKindOfClass:[YOUPAILCMessageTxtAttachment class]]) {
- for (UIView* subView in self.backView.subviews) {
- [subView removeFromSuperview];
- }
-
- YOUPAILCMessageTxtAttachment* attachment = (YOUPAILCMessageTxtAttachment*)customObject.attachment;
-
- UIImageView *avatarImgV = [[UIImageView alloc] init];
- avatarImgV.layer.cornerRadius = 10.0f;
- avatarImgV.clipsToBounds = YES;
- avatarImgV.contentMode = UIViewContentModeScaleAspectFill;
- [self setAvatarBySession:data.message.session avatarImgV:avatarImgV] ;
- [self.backView addSubview:avatarImgV];
- [avatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(16.0f);
- make.size.mas_offset(CGSizeMake(40.0f, 40.0f));
- make.top.offset(0.0f);
- }];
-
- UIView *bgV = [[UIView alloc] init];
- bgV.backgroundColor = [UIColor whiteColor];
- bgV.layer.cornerRadius = 10.0f;
- bgV.clipsToBounds = YES;
- [self.backView addSubview:bgV];
- [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(avatarImgV.mas_right).offset(10.0f);
- make.width.offset(243.0f);
- make.top.bottom.offset(0.0f);
- }];
- UILabel* topTitle = [[UILabel alloc]init];
- topTitle.numberOfLines = 0;
- // self.topTitle = topTitle;
- // CGFloat topTitleHeight = [attachment.title heightWithFont:LCFont16 padding:3.0 constrainedToWidth:KScreenWidth-28.0f];
- topTitle.text = attachment.title;
- topTitle.font = LCFont(14.0f);
- topTitle.textColor = LZ273145Color;
- // topTitle.mj_h = topTitleHeight+2;
- [UILabel changeLineSpaceForLabel:topTitle WithSpace:3.0];
- [bgV addSubview:topTitle];
- [topTitle mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(12.0f);
- make.right.offset(-12.0f);
- make.top.offset(10.0f);
- }];
-
- UIView *frontV = topTitle;
- //
- //// UILabel* timeTitle = [[UILabel alloc]initWithFrame:CGRectMake(20, topTitleHeight+25, KScreenWidth-70, 20)];
- //// self.timeTitle = timeTitle;
- //// timeTitle.font = [UIFont systemFontOfSize:15];
- //// timeTitle.textColor = LCTextGray;
- //// self.timeTitle.text = attachment.date;
- //// [self.backView addSubview:timeTitle];
- // self.currentY = topTitleHeight + 17.0f;
- //
- UIView* botmView = [[UIView alloc]init];
- botmView.backgroundColor = [UIColor clearColor];
- // self.botmView = botmView;
- botmView.hidden = YES;
- [bgV addSubview:botmView];
- [botmView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.offset(0.0f);
- make.height.offset(32.0f);
- }];
- [botmView addLineWithColor:LZF5F4F7Color lineRect:CGRectMake(12.0f, 0.0f, 243.0f - 24.0f, 0.5f)];
- //
- UILabel* btnLabel = [[UILabel alloc]init];
- btnLabel.textAlignment = NSTextAlignmentLeft;
- btnLabel.font = [UIFont systemFontOfSize:12];
- btnLabel.textColor = LZ7C69FEColor;
- btnLabel.text = @"详情 >";
- [botmView addSubview:btnLabel];
- [btnLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(12.0f);
- make.right.offset(-12.0f);
- make.top.bottom.offset(0.0f);
- }];
- //
- if (![attachment.txt1 isEqualToString:@""]) {
- UILabel* txtOneLabel = [[UILabel alloc]init];
- txtOneLabel.numberOfLines = 0;
- txtOneLabel.text = attachment.txt1;
- txtOneLabel.font = LCFont(11.0f);
- txtOneLabel.textColor = LZA3AABEColor;
- // CGFloat txtOneHeight =[attachment.txt1 heightWithFont:LCFont12 padding:3.0 constrainedToWidth:KScreenWidth-28.0f];
- // txtOneLabel.frame = CGRectMake(14.0f, self.currentY, KScreenWidth-28.0f, txtOneHeight+2);
- [UILabel changeLineSpaceForLabel:txtOneLabel WithSpace:3.0];
- [bgV addSubview:txtOneLabel];
- [txtOneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(12.0f);
- make.right.offset(-12.0f);
- make.top.equalTo(frontV.mas_bottom).offset(5.0f);
- }];
-
- frontV = txtOneLabel;
- // self.currentY += txtOneHeight;
- }
- if ([attachment.fields isKindOfClass:[NSArray class]] &&attachment.fields.count>0) {
- // self.currentY += 5.0f;
- for (NSDictionary* dict in attachment.fields) {
- NSString* name = [dict objectForKey:@"n"];
- NSString* value = [dict objectForKey:@"v"];
- UILabel* dataLabel = [[UILabel alloc]init];
- NSString* dataStr = [NSString stringWithFormat:@"%@: %@",name,value];
- // CGFloat dataLabelHeight =[dataStr heightWithFont:LCFont12 padding:3.0 constrainedToWidth:KScreenWidth-28.0f];
- dataLabel.numberOfLines = 0;
- dataLabel.font = LCFont(11.0f);
- dataLabel.textColor = LZA3AABEColor;
- dataLabel.text = dataStr;
- // dataLabel.frame = CGRectMake(14.0f, self.currentY, KScreenWidth-28.0f, dataLabelHeight+2);
- [UILabel changeLineSpaceForLabel:dataLabel WithSpace:3.0];
- [bgV addSubview:dataLabel];
- [dataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(12.0f);
- make.right.offset(-12.0f);
- make.top.equalTo(frontV.mas_bottom).offset(5.0f);
- }];
- frontV = dataLabel;
- // self.currentY +=dataLabelHeight+5;
- }
- }
- if (![attachment.txt2 isEqualToString:@""]) {
- UILabel* txtTwoLabel = [[UILabel alloc]init];
- txtTwoLabel.text = attachment.txt2;
- txtTwoLabel.numberOfLines = 0;
- txtTwoLabel.font = LCFont(11.0f);
- txtTwoLabel.textColor = LZA3AABEColor;
- // CGFloat txtTwoHeight =[attachment.txt2 heightWithFont:LCFont12 padding:3.0 constrainedToWidth:KScreenWidth-28.0f];
- // txtTwoLabel.frame = CGRectMake(14.0f, self.currentY+14.0f, KScreenWidth-28.0f, txtTwoHeight+2);
- [UILabel changeLineSpaceForLabel:txtTwoLabel WithSpace:3.0];
- [bgV addSubview:txtTwoLabel];
- [txtTwoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(12.0f);
- make.right.offset(-12.0f);
- make.top.equalTo(frontV.mas_bottom).offset(5.0f);
- }];
-
- frontV = txtTwoLabel;
- // self.currentY += txtTwoHeight+16;
- }
- // self.currentY += 17.0f;
- if (attachment.link_type!=0) {
- botmView.hidden = NO;
- }
- // [self.backView addLineWithColor:HexColorFromRGB(0x28262D) lineRect:CGRectMake(14.0f, self.currentY - 0.5f, KScreenWidth - 28.0f, 0.5f)];
- }
-
- }
- - (void)tapHandel:(UITapGestureRecognizer*)tap{
- if (tap.state == UIGestureRecognizerStateEnded) {
- NIMKitEvent *event = [[NIMKitEvent alloc] init];
- event.eventName = NIMKitEventNameTapContent;
- event.messageModel = self.model;
- [self.delegate onCatchEvent:event];
- }
- }
- - (void)onTouchUpInside:(id)sender
- {
- NIMKitEvent *event = [[NIMKitEvent alloc] init];
- event.eventName = NIMKitEventNameTapContent;
- event.messageModel = self.model;
- [self.delegate onCatchEvent:event];
- }
- - (void)layoutSubviews{
- [super layoutSubviews];
- UIEdgeInsets contentInsets = self.model.contentViewInsets;
- CGSize contentsize = [self.model contentSize:KScreenWidth];
- CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height);
- self.backView.frame = imageViewFrame;
-
- }
- - (void)setAvatarBySession:(NIMSession *)session avatarImgV:(UIImageView *)avatarImgV
- {
- NIMKitInfo *info = nil;
- if (session.sessionType == NIMSessionTypeTeam)
- {
- info = [[NIMKit sharedKit] infoByTeam:session.sessionId option:nil];
- }
- else
- {
- NIMKitInfoFetchOption *option = [[NIMKitInfoFetchOption alloc] init];
- option.session = session;
- info = [[NIMKit sharedKit] infoByUser:session.sessionId option:option];
- }
- NSURL *url = info.avatarUrlString ? [NSURL URLWithString:info.avatarUrlString] : nil;
- NIMUser* nimUser = [[[NIMSDK sharedSDK] userManager] userInfo:session.sessionId];
- if(nimUser.userInfo.gender == NIMUserGenderMale){//默认男头像
- info.avatarImage = [UIImage imageNamed:@"woman"];
- }else{
- info.avatarImage = [UIImage imageNamed:@"vqu_images_P_man"];
- }
- [avatarImgV sd_setImageWithURL:[[LCTools getImageUrlWithAddress:[url absoluteString]] urlWithImageScale:60] placeholderImage:info.avatarImage];
- }
- @end
|