YMHomeChildCollectCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. //
  2. // YMHomeChildCollectCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by You on 2024/4/19.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMHomeChildCollectCell.h"
  9. #import "YMHomePageListCellViewModel.h"
  10. @interface YMHomeChildCollectCell()
  11. /// ViewModel
  12. @property (nonatomic, strong) YMHomePageListCellViewModel *viewModel;
  13. /// 基础视图
  14. @property (nonatomic, strong) UIView *baseView;
  15. /// 用户头像视图
  16. @property (nonatomic, strong) UIImageView *userAvatarView;
  17. /// 用户在线状态视图
  18. @property (nonatomic, strong) UIImageView *userOnlineStatusImgv;
  19. /// 用户在线状态点
  20. @property (nonatomic, strong) UIView *userOnlineStatusPointTopLeft;
  21. /// 用户在线状态视图
  22. @property (nonatomic, strong) UIView *userOnlineStatusView;
  23. /// 用户在线状态点
  24. @property (nonatomic, strong) UIView *userOnlineStatusPoint;
  25. /// 用户在线状态标签
  26. @property (nonatomic, strong) UILabel *userOnlineStatusLb;
  27. /// 用户昵称标签
  28. @property (nonatomic, strong) UILabel *userNicknameLb;
  29. /// 用户视频费用金额按钮
  30. @property (nonatomic, strong) UIButton *userVideoFeesAmountBtn;
  31. /// 心动或搭讪按钮
  32. @property (nonatomic, strong) UIButton *heartbeatOrAccostBtn;
  33. @end
  34. @implementation YMHomeChildCollectCell
  35. - (void)ym_setupViews{
  36. [self.contentView addSubview:self.baseView];
  37. [self.baseView addSubview:self.userAvatarView];
  38. [self.baseView addSubview:self.userNicknameLb];
  39. [self.baseView addSubview:self.userVideoFeesAmountBtn];
  40. [self.baseView addSubview:self.userOnlineStatusImgv];
  41. [self.baseView addSubview:self.userOnlineStatusPointTopLeft];
  42. [self.baseView addSubview:self.userOnlineStatusView];
  43. [self.userOnlineStatusView addSubview:self.userOnlineStatusPoint];
  44. [self.userOnlineStatusView addSubview:self.userOnlineStatusLb];
  45. [self.baseView addSubview:self.heartbeatOrAccostBtn];
  46. [self setupConstraints];
  47. }
  48. - (void)setupConstraints {
  49. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.equalTo(self.contentView);
  51. make.left.equalTo(self.contentView);
  52. make.right.equalTo(self.contentView);
  53. make.bottom.equalTo(self.contentView);
  54. }];
  55. [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.equalTo(self.baseView).offset(adapt(5));
  57. make.left.equalTo(self.baseView).offset(adapt(5));
  58. make.width.height.mas_equalTo(adapt(80));
  59. }];
  60. [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.top.equalTo(self.userAvatarView.mas_top).offset(adapt(5));
  62. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  63. }];
  64. [self.userVideoFeesAmountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.equalTo(self.userNicknameLb.mas_bottom).offset(adapt(5));
  66. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  67. //make.centerY.equalTo(self.userAvatarView.mas_centerY).offset(adapt(0));
  68. }];
  69. [self.userOnlineStatusImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.top.equalTo(self.userVideoFeesAmountBtn.mas_bottom).offset(adapt(5));
  71. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  72. //make.height.mas_equalTo(adapt(20));
  73. }];
  74. [self.userOnlineStatusPointTopLeft mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.top.equalTo(self.userAvatarView.mas_top).offset(adapt(0));
  76. make.left.equalTo(self.userAvatarView.mas_left).offset(adapt(0));
  77. make.width.height.mas_equalTo(adapt(8));
  78. }];
  79. [self.userOnlineStatusView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.top.equalTo(self.userVideoFeesAmountBtn.mas_bottom).offset(adapt(5));
  81. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  82. make.height.mas_equalTo(adapt(20));
  83. }];
  84. [self.userOnlineStatusPoint mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.centerY.equalTo(self.userOnlineStatusView.mas_centerY);
  86. make.left.equalTo(self.userOnlineStatusView).offset(adapt(10));
  87. make.width.height.mas_equalTo(adapt(6));
  88. }];
  89. [self.userOnlineStatusLb mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.centerY.equalTo(self.userOnlineStatusView.mas_centerY);
  91. make.left.equalTo(self.userOnlineStatusPoint.mas_right).offset(adapt(5));
  92. make.right.equalTo(self.userOnlineStatusView).offset(adapt(-10));
  93. }];
  94. [self.heartbeatOrAccostBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.right.equalTo(self.baseView).offset(adapt(-10));
  96. make.centerY.equalTo(self.baseView.mas_centerY);
  97. make.width.mas_equalTo(adapt(80));
  98. make.height.mas_equalTo(adapt(32));
  99. }];
  100. }
  101. - (void)ym_bindViewModel:(YMHomePageListCellViewModel*)viewModel{
  102. if (!viewModel) {
  103. return;
  104. }
  105. _viewModel = viewModel;
  106. [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.userAvatar]];
  107. @weakify(self)
  108. [[[[RACObserve(self.viewModel, userOnlineStatusColor) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(UIColor * userOnlineStatusColor) {
  109. @strongify(self)
  110. self.userOnlineStatusPoint.backgroundColor = userOnlineStatusColor;
  111. self.userOnlineStatusPointTopLeft.backgroundColor = userOnlineStatusColor;
  112. }];
  113. [[[[RACObserve(self.viewModel, userOnlineStatusText) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * userOnlineStatusText) {
  114. @strongify(self)
  115. self.userOnlineStatusLb.text = userOnlineStatusText;
  116. if ([userOnlineStatusText containsString:@"空闲"]) {
  117. self.userOnlineStatusImgv.image = ImageByName(@"ym_common_home_status_kongxian");
  118. self.userOnlineStatusPointTopLeft.backgroundColor = HexColorFromRGB(0x22F759);
  119. } else if ([userOnlineStatusText containsString:@"在聊"]) {
  120. self.userOnlineStatusImgv.image = ImageByName(@"ym_common_home_status_zailiao");
  121. self.userOnlineStatusPointTopLeft.backgroundColor = HexColorFromRGB(0x98211D);
  122. } else if ([userOnlineStatusText containsString:@"离线"]) {
  123. self.userOnlineStatusImgv.image = ImageByName(@"ym_common_home_status_lixian");
  124. self.userOnlineStatusPointTopLeft.backgroundColor = HexColorFromRGB(0x98211D);
  125. }
  126. }];
  127. self.userNicknameLb.text = self.viewModel.userNickname;
  128. self.userNicknameLb.textColor = self.viewModel.userNicknameColor;
  129. self.userOnlineStatusPointTopLeft.backgroundColor = self.viewModel.is_onlineColor;
  130. [self.userVideoFeesAmountBtn setTitle:self.viewModel.userVideoFeesAmount forState:UIControlStateNormal];
  131. self.userVideoFeesAmountBtn.hidden = self.viewModel.isHideUserFeesAmount;
  132. if (self.viewModel.isHideUserFeesAmount) {
  133. [self.userNicknameLb mas_remakeConstraints:^(MASConstraintMaker *make) {
  134. make.bottom.equalTo(self.userAvatarView.mas_centerY).offset(adapt(-10));
  135. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  136. make.right.equalTo(self.heartbeatOrAccostBtn.mas_left).offset(adapt(-10));
  137. }];
  138. [self.userVideoFeesAmountBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  139. make.top.equalTo(self.userNicknameLb.mas_bottom).offset(adapt(5));
  140. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  141. make.height.mas_equalTo(0);
  142. }];
  143. [self.userOnlineStatusImgv mas_remakeConstraints:^(MASConstraintMaker *make) {
  144. make.top.equalTo(self.userAvatarView.mas_centerY).offset(adapt(10));
  145. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  146. }];
  147. } else {
  148. [self.userNicknameLb mas_remakeConstraints:^(MASConstraintMaker *make) {
  149. make.top.equalTo(self.userAvatarView.mas_top).offset(adapt(5));
  150. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  151. make.right.equalTo(self.heartbeatOrAccostBtn.mas_left).offset(adapt(-10));
  152. }];
  153. [self.userVideoFeesAmountBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  154. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  155. make.right.equalTo(self.heartbeatOrAccostBtn.mas_left).offset(adapt(-10));
  156. make.centerY.equalTo(self.userAvatarView.mas_centerY);
  157. }];
  158. [self.userOnlineStatusImgv mas_remakeConstraints:^(MASConstraintMaker *make) {
  159. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  160. make.bottom.equalTo(self.userAvatarView.mas_bottom).offset(adapt(-10));
  161. }];
  162. }
  163. [self.heartbeatOrAccostBtn setTitle:self.viewModel.heartbeatOrAccostButtonTitle forState:UIControlStateNormal];
  164. [self.heartbeatOrAccostBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)];
  165. [self.heartbeatOrAccostBtn setImage:ImageByName(self.viewModel.heartbeatOrAccostButtonImage) forState:UIControlStateNormal];
  166. if ([self.viewModel.heartbeatOrAccostButtonTitle containsString:@"心动"] || [self.viewModel.heartbeatOrAccostButtonTitle containsString:@"搭讪"]) {
  167. [self.heartbeatOrAccostBtn ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0x7947DC),HexColorFromRGB(0xF34BCA)] locations:kMainGradLocation startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  168. } else {
  169. [self.heartbeatOrAccostBtn ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xFFEA00),HexColorFromRGB(0xFF34CD)] locations:kMainGradLocation startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  170. }
  171. //[self.heartbeatOrAccostBtn setTitleColor:self.viewModel.heartbeatOrAccostButtonTitleColor forState:UIControlStateNormal];
  172. //self.heartbeatOrAccostBtn.backgroundColor = self.viewModel.heartbeatOrAccostButtonBackgroundColor;
  173. }
  174. - (UIView *)baseView{
  175. if (!_baseView) {
  176. _baseView = [[UIView alloc]init];
  177. // _baseView.layer.cornerRadius = adapt(10);
  178. // _baseView.layer.masksToBounds = YES;
  179. }
  180. return _baseView;
  181. }
  182. - (UIImageView *)userAvatarView{
  183. if (!_userAvatarView) {
  184. _userAvatarView = [[UIImageView alloc]init];
  185. _userAvatarView.contentMode = UIViewContentModeScaleAspectFill;
  186. _userAvatarView.layer.cornerRadius = adapt(10);
  187. _userAvatarView.layer.masksToBounds = YES;
  188. _userAvatarView.clipsToBounds = YES;
  189. _userAvatarView.userInteractionEnabled = YES;
  190. }
  191. return _userAvatarView;
  192. }
  193. - (UIImageView *)userOnlineStatusImgv {
  194. if (!_userOnlineStatusImgv) {
  195. _userOnlineStatusImgv = [[UIImageView alloc] init];
  196. //_userOnlineStatusImgv.backgroundColor = HexColorFromRGBA(0x000000, 0.4);
  197. //_userOnlineStatusImgv.layer.cornerRadius = adapt(18)/2;
  198. //_userOnlineStatusImgv.layer.masksToBounds = YES;
  199. }
  200. return _userOnlineStatusImgv;
  201. }
  202. - (UIView *)userOnlineStatusPointTopLeft {
  203. if (!_userOnlineStatusPointTopLeft) {
  204. _userOnlineStatusPointTopLeft = [[UIView alloc]init];
  205. _userOnlineStatusPointTopLeft.layer.cornerRadius = adapt(8)/2;
  206. _userOnlineStatusPointTopLeft.layer.masksToBounds = YES;
  207. _userOnlineStatusPointTopLeft.layer.borderColor = UIColor.whiteColor.CGColor;
  208. _userOnlineStatusPointTopLeft.layer.borderWidth = 0.7;
  209. }
  210. return _userOnlineStatusPointTopLeft;
  211. }
  212. - (UIView *)userOnlineStatusView{
  213. if (!_userOnlineStatusView) {
  214. _userOnlineStatusView = [[UIView alloc]init];
  215. _userOnlineStatusView.hidden = YES;
  216. _userOnlineStatusView.layer.cornerRadius = adapt(20)/2;
  217. _userOnlineStatusView.layer.masksToBounds = YES;
  218. }
  219. return _userOnlineStatusView;
  220. }
  221. - (UIView *)userOnlineStatusPoint{
  222. if (!_userOnlineStatusPoint) {
  223. _userOnlineStatusPoint = [[UIView alloc]init];
  224. _userOnlineStatusPoint.backgroundColor = HexColorFromRGB(0xD8BFD8);
  225. _userOnlineStatusPoint.layer.cornerRadius = adapt(6)/2;
  226. _userOnlineStatusPoint.layer.masksToBounds = YES;
  227. }
  228. return _userOnlineStatusPoint;
  229. }
  230. - (UILabel *)userOnlineStatusLb{
  231. if (!_userOnlineStatusLb) {
  232. _userOnlineStatusLb = [[UILabel alloc]init];
  233. _userOnlineStatusLb.font = LCFont(12);
  234. _userOnlineStatusLb.textColor = HexColorFromRGB(0xFFFFFF);
  235. _userOnlineStatusLb.textAlignment = NSTextAlignmentCenter;
  236. _userOnlineStatusLb.text = @"空闲";
  237. }
  238. return _userOnlineStatusLb;
  239. }
  240. - (UILabel *)userNicknameLb{
  241. if (!_userNicknameLb) {
  242. _userNicknameLb = [[UILabel alloc]init];
  243. _userNicknameLb.font = LCBoldFont(13);
  244. _userNicknameLb.textColor = HexColorFromRGB(0x000000);
  245. _userNicknameLb.textAlignment = NSTextAlignmentLeft;
  246. _userNicknameLb.text = @"******";
  247. }
  248. return _userNicknameLb;
  249. }
  250. - (UIButton *)userVideoFeesAmountBtn{
  251. if (!_userVideoFeesAmountBtn) {
  252. _userVideoFeesAmountBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  253. _userVideoFeesAmountBtn.titleLabel.font = LCFont(11);
  254. [_userVideoFeesAmountBtn setTitleColor:DecColorFromRGBA(0, 0, 0, 0.5) forState:UIControlStateNormal];
  255. [_userVideoFeesAmountBtn setTitle:@"****钻石/分钟" forState:UIControlStateNormal];
  256. [_userVideoFeesAmountBtn setImage:ImageByName(@"ym_home_page_diamond_icon") forState:UIControlStateNormal];
  257. _userVideoFeesAmountBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  258. [_userVideoFeesAmountBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
  259. CGFloat margin = 3;
  260. _userVideoFeesAmountBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
  261. }
  262. return _userVideoFeesAmountBtn;
  263. }
  264. - (UIButton *)heartbeatOrAccostBtn{
  265. if (!_heartbeatOrAccostBtn) {
  266. _heartbeatOrAccostBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  267. [_heartbeatOrAccostBtn setImage:ImageByName(@"ym_common_home_heart") forState:UIControlStateNormal];
  268. _heartbeatOrAccostBtn.layer.cornerRadius = 10;
  269. _heartbeatOrAccostBtn.layer.masksToBounds = YES;
  270. _heartbeatOrAccostBtn.titleLabel.font = LCFont14;
  271. WS(weakSelf)
  272. [[[_heartbeatOrAccostBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  273. [weakSelf.viewModel sendAccostRequest];
  274. }];
  275. }
  276. return _heartbeatOrAccostBtn;
  277. }
  278. @end