123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- //
- // YMHomeChildCollectCell.m
- // MSYOUPAI
- //
- // Created by You on 2024/4/19.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMHomeChildCollectCell.h"
- #import "YMHomePageListCellViewModel.h"
- @interface YMHomeChildCollectCell()
- /// ViewModel
- @property (nonatomic, strong) YMHomePageListCellViewModel *viewModel;
- /// 基础视图
- @property (nonatomic, strong) UIView *baseView;
- /// 用户头像视图
- @property (nonatomic, strong) UIImageView *userAvatarView;
- /// 用户在线状态视图
- @property (nonatomic, strong) UIImageView *userOnlineStatusImgv;
- /// 用户在线状态点
- @property (nonatomic, strong) UIView *userOnlineStatusPointTopLeft;
- /// 用户在线状态视图
- @property (nonatomic, strong) UIView *userOnlineStatusView;
- /// 用户在线状态点
- @property (nonatomic, strong) UIView *userOnlineStatusPoint;
- /// 用户在线状态标签
- @property (nonatomic, strong) UILabel *userOnlineStatusLb;
- /// 用户昵称标签
- @property (nonatomic, strong) UILabel *userNicknameLb;
- /// 用户视频费用金额按钮
- @property (nonatomic, strong) UIButton *userVideoFeesAmountBtn;
- /// 心动或搭讪按钮
- @property (nonatomic, strong) UIButton *heartbeatOrAccostBtn;
- @end
- @implementation YMHomeChildCollectCell
- - (void)ym_setupViews{
-
- [self.contentView addSubview:self.baseView];
- [self.baseView addSubview:self.userAvatarView];
- [self.baseView addSubview:self.userNicknameLb];
-
- [self.baseView addSubview:self.userVideoFeesAmountBtn];
-
- [self.baseView addSubview:self.userOnlineStatusImgv];
- [self.baseView addSubview:self.userOnlineStatusPointTopLeft];
-
- [self.baseView addSubview:self.userOnlineStatusView];
- [self.userOnlineStatusView addSubview:self.userOnlineStatusPoint];
- [self.userOnlineStatusView addSubview:self.userOnlineStatusLb];
-
- [self.baseView addSubview:self.heartbeatOrAccostBtn];
-
- [self setupConstraints];
- }
- - (void)setupConstraints {
- [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.left.equalTo(self.contentView);
- make.right.equalTo(self.contentView);
- make.bottom.equalTo(self.contentView);
- }];
-
- [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.baseView).offset(adapt(5));
- make.left.equalTo(self.baseView).offset(adapt(5));
- make.width.height.mas_equalTo(adapt(80));
- }];
-
- [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userAvatarView.mas_top).offset(adapt(5));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- }];
-
- [self.userVideoFeesAmountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userNicknameLb.mas_bottom).offset(adapt(5));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- //make.centerY.equalTo(self.userAvatarView.mas_centerY).offset(adapt(0));
- }];
-
- [self.userOnlineStatusImgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userVideoFeesAmountBtn.mas_bottom).offset(adapt(5));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- //make.height.mas_equalTo(adapt(20));
- }];
- [self.userOnlineStatusPointTopLeft mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userAvatarView.mas_top).offset(adapt(0));
- make.left.equalTo(self.userAvatarView.mas_left).offset(adapt(0));
- make.width.height.mas_equalTo(adapt(8));
- }];
- [self.userOnlineStatusView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userVideoFeesAmountBtn.mas_bottom).offset(adapt(5));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- make.height.mas_equalTo(adapt(20));
- }];
-
- [self.userOnlineStatusPoint mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.userOnlineStatusView.mas_centerY);
- make.left.equalTo(self.userOnlineStatusView).offset(adapt(10));
- make.width.height.mas_equalTo(adapt(6));
- }];
-
- [self.userOnlineStatusLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.userOnlineStatusView.mas_centerY);
- make.left.equalTo(self.userOnlineStatusPoint.mas_right).offset(adapt(5));
- make.right.equalTo(self.userOnlineStatusView).offset(adapt(-10));
- }];
-
- [self.heartbeatOrAccostBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.baseView).offset(adapt(-10));
- make.centerY.equalTo(self.baseView.mas_centerY);
- make.width.mas_equalTo(adapt(80));
- make.height.mas_equalTo(adapt(32));
- }];
- }
- - (void)ym_bindViewModel:(YMHomePageListCellViewModel*)viewModel{
- if (!viewModel) {
- return;
- }
- _viewModel = viewModel;
-
- [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.userAvatar]];
-
- @weakify(self)
- [[[[RACObserve(self.viewModel, userOnlineStatusColor) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(UIColor * userOnlineStatusColor) {
- @strongify(self)
- self.userOnlineStatusPoint.backgroundColor = userOnlineStatusColor;
- self.userOnlineStatusPointTopLeft.backgroundColor = userOnlineStatusColor;
- }];
-
- [[[[RACObserve(self.viewModel, userOnlineStatusText) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * userOnlineStatusText) {
- @strongify(self)
- self.userOnlineStatusLb.text = userOnlineStatusText;
- if ([userOnlineStatusText containsString:@"空闲"]) {
- self.userOnlineStatusImgv.image = ImageByName(@"ym_common_home_status_kongxian");
- self.userOnlineStatusPointTopLeft.backgroundColor = HexColorFromRGB(0x22F759);
- } else if ([userOnlineStatusText containsString:@"在聊"]) {
- self.userOnlineStatusImgv.image = ImageByName(@"ym_common_home_status_zailiao");
- self.userOnlineStatusPointTopLeft.backgroundColor = HexColorFromRGB(0x98211D);
- } else if ([userOnlineStatusText containsString:@"离线"]) {
- self.userOnlineStatusImgv.image = ImageByName(@"ym_common_home_status_lixian");
- self.userOnlineStatusPointTopLeft.backgroundColor = HexColorFromRGB(0x98211D);
- }
- }];
-
- self.userNicknameLb.text = self.viewModel.userNickname;
- self.userNicknameLb.textColor = self.viewModel.userNicknameColor;
- self.userOnlineStatusPointTopLeft.backgroundColor = self.viewModel.is_onlineColor;
-
- [self.userVideoFeesAmountBtn setTitle:self.viewModel.userVideoFeesAmount forState:UIControlStateNormal];
- self.userVideoFeesAmountBtn.hidden = self.viewModel.isHideUserFeesAmount;
-
- if (self.viewModel.isHideUserFeesAmount) {
- [self.userNicknameLb mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.userAvatarView.mas_centerY).offset(adapt(-10));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- make.right.equalTo(self.heartbeatOrAccostBtn.mas_left).offset(adapt(-10));
- }];
- [self.userVideoFeesAmountBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userNicknameLb.mas_bottom).offset(adapt(5));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- make.height.mas_equalTo(0);
- }];
-
- [self.userOnlineStatusImgv mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userAvatarView.mas_centerY).offset(adapt(10));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- }];
- } else {
- [self.userNicknameLb mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userAvatarView.mas_top).offset(adapt(5));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- make.right.equalTo(self.heartbeatOrAccostBtn.mas_left).offset(adapt(-10));
- }];
- [self.userVideoFeesAmountBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- make.right.equalTo(self.heartbeatOrAccostBtn.mas_left).offset(adapt(-10));
- make.centerY.equalTo(self.userAvatarView.mas_centerY);
- }];
-
- [self.userOnlineStatusImgv mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- make.bottom.equalTo(self.userAvatarView.mas_bottom).offset(adapt(-10));
- }];
- }
-
- [self.heartbeatOrAccostBtn setTitle:self.viewModel.heartbeatOrAccostButtonTitle forState:UIControlStateNormal];
- [self.heartbeatOrAccostBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)];
- [self.heartbeatOrAccostBtn setImage:ImageByName(self.viewModel.heartbeatOrAccostButtonImage) forState:UIControlStateNormal];
- if ([self.viewModel.heartbeatOrAccostButtonTitle containsString:@"心动"] || [self.viewModel.heartbeatOrAccostButtonTitle containsString:@"搭讪"]) {
- [self.heartbeatOrAccostBtn ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0x7947DC),HexColorFromRGB(0xF34BCA)] locations:kMainGradLocation startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
- } else {
- [self.heartbeatOrAccostBtn ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xFFEA00),HexColorFromRGB(0xFF34CD)] locations:kMainGradLocation startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
- }
- //[self.heartbeatOrAccostBtn setTitleColor:self.viewModel.heartbeatOrAccostButtonTitleColor forState:UIControlStateNormal];
- //self.heartbeatOrAccostBtn.backgroundColor = self.viewModel.heartbeatOrAccostButtonBackgroundColor;
- }
- - (UIView *)baseView{
- if (!_baseView) {
- _baseView = [[UIView alloc]init];
- // _baseView.layer.cornerRadius = adapt(10);
- // _baseView.layer.masksToBounds = YES;
- }
- return _baseView;
- }
- - (UIImageView *)userAvatarView{
- if (!_userAvatarView) {
- _userAvatarView = [[UIImageView alloc]init];
- _userAvatarView.contentMode = UIViewContentModeScaleAspectFill;
- _userAvatarView.layer.cornerRadius = adapt(10);
- _userAvatarView.layer.masksToBounds = YES;
- _userAvatarView.clipsToBounds = YES;
- _userAvatarView.userInteractionEnabled = YES;
- }
- return _userAvatarView;
- }
- - (UIImageView *)userOnlineStatusImgv {
- if (!_userOnlineStatusImgv) {
- _userOnlineStatusImgv = [[UIImageView alloc] init];
- //_userOnlineStatusImgv.backgroundColor = HexColorFromRGBA(0x000000, 0.4);
- //_userOnlineStatusImgv.layer.cornerRadius = adapt(18)/2;
- //_userOnlineStatusImgv.layer.masksToBounds = YES;
- }
- return _userOnlineStatusImgv;
- }
- - (UIView *)userOnlineStatusPointTopLeft {
- if (!_userOnlineStatusPointTopLeft) {
- _userOnlineStatusPointTopLeft = [[UIView alloc]init];
- _userOnlineStatusPointTopLeft.layer.cornerRadius = adapt(8)/2;
- _userOnlineStatusPointTopLeft.layer.masksToBounds = YES;
- _userOnlineStatusPointTopLeft.layer.borderColor = UIColor.whiteColor.CGColor;
- _userOnlineStatusPointTopLeft.layer.borderWidth = 0.7;
- }
- return _userOnlineStatusPointTopLeft;
- }
- - (UIView *)userOnlineStatusView{
- if (!_userOnlineStatusView) {
- _userOnlineStatusView = [[UIView alloc]init];
- _userOnlineStatusView.hidden = YES;
- _userOnlineStatusView.layer.cornerRadius = adapt(20)/2;
- _userOnlineStatusView.layer.masksToBounds = YES;
- }
- return _userOnlineStatusView;
- }
- - (UIView *)userOnlineStatusPoint{
- if (!_userOnlineStatusPoint) {
- _userOnlineStatusPoint = [[UIView alloc]init];
- _userOnlineStatusPoint.backgroundColor = HexColorFromRGB(0xD8BFD8);
- _userOnlineStatusPoint.layer.cornerRadius = adapt(6)/2;
- _userOnlineStatusPoint.layer.masksToBounds = YES;
- }
- return _userOnlineStatusPoint;
- }
- - (UILabel *)userOnlineStatusLb{
- if (!_userOnlineStatusLb) {
- _userOnlineStatusLb = [[UILabel alloc]init];
- _userOnlineStatusLb.font = LCFont(12);
- _userOnlineStatusLb.textColor = HexColorFromRGB(0xFFFFFF);
- _userOnlineStatusLb.textAlignment = NSTextAlignmentCenter;
- _userOnlineStatusLb.text = @"空闲";
- }
- return _userOnlineStatusLb;
- }
- - (UILabel *)userNicknameLb{
- if (!_userNicknameLb) {
- _userNicknameLb = [[UILabel alloc]init];
- _userNicknameLb.font = LCBoldFont(13);
- _userNicknameLb.textColor = HexColorFromRGB(0x000000);
- _userNicknameLb.textAlignment = NSTextAlignmentLeft;
- _userNicknameLb.text = @"******";
- }
- return _userNicknameLb;
- }
- - (UIButton *)userVideoFeesAmountBtn{
- if (!_userVideoFeesAmountBtn) {
- _userVideoFeesAmountBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _userVideoFeesAmountBtn.titleLabel.font = LCFont(11);
- [_userVideoFeesAmountBtn setTitleColor:DecColorFromRGBA(0, 0, 0, 0.5) forState:UIControlStateNormal];
- [_userVideoFeesAmountBtn setTitle:@"****钻石/分钟" forState:UIControlStateNormal];
- [_userVideoFeesAmountBtn setImage:ImageByName(@"ym_home_page_diamond_icon") forState:UIControlStateNormal];
- _userVideoFeesAmountBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [_userVideoFeesAmountBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
- CGFloat margin = 3;
- _userVideoFeesAmountBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
- }
- return _userVideoFeesAmountBtn;
- }
- - (UIButton *)heartbeatOrAccostBtn{
- if (!_heartbeatOrAccostBtn) {
- _heartbeatOrAccostBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_heartbeatOrAccostBtn setImage:ImageByName(@"ym_common_home_heart") forState:UIControlStateNormal];
- _heartbeatOrAccostBtn.layer.cornerRadius = 10;
- _heartbeatOrAccostBtn.layer.masksToBounds = YES;
- _heartbeatOrAccostBtn.titleLabel.font = LCFont14;
- WS(weakSelf)
- [[[_heartbeatOrAccostBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- [weakSelf.viewModel sendAccostRequest];
- }];
- }
- return _heartbeatOrAccostBtn;
- }
- @end
|