// // QXUserHomeHeaderView.m // QXLive // // Created by 启星 on 2025/5/20. // #import "QXUserHomeHeaderView.h" #import "QXSeatHeaderView.h" #import "QXSearchCell.h" #import "NSDate+BRPickerView.h" #import "NSString+QX.h" #import "QXDynamicNetwork.h" #import "QXChatViewController.h" #import "CKShimmerLabel.h" #import "QXUserCpDressView.h" #import "QXUserCpCardView.h" #import "QXGiftWallViewController.h" #import "QXHeartBeatSpaceViewController.h" #import "QXUserHomePageViewController.h" #import "QXHeartBeatSpaceViewController.h" @interface QXUserHomeHeaderView() //@property (nonatomic,strong) CKShimmerLabel * tempName; @property (nonatomic,strong) QXSeatHeaderView* headerView; @property (nonatomic,strong) UIView * whiteBgView; @property (nonatomic,strong) UIView * grayBgView; @property (nonatomic,strong) CKShimmerLabel * nameLabel; @property (nonatomic,strong) UILabel * idLabel; //@property (nonatomic,strong) UILabel * ageLabel; @property (nonatomic,strong) UIImageView * guildBgImageView; @property (nonatomic,strong) UILabel * guildLabel; @property (nonatomic,strong) UICollectionView * collectionView; @property (nonatomic,strong) NSMutableArray * tagArray; @property (nonatomic,strong) UILabel *introduceLabel; @property (nonatomic,strong) UICollectionView *inCollectionView; @property (nonatomic, strong) UIImageView *useCodeImageView; //@property (nonatomic, strong)UIImageView *sexImageView; @property (nonatomic,strong) UIButton *followBtn; @property (nonatomic,strong) UIButton *playBtn; @property (nonatomic,strong) QXUserCpDressView *cpDressView; @property (nonatomic,strong) QXUserCpCardView *cpCardView; @property (nonatomic,strong) UIButton *giftWallBtn; @end @implementation QXUserHomeHeaderView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ self.backgroundColor = [UIColor clearColor]; self.headerView = [[QXSeatHeaderView alloc] initWithFrame:CGRectMake(32, 26, 70, 84)]; [self addSubview:self.headerView]; [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(32); make.width.mas_equalTo(70); make.height.mas_equalTo(84); make.top.mas_equalTo(26); }]; self.nameLabel = [[CKShimmerLabel alloc] initWithFrame:CGRectMake(32, self.headerView.bottom+4, 200, 24)]; // self.nameLabel.text = @"羽声语音"; self.nameLabel.shimmerWidth = 20; self.nameLabel.shimmerRadius = 20; self.nameLabel.durationTime = 1; self.nameLabel.repeat = YES; self.nameLabel.textColor = QXConfig.textColor; // self.nameLabel.shimmerColor = [UIColor yellowColor]; self.nameLabel.font = [UIFont boldSystemFontOfSize:18]; // [self.nameLabel startShimmer]; [self addSubview:self.nameLabel]; [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerView); make.height.mas_equalTo(24); make.top.equalTo(self.headerView.mas_bottom).offset(4); make.width.mas_greaterThanOrEqualTo(200); }]; self.followBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.playBtn.left-6-91, self.whiteBgView.top+10, 91, 12)]; [self.followBtn setTitle:QXText(@"关注") forState:(UIControlStateNormal)]; [self.followBtn setTitle:QXText(@"已关注") forState:(UIControlStateSelected)]; [self.followBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; [self.followBtn setTitleColor:RGB16(0x999999) forState:(UIControlStateSelected)]; [self.followBtn setBackgroundImage:[UIImage imageWithColor:QXConfig.themeColor] forState:UIControlStateNormal]; [self.followBtn setBackgroundImage:[UIImage imageWithColor:RGB16(0xF1F2F3)] forState:UIControlStateSelected]; self.followBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.followBtn addRoundedCornersWithRadius:12]; self.followBtn.hidden = YES; [self.followBtn addTarget:self action:@selector(followAction) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.followBtn]; [self.followBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.nameLabel.mas_right).offset(10); make.width.mas_equalTo(55); make.height.mas_equalTo(24); make.centerY.equalTo(self.nameLabel); }]; // self.sexImageView = [[UIImageView alloc] init]; // [self addSubview:self.sexImageView]; // [self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.nameLabel.mas_right).offset(5); // make.centerY.equalTo(self.nameLabel); // make.height.width.mas_equalTo(16); // }]; self.idLabel = [[UILabel alloc] init]; self.idLabel.textColor = RGB16(0x999999); self.idLabel.font = [UIFont boldSystemFontOfSize:12]; [self addSubview:self.idLabel]; [self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.nameLabel); make.height.mas_equalTo(18); make.top.equalTo(self.nameLabel.mas_bottom).offset(5); }]; self.useCodeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_usercode_isLiang"]]; self.useCodeImageView.hidden = YES; [self addSubview:self.useCodeImageView]; [self.useCodeImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.idLabel.mas_right).offset(5); make.height.mas_equalTo(11); make.width.mas_equalTo(31); make.centerY.equalTo(self.idLabel); }]; // self.ageLabel = [[UILabel alloc] init]; // self.ageLabel.textColor = RGB16(0x999999); // self.ageLabel.font = [UIFont boldSystemFontOfSize:12]; // [self addSubview:self.ageLabel]; // [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.headerView); // make.height.mas_equalTo(18); // make.top.equalTo(self.nameLabel.mas_bottom).offset(8); // make.width.mas_greaterThanOrEqualTo(35); // }]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake(UserIconWidth, UserIconHeight); layout.minimumLineSpacing = 7; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.backgroundColor = UIColor.clearColor; [self.collectionView registerClass:[QXTagImageCell class] forCellWithReuseIdentifier:@"QXTagImageCell"]; [self addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.nameLabel); make.height.mas_equalTo(18); make.top.equalTo(self.idLabel.mas_bottom).offset(5); make.width.mas_equalTo(ScaleWidth(240)); }]; self.introduceLabel = [[UILabel alloc] init]; self.introduceLabel.textColor = QXConfig.textColor; self.introduceLabel.font = [UIFont systemFontOfSize:14]; self.introduceLabel.numberOfLines = 0; [self addSubview:self.introduceLabel]; [self.introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerView); make.top.equalTo(self.collectionView.mas_bottom).offset(6); make.width.mas_equalTo(SCREEN_WIDTH-64); make.height.mas_greaterThanOrEqualTo(17); }]; UICollectionViewFlowLayout *inlayout = [[UICollectionViewFlowLayout alloc] init]; inlayout.itemSize = CGSizeMake(77, 22); inlayout.minimumLineSpacing = 12; inlayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; self.inCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:inlayout]; self.inCollectionView.delegate = self; self.inCollectionView.dataSource = self; self.inCollectionView.showsHorizontalScrollIndicator = NO; self.inCollectionView.backgroundColor = UIColor.clearColor; [self.inCollectionView registerClass:[QXSearchCell class] forCellWithReuseIdentifier:@"QXSearchCell"]; [self addSubview:self.inCollectionView]; [self.inCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerView); make.height.mas_equalTo(22); make.top.equalTo(self.introduceLabel.mas_bottom).offset(4); make.right.mas_equalTo(-32); }]; self.whiteBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 46, self.width, 167)]; self.whiteBgView.backgroundColor = RGB16(0xffffff); [self.whiteBgView addRoundedCornersWithRadius:16]; [self insertSubview:self.whiteBgView belowSubview:self.headerView]; [self.whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.equalTo(self.headerView.mas_top).offset(20); make.bottom.equalTo(self.inCollectionView).offset(10); }]; self.guildBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_home_guild_bg"]]; [self.whiteBgView addSubview:self.guildBgImageView]; [self.guildBgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-8); make.height.mas_equalTo(31); make.top.mas_equalTo(6); make.width.mas_equalTo(94); }]; self.guildLabel = [[UILabel alloc] init]; self.guildLabel.textColor = RGB16(0xffffff); self.guildLabel.textAlignment = NSTextAlignmentCenter; self.guildLabel.lineBreakMode = NSLineBreakByClipping; self.guildLabel.font = [UIFont boldSystemFontOfSize:10]; [self.whiteBgView addSubview:self.guildLabel]; [self.guildLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.guildBgImageView).offset(6); make.height.mas_equalTo(14); make.top.equalTo(self.guildBgImageView).offset(6); make.right.equalTo(self.guildBgImageView).offset(-28); }]; self.grayBgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.whiteBgView.top+75, self.width, 92)]; self.grayBgView.backgroundColor = RGB16(0xF3F3F3); // [self.grayBgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; [self insertSubview:self.grayBgView belowSubview:self.whiteBgView]; [self.grayBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self); make.top.equalTo(self.whiteBgView).offset(16); make.bottom.equalTo(self); }]; self.playBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.playBtn.left-6-91, self.whiteBgView.top+10, 91, 24)]; // [self.playBtn setTitle:QXText(@"私信") forState:(UIControlStateNormal)]; // [self.playBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)]; // self.playBtn.backgroundColor = RGB16(0x333333); self.playBtn.hidden = YES; self.playBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.playBtn addRoundedCornersWithRadius:12]; [self.playBtn addTarget:self action:@selector(playAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.whiteBgView addSubview:self.playBtn]; [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.guildBgImageView.mas_left).offset(-6); make.width.mas_equalTo(59); make.height.mas_equalTo(24); make.centerY.equalTo(self.guildBgImageView).offset(-2); }]; // self.nameLabel.text = @"张三"; // self.idLabel.text = @"313213213"; // self.ageLabel.text = @"36岁"; // self.introduceLabel.text = @"个人简介个人简介个人简介个人简个人简介"; [self.inCollectionView reloadData]; self.cpDressView = [[QXUserCpDressView alloc] initWithFrame:CGRectMake(self.width-15-ScaleWidth(120), 0, ScaleWidth(120), ScaleWidth(194))]; self.cpDressView.hidden = YES; [self.whiteBgView addSubview:self.cpDressView]; self.cpCardView = [[QXUserCpCardView alloc] init]; self.cpCardView.delegate = self; self.cpCardView.hidden = YES; MJWeakSelf [self.cpCardView addTapBlock:^(id _Nonnull obj) { QXHeartBeatSpaceViewController*vc = [[QXHeartBeatSpaceViewController alloc] init]; vc.userId = weakSelf.userId; [weakSelf.viewController.navigationController pushViewController:vc animated:YES]; }]; [self addSubview:self.cpCardView]; [self.cpCardView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(17); make.right.mas_equalTo(-17); make.top.equalTo(self.whiteBgView.mas_bottom).offset(14); make.height.mas_equalTo(ScaleWidth(100)); }]; self.giftWallBtn = [[UIButton alloc] init]; [self.giftWallBtn addTarget:self action:@selector(giftWallAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.giftWallBtn setBackgroundImage:[UIImage imageNamed:@"user_home_gift_wall"] forState:(UIControlStateNormal)]; [self addSubview:self.giftWallBtn]; [self.giftWallBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(17); make.right.mas_equalTo(-17); make.height.mas_equalTo(ScaleWidth(40)); make.top.equalTo(self.cpCardView.mas_bottom).offset(8); }]; [self.whiteBgView bringSubviewToFront:self.playBtn]; [self bringSubviewToFront:self.followBtn]; } -(void)headerStartPlay{ [self.headerView playHWDMP4]; [self.cpCardView headerStartPlay]; [self.cpDressView headerStartPlay]; } -(void)giftWallAction{ QXGiftWallViewController *vc = [[QXGiftWallViewController alloc] init]; vc.userId = self.userId; [self.viewController.navigationController pushViewController:vc animated:YES]; } -(void)followAction{ MJWeakSelf [QXDynamicNetwork followWithUserId:self.model.user_id type:@"1" successBlock:^(NSDictionary * _Nonnull dict) { weakSelf.followBtn.selected = !weakSelf.followBtn.selected; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)playAction{ if (self.model.room_id.intValue > 0) { // 去房间 [[QXGlobal shareGlobal] joinRoomWithRoomId:self.model.room_id isRejoin:NO navagationController:self.navigationController]; }else{ // 去聊天 [[QXGlobal shareGlobal] chatWithUserID:self.model.user_id nickname:self.model.nickname avatar:self.model.avatar navagationController:self.navigationController]; } } -(void)didClickHeaderViewUserId:(NSString*)userId{ if ([userId isEqualToString:self.userId]) { return; } QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init]; vc.user_id = userId; [self.viewController.navigationController pushViewController:vc animated:YES]; } -(void)didClickHeaderCardViewWithUserId:(NSString*)userId{ QXHeartBeatSpaceViewController *vc = [[QXHeartBeatSpaceViewController alloc] init]; vc.userId = userId; [self.viewController.navigationController pushViewController:vc animated:YES]; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if (collectionView == self.collectionView) { return self.model.icon.count; }else{ return self.model.tag_list.count; } } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ if (collectionView == self.collectionView) { QXTagImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXTagImageCell" forIndexPath:indexPath]; cell.imageUrl = self.model.icon[indexPath.row]; return cell; }else{ QXSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXSearchCell" forIndexPath:indexPath]; cell.cellType = QXSearchCellTypeIntroduce; cell.userTag = self.model.tag_list[indexPath.row]; return cell; } } -(void)setUserId:(NSString *)userId{ _userId = userId; self.cpCardView.userId = self.userId; } -(void)setModel:(QXUserHomeModel *)model{ _model = model; // model.nickname = @"大家好撒客户端撒大厦尽快"; // self.tempName.text = model.nickname; [self.headerView setHeadIcon:model.avatar dress:model.dress]; [self.headerView.nobilityImageView sd_setImageWithURL:[NSURL URLWithString:model.nobility_image]]; if ([model.nickname_color isExist]) { self.nameLabel.shimmerColor = [UIColor colorWithHexString:model.nickname_color]; [self.nameLabel startShimmer]; // self.tempName.shimmerColor = UIColor.redColor; // [self.tempName startShimmer]; }else{ [self.nameLabel stopShimmer]; } self.nameLabel.text = model.nickname; [self.nameLabel.contentLabel sizeToFit]; [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerView); make.height.mas_equalTo(24); make.top.equalTo(self.headerView.mas_bottom).offset(4); make.width.mas_equalTo(self.nameLabel.contentLabel.width); }]; if (model.cp_info != nil) { self.cpDressView.hidden = NO; self.cpCardView.hidden = NO; self.cpDressView.model = model.cp_info; self.cpCardView.model = model.cp_info; [self.giftWallBtn mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(17); make.right.mas_equalTo(-17); make.height.mas_equalTo(ScaleWidth(40)); make.top.equalTo(self.cpCardView.mas_bottom).offset(8); }]; }else{ self.cpDressView.hidden = YES; self.cpCardView.hidden = YES; [self.giftWallBtn mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(17); make.right.mas_equalTo(-17); make.height.mas_equalTo(ScaleWidth(40)); make.top.equalTo(self.whiteBgView.mas_bottom).offset(8); }]; } // self.tempName.text = model.nickname; // [self.tempName.contentLabel sizeToFit]; // [self.tempName mas_remakeConstraints:^(MASConstraintMaker *make) { // make.top.left.mas_equalTo(0); // make.height.mas_equalTo(24); // make.width.mas_equalTo(self.tempName.contentLabel.width); // }]; // self.tempName.text = model.nickname; // self.idLabel.text = [NSString stringWithFormat:@"ID:%@",model.user_code]; self.idLabel.text = [NSString stringWithFormat:@"%@|%ld岁 ID:%@",model.sex.intValue==1?QXText(@"男"):QXText(@"女"),[model.birthday ageWithDateOfBirth],model.user_code]; self.introduceLabel.text = model.profile; [self.inCollectionView reloadData]; [self.collectionView reloadData]; if ([model.user_id isEqualToString:[QXGlobal shareGlobal].loginModel.user_id]) { self.followBtn.hidden = YES; self.playBtn.hidden = YES; }else{ self.followBtn.hidden = NO; self.playBtn.hidden = NO; self.followBtn.selected = model.is_follow==0?NO:YES; if (model.room_id.intValue > 0) { // [self.playBtn setTitle:QXText(@"跟随") forState:(UIControlStateNormal)]; [self.playBtn setBackgroundImage:[UIImage imageNamed:@"room_user_follow"] forState:(UIControlStateNormal)]; }else{ // [self.playBtn setTitle:QXText(@"私信") forState:(UIControlStateNormal)]; [self.playBtn setBackgroundImage:[UIImage imageNamed:@"expansion_call"] forState:(UIControlStateNormal)]; } } if ([model.guild isExist]) { self.guildLabel.text = model.guild; }else{ self.guildLabel.text = @"无"; } if (model.is_use_code.intValue == 1) { self.useCodeImageView.hidden = NO; }else{ self.useCodeImageView.hidden = YES; } // UIImage *sexImage = [UIImage imageNamed:model.sex.intValue==1?@"user_sex_boy":@"user_sex_girl"]; // self.sexImageView.image = sexImage; } -(NSMutableArray *)tagArray{ if (!_tagArray) { _tagArray = [NSMutableArray array]; } return _tagArray; } @end @implementation QXTagImageCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)setImageUrl:(NSString *)imageUrl{ _imageUrl = imageUrl; if ([imageUrl hasPrefix:@"http"] || [imageUrl hasPrefix:@"https"]) { [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil]; }else{ if ([imageUrl isEqualToString:@"mine_room_cover_add"]) { self.imageView.image = [UIImage imageNamed:imageUrl]; }else{ NSString *fileUrl =[NSString stringWithFormat:@"https://%@.%@/%@",OSS_BUCKET_NAME,OSSEndPoint,imageUrl]; [self.imageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:nil]; } } } -(void)initSubviews{ self.imageView = [[UIImageView alloc] initWithFrame:self.bounds]; [self.contentView addSubview:self.imageView]; self.imageView.contentMode = UIViewContentModeScaleToFill; self.imageView.clipsToBounds = YES; // [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.bottom.left.right.equalTo(self.contentView); // }]; } @end