YMHomePageListCell.m 16 KB

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