YOUPAILPFollowContentView.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // YOUPAILPFollowContentView.m
  3. // zhimi
  4. //
  5. // Created by 张灿 on 2019/1/28.
  6. // Copyright © 2019年 caiPro. All rights reserved.
  7. //
  8. #import "YOUPAILPFollowContentView.h"
  9. #import "YOUPAILPFollowAttachment.h"
  10. #import "YOUPAILZLiveGradeModel.h"
  11. #import "YOUPAILZLevelView.h"
  12. @interface YOUPAILPFollowContentView()
  13. @property(nonatomic,strong)UIView* backView;
  14. //@property(nonatomic,strong)UILabel* topTitle;
  15. //@property(nonatomic,strong)UILabel* timeTitle;
  16. //@property(nonatomic,strong)UIView* botmView;
  17. //@property(nonatomic,assign)CGFloat currentY;
  18. @end
  19. @implementation YOUPAILPFollowContentView
  20. - (instancetype)initSessionMessageContentView{
  21. self = [super initSessionMessageContentView];
  22. if (self) {
  23. self.opaque = YES;
  24. UIView* testView = [[UIView alloc] initWithFrame:CGRectZero];
  25. testView.backgroundColor= UIColor.whiteColor;
  26. // testView.layer.cornerRadius = 10.0;
  27. UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)];
  28. [testView addGestureRecognizer:tap];
  29. self.backView = testView;
  30. self.bubbleImageView.hidden = YES;
  31. [self addSubview:testView];
  32. // UILabel* topTitle = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, KScreenWidth-70, 60)];
  33. // self.topTitle = topTitle;
  34. // topTitle.font = [UIFont systemFontOfSize:24];
  35. // topTitle.textColor = LCTextBlack;
  36. // [self.backView addSubview:topTitle];
  37. }
  38. return self;
  39. }
  40. - (void)refresh:(NIMMessageModel *)data{
  41. [super refresh:data];
  42. NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject;
  43. id attachment = customObject.attachment;
  44. if ([attachment isKindOfClass:[YOUPAILPFollowAttachment class]]) {
  45. for (UIView* subView in self.backView.subviews) {
  46. [subView removeFromSuperview];
  47. }
  48. YOUPAILPFollowAttachment* attachment = (YOUPAILPFollowAttachment*)customObject.attachment;
  49. UILabel* topTitle = [[UILabel alloc]initWithFrame:CGRectMake(14.0f, 0, KScreenWidth-28.0f, 16.0f)];
  50. topTitle.font = LCFont16;
  51. topTitle.textColor = LZ273145Color;
  52. //modify by leo v1.0.7
  53. NSLog(@"类型 == %ld",attachment.type);
  54. if(attachment.type == 16)
  55. topTitle.text = @"新增粉丝";
  56. else if(attachment.type == 17)
  57. topTitle.text = @"发布动态";
  58. else if(attachment.type == 19)
  59. topTitle.text = @"发布视频";
  60. else
  61. topTitle.text = @"上线啦!";
  62. [self.backView addSubview:topTitle];
  63. // UIView* followView = [[UIView alloc]initWithFrame:CGRectMake(0, 60, KScreenWidth-30, 80)];
  64. // [self.backView addSubview:followView];
  65. //
  66. UIImageView* avatarImgV = [[UIImageView alloc]init];
  67. avatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  68. avatarImgV.layer.masksToBounds = YES;
  69. avatarImgV.layer.cornerRadius = 22.0f;
  70. [self.backView addSubview:avatarImgV];
  71. [avatarImgV makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.offset(14);
  73. make.top.equalTo(topTitle.mas_bottom).offset(17);
  74. make.size.mas_equalTo(CGSizeMake(44.0f, 44.0f));
  75. }];
  76. //
  77. UILabel* nickLab = [[UILabel alloc]init];
  78. nickLab.textColor = LZ273145Color;
  79. nickLab.font = LCFont14;
  80. [self.backView addSubview:nickLab];
  81. [nickLab makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.equalTo(avatarImgV.right).offset(@10);
  83. make.top.equalTo(avatarImgV.top).offset(@5);
  84. }];
  85. UIImageView *sexV = [[UIImageView alloc] init];
  86. [self.backView addSubview:sexV];
  87. [sexV mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.equalTo(nickLab.mas_right).offset(3.0f);
  89. make.centerY.equalTo(nickLab);
  90. make.size.mas_offset(CGSizeMake(15.0f, 15.0f));
  91. }];
  92. YOUPAILZLevelView *levelView = [[YOUPAILZLevelView alloc] init];
  93. [self.backView addSubview:levelView];
  94. [levelView mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.left.equalTo(sexV.mas_right).offset(5.0f);
  96. make.centerY.equalTo(nickLab);
  97. }];
  98. UIButton *hiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  99. // hiBtn.layer.borderWidth = 0.5f;
  100. // hiBtn.layer.borderColor = HexColorFromRGB(0xF4003F).CGColor;
  101. hiBtn.layer.cornerRadius = 11.0f;
  102. hiBtn.clipsToBounds = YES;
  103. hiBtn.backgroundColor = HexColorFromRGB(0xF4003F);
  104. [hiBtn setTitle:@"去打招呼" forState:UIControlStateNormal];
  105. [hiBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  106. hiBtn.titleLabel.font = LCFont12;
  107. [hiBtn addTarget:self action:@selector(hiBtnClick) forControlEvents:UIControlEventTouchUpInside];
  108. [self.backView addSubview:hiBtn];
  109. [hiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.right.offset(-14.0f);
  111. make.centerY.equalTo(avatarImgV);
  112. make.size.mas_offset(CGSizeMake(64.0f, 22.0f));
  113. }];
  114. UILabel *signL = [[UILabel alloc] init];
  115. signL.textColor = HexColorFromRGB(0x9F9DA5);
  116. signL.font = LCFont12;
  117. [self.backView addSubview:signL];
  118. [signL mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.left.equalTo(avatarImgV.mas_right).offset(10.0f);
  120. make.top.equalTo(nickLab.mas_bottom).offset(8.0f);
  121. make.right.equalTo(hiBtn.mas_left).offset(-10.0f);
  122. }];
  123. [avatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:attachment.avatar]];
  124. nickLab.text = attachment.nickname;
  125. if (attachment.sex == 1) {
  126. sexV.image = [UIImage imageNamed:@"vqu_images_D_dynamic_woman"];
  127. }else{
  128. sexV.image = [UIImage imageNamed:@"vqu_images_D_dynamic_man"];
  129. }
  130. YOUPAILZLiveGradeModel *model = [YOUPAILZLiveGradeModel mj_objectWithKeyValues:attachment.grade];
  131. [levelView youpaifreloadWithIcon:model.youpaipimg1 iconWidth:model.youpaipicon_width bgImg:model.youpaipimg2 bgImgWidth:model.youpaipicon1_width levelName:model.youpaipgrade_name level:model.youpaipgrade];
  132. [levelView mas_updateConstraints:^(MASConstraintMaker *make) {
  133. make.size.mas_offset(levelView.mj_size);
  134. }];
  135. signL.text = attachment.sign.length == 0 ? @" " : attachment.sign;
  136. }
  137. }
  138. - (void)tapHandel:(UITapGestureRecognizer*)tap{
  139. if (tap.state == UIGestureRecognizerStateEnded) {
  140. // NIMKitEvent *event = [[NIMKitEvent alloc] init];
  141. // event.eventName = NIMKitEventNameTapContent;
  142. // event.messageModel = self.model;
  143. // [self.delegate onCatchEvent:event];
  144. NIMCustomObject *customObject = (NIMCustomObject*)self.model.message.messageObject;
  145. YOUPAILPFollowAttachment* attachment = (YOUPAILPFollowAttachment*)customObject.attachment;
  146. attachment.type = 16;
  147. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  148. event.eventName = NIMKitEventNameTapContent;
  149. event.messageModel = self.model;
  150. [self.delegate onCatchEvent:event];
  151. }
  152. }
  153. - (void)hiBtnClick{
  154. NIMCustomObject *customObject = (NIMCustomObject*)self.model.message.messageObject;
  155. YOUPAILPFollowAttachment* attachment = (YOUPAILPFollowAttachment*)customObject.attachment;
  156. attachment.type = 1;
  157. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  158. event.eventName = NIMKitEventNameTapContent;
  159. event.messageModel = self.model;
  160. [self.delegate onCatchEvent:event];
  161. }
  162. - (void)onTouchUpInside:(id)sender
  163. {
  164. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  165. event.eventName = NIMKitEventNameTapContent;
  166. event.messageModel = self.model;
  167. [self.delegate onCatchEvent:event];
  168. }
  169. - (void)layoutSubviews{
  170. [super layoutSubviews];
  171. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  172. CGSize contentsize = [self.model contentSize:KScreenWidth];
  173. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height);
  174. self.backView.frame = imageViewFrame;
  175. }
  176. @end