// // SessionUserInfoTableViewCell.m // YUMI // // Created by YUMI on 2023/1/16. // #import "SessionUserInfoTableViewCell.h" ///Third #import #import #import ///Tool #import "DJDKMIMOMColor.h" #import "NetImageView.h" #import "SpriteSheetImageManager.h" #import "YUMIMacroUitls.h" #import "NSArray+Safe.h" #import "UIImage+Utils.h" #import "PLTimeUtil.h" #import "SDPhotoBrowser.h" #import "XCCurrentVCStackManager.h" #import "StatisticsServiceHelper.h" ///Model #import "UserInfoModel.h" #import "UserPhoto.h" @interface SessionUserInfoCell : UICollectionViewCell ///头像 @property (nonatomic,strong) NetImageView *avatarImageView; @end @implementation SessionUserInfoCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { self.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:self.avatarImageView]; } - (void)initSubViewConstraints { [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.contentView); }]; } #pragma mark - Getters And Setters - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig * config = [[NetImageConfig alloc]init]; config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _avatarImageView = [[NetImageView alloc] initWithConfig:config]; _avatarImageView.layer.masksToBounds = YES; _avatarImageView.layer.cornerRadius = 8; _avatarImageView.contentMode = UIViewContentModeScaleAspectFill; } return _avatarImageView; } @end @interface SessionUserInfoTableViewCell () ///背景 @property (nonatomic,strong) UIView *backView; ///容器 @property (nonatomic,strong) UIStackView *stackView; ///用户信息 @property (nonatomic,strong) UIView *userView; ///头像 @property (nonatomic,strong) NetImageView * avatarImageView; ///VIP等级icon @property (nonatomic,strong) NetImageView *nobleImageView; ///普通的 @property (nonatomic,strong) YYAnimatedImageView *headWearImageView; @property (nonatomic,strong) SVGAImageView *headWearSVGAImageView; ///头饰播放 @property (nonatomic, strong) SpriteSheetImageManager *manager; ///昵称 @property (nonatomic,strong) UILabel *nickLabel; /// @property (nonatomic,strong) UIStackView *tagStackView; ///性别 @property (nonatomic,strong) UIButton *sexButton; ///签名 @property (nonatomic,strong) UILabel *signLabel; ///列表 @property (nonatomic,strong) UICollectionView *collectionView; @end @implementation SessionUserInfoTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { self.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.backView]; [self.contentView addSubview:self.stackView]; [self.stackView addArrangedSubview:self.userView]; // [self.stackView addArrangedSubview:self.collectionView]; [self.userView addSubview:self.avatarImageView]; [self.userView addSubview:self.headWearImageView]; [self.userView addSubview:self.headWearSVGAImageView]; [self.userView addSubview:self.tagStackView]; [self.userView addSubview:self.signLabel]; [self.tagStackView addArrangedSubview:self.nickLabel]; [self.tagStackView addArrangedSubview:self.sexButton]; [self.tagStackView addArrangedSubview:self.nobleImageView]; } - (void)initSubViewConstraints { [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.mas_equalTo(self.contentView).inset(15); make.top.mas_equalTo(self.contentView).offset(10); }]; [self.backView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.mas_equalTo(self.contentView).inset(15); make.bottom.mas_equalTo(self.stackView.mas_bottom).offset(16); make.top.mas_equalTo(self.contentView).offset(10); }]; [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(56, 56)); make.leading.mas_equalTo(self.userView).offset(22); make.top.mas_equalTo(self.backView).offset(22); }]; [self.headWearImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.centerY.mas_equalTo(self.avatarImageView); make.width.mas_equalTo(self.avatarImageView.mas_width).multipliedBy(1.31); make.height.mas_equalTo(self.headWearImageView.mas_width); }]; [self.headWearSVGAImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.centerY.mas_equalTo(self.avatarImageView); make.width.mas_equalTo(self.avatarImageView.mas_width).multipliedBy(1.31); make.height.mas_equalTo(self.headWearImageView.mas_width); }]; [self.tagStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self.headWearImageView.mas_trailing).offset(0); make.width.mas_greaterThanOrEqualTo(kGetScaleWidth(100)); make.bottom.mas_equalTo(self.headWearImageView.mas_centerY).offset(-3); }]; [self.nobleImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(20); }]; [self.sexButton mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(32, 14)); }]; [self.signLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self.tagStackView); make.trailing.mas_lessThanOrEqualTo(self.userView).offset(-5); make.top.mas_equalTo(self.headWearImageView.mas_centerY).offset(3); }]; [self.userView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(76); }]; // [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { // make.height.mas_equalTo(72); // }]; } -(NSInteger) getMonth:(long )time { NSDate *date = [NSDate dateWithTimeIntervalSince1970:time/1000]; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* components = [calendar components:NSCalendarUnitMonth fromDate:date]; NSInteger month = components.month; return month; } - (NSInteger) getDay:(long) time { NSDate *date = [NSDate dateWithTimeIntervalSince1970:time/1000]; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* components = [calendar components:NSCalendarUnitDay fromDate:date]; NSInteger day = components.day; return day; } #pragma mark - UICollectionViewDelegate And UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.userInfo.privatePhoto.count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { SessionUserInfoCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SessionUserInfoCell class]) forIndexPath:indexPath]; UserPhoto * photo = [self.userInfo.privatePhoto xpSafeObjectAtIndex:indexPath.row]; cell.avatarImageView.imageUrl = photo.photoUrl; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView deselectItemAtIndexPath:indexPath animated:YES]; if (self.userInfo.privatePhoto.count > 0) { SessionUserInfoCell * cell = (SessionUserInfoCell *)[collectionView cellForItemAtIndexPath:indexPath]; SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init]; browser.sourceImagesContainerView = cell; browser.delegate = self; browser.imageCount = self.userInfo.privatePhoto.count; browser.currentImageIndex = indexPath.row; browser.isMe = NO; [browser show]; [StatisticsServiceHelper trackEventWithKey:StatisticsServiceEvent_chat_toolbar_photo_click]; } } #pragma mark - SDPhotoBrowserDelegate - (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index { UserPhoto * photo = [self.userInfo.privatePhoto xpSafeObjectAtIndex:index]; return [NSURL URLWithString:photo.photoUrl]; } - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index { return [UIImageConstant defaultBannerPlaceholder]; } #pragma mark - Event Response - (void)avatarImageViewRecognizer { [StatisticsServiceHelper trackEventWithKey:StatisticsServiceEvent_chat_frame_datacard_head_click]; if (self.delegate && [self.delegate respondsToSelector:@selector(sessionUserInfoTableViewCell:showUserInfoVC:)]) { [self.delegate sessionUserInfoTableViewCell:self showUserInfoVC:self.userInfo]; } } #pragma mark - Getters And Setters - (void)setUserInfo:(UserInfoModel *)userInfo { _userInfo = userInfo; if (_userInfo) { self.avatarImageView.imageUrl = _userInfo.avatar; NSString * nick = _userInfo.nick; if (nick.length > 8) { nick = [nick substringToIndex:8]; nick = [NSString stringWithFormat:@"%@...", nick]; } self.nickLabel.text = nick; self.signLabel.text = _userInfo.userDesc.length > 0 ? _userInfo.userDesc : YMLocalizedString(@"XPTreasureFairyFriendCell0"); self.nobleImageView.hidden = _userInfo.userVipInfoVO.nameplateUrl.length > 0 ? NO : YES; @kWeakify(self); [self.nobleImageView loadImageWithUrl:_userInfo.userVipInfoVO.nameplateUrl completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) { @kStrongify(self); if (image) { self.nobleImageView.image = image; CGFloat scale = image.size.width / image.size.height; [self.nobleImageView mas_remakeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(20* scale, 20)); }]; } else { [self.nobleImageView mas_remakeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(0, 20)); }]; } }]; NSString * headurl = userInfo.headwearEffect.length > 0 ? userInfo.headwearEffect : userInfo.headwearPic; if (headurl.length == 0) { self.headWearImageView.hidden = YES; self.headWearSVGAImageView.hidden = YES; } else { if ([userInfo isHeadWearSVGA]) { self.headWearSVGAImageView.hidden = NO; [self.headWearSVGAImageView setImageName:headurl]; } else { self.headWearImageView.hidden = NO; NSURL *url = [NSURL URLWithString:headurl]; @kWeakify(self); [self.manager loadSpriteSheetImageWithURL:url completionBlock:^(YYSpriteSheetImage * _Nullable sprit) { @kStrongify(self); self.headWearImageView.image = sprit; } failureBlock:^(NSError * _Nullable error) { }]; } } self.collectionView.hidden = _userInfo.privatePhoto.count <= 0; if (_userInfo.gender == GenderType_Male) { [self.sexButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor colorWithHexString:@"#45BBFF"], [DJDKMIMOMColor colorWithHexString:@"#8AD4FF"]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal]; [self.sexButton setImage:[UIImage imageNamed:@"session_user_sex_male"] forState:UIControlStateNormal]; } else { [self.sexButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor colorWithHexString:@"#FF497D"], [DJDKMIMOMColor colorWithHexString:@"#FF90AE"]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal]; [self.sexButton setImage:[UIImage imageNamed:@"session_user_sex_female"] forState:UIControlStateNormal]; } [self.sexButton setTitle:[NSString stringWithFormat:@"%ld", [PLTimeUtil ageWithDateFromBirth:_userInfo.birth]] forState:UIControlStateNormal]; // NSString *image = [NSString getCalculateConstellationImageWithMonth:_userInfo.birth]; // if(image.length > 0){ // self.constellationButton.image = kImage(image); // } [self.collectionView reloadData]; } } - (UIView *)backView { if (!_backView) { _backView = [[UIView alloc] init]; _backView.backgroundColor = [UIColor whiteColor]; _backView.layer.masksToBounds = YES; _backView.layer.cornerRadius = 8; } return _backView; } - (UIStackView *)stackView { if (!_stackView) { _stackView = [[UIStackView alloc] init]; _stackView.axis = UILayoutConstraintAxisVertical; _stackView.distribution = UIStackViewDistributionFill; _stackView.alignment = UIStackViewAlignmentFill; _stackView.spacing = 12; } return _stackView; } - (UIView *)userView { if (!_userView) { _userView = [[UIView alloc] init]; _userView.backgroundColor = [UIColor clearColor]; } return _userView; } - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig * config = [[NetImageConfig alloc]init]; config.imageType = ImageTypeUserIcon; config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _avatarImageView = [[NetImageView alloc] initWithConfig:config]; _avatarImageView.userInteractionEnabled = YES; _avatarImageView.layer.masksToBounds = YES; _avatarImageView.layer.cornerRadius = 56 / 2; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarImageViewRecognizer)]; [_avatarImageView addGestureRecognizer:tap]; } return _avatarImageView; } - (UIStackView *)tagStackView { if (!_tagStackView) { _tagStackView = [[UIStackView alloc] init]; _tagStackView.axis = UILayoutConstraintAxisHorizontal; _tagStackView.distribution = UIStackViewDistributionFill; _tagStackView.alignment = UIStackViewAlignmentCenter; _tagStackView.spacing = 3; } return _tagStackView; } - (YYAnimatedImageView *)headWearImageView { if (!_headWearImageView) { _headWearImageView = [[YYAnimatedImageView alloc] init]; _headWearImageView.backgroundColor = [UIColor clearColor]; _headWearImageView.contentMode = UIViewContentModeScaleAspectFit; _headWearImageView.userInteractionEnabled = NO; } return _headWearImageView; } - (SVGAImageView *)headWearSVGAImageView { if (!_headWearSVGAImageView) { _headWearSVGAImageView = [[SVGAImageView alloc]init]; _headWearSVGAImageView.backgroundColor = [UIColor clearColor]; _headWearSVGAImageView.frame = CGRectZero; _headWearSVGAImageView.userInteractionEnabled = NO; _headWearSVGAImageView.autoPlay = YES; } return _headWearSVGAImageView; } - (SpriteSheetImageManager *)manager { if (!_manager) { _manager = [[SpriteSheetImageManager alloc] init]; } return _manager; } - (UILabel *)nickLabel { if (!_nickLabel) { _nickLabel = [[UILabel alloc] init]; _nickLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold]; _nickLabel.textColor = [DJDKMIMOMColor mainTextColor]; } return _nickLabel; } - (NetImageView *)nobleImageView { if (!_nobleImageView) { _nobleImageView = [[NetImageView alloc] init]; } return _nobleImageView; } - (UILabel *)signLabel { if (!_signLabel) { _signLabel = [[UILabel alloc] init]; _signLabel.font = [UIFont systemFontOfSize:12]; _signLabel.textColor = [DJDKMIMOMColor textThirdColor]; } return _signLabel; } - (UICollectionView *)collectionView{ if (!_collectionView) { MSBaseRTLFlowLayout *layout = [[MSBaseRTLFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(00, 15, 0, 0); layout.itemSize = CGSizeMake(72, 72); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; layout.minimumLineSpacing = 8; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _collectionView.dataSource = self; _collectionView.delegate = self; _collectionView.backgroundColor = [UIColor clearColor]; [_collectionView registerClass:[SessionUserInfoCell class] forCellWithReuseIdentifier:NSStringFromClass([SessionUserInfoCell class])]; } return _collectionView; } - (UIButton *)sexButton { if (!_sexButton) { _sexButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_sexButton setTitle:@"0" forState:UIControlStateNormal]; [_sexButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _sexButton.titleLabel.font = [UIFont systemFontOfSize:10]; [_sexButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 3, 0, 0)]; _sexButton.layer.masksToBounds = YES; _sexButton.layer.cornerRadius = 7; } return _sexButton; } @end