// // XPFindNewFriendTableViewCell.m // xplan-ios // // Created by XY on 2023/3/3. // #import "XPFindNewFriendTableViewCell.h" /// Third #import #import #import /// Tool #import "NetImageView.h" #import "ThemeColor.h" #import "XPButton.h" /// Model #import "UserInfoModel.h" @interface XPFindNewFriendTableViewCell() /// 背景 @property (nonatomic, strong) UIView *bgView; /// 头像 @property (nonatomic, strong) NetImageView *avatarImageView; /// 在线状态 @property (nonatomic, strong) UIImageView *onlineImageView; @property (nonatomic, strong) UIStackView *nameStackView; /// 贵族图标 @property (nonatomic, strong) NetImageView *nobleImageView; /// 昵称 @property (nonatomic, strong) UILabel *nickLabel; @property (nonatomic, strong) UIStackView *constellationStackView; /// 性别年龄 @property (nonatomic, strong) UIButton *sexBtn; /// 星座 @property (nonatomic, strong) UILabel *constellationLabel; /// 签名 @property (nonatomic, strong) UILabel *signLabel; /// 直播中/和Ta聊 @property (nonatomic, strong) SVGAPlayer *livingView; @property (nonatomic, strong) UIImageView *chatImageView; @property (nonatomic, strong) UILabel *statusLabel; @property (nonatomic, strong) UIStackView *statusStackView; @end @implementation XPFindNewFriendTableViewCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = UIColor.clearColor; self.contentView.backgroundColor = UIColor.clearColor; self.selectionStyle = UITableViewCellSelectionStyleNone; [self initSubViews]; [self initSubViewConstraints]; SVGAParser *parser = [[SVGAParser alloc] init]; [parser parseWithNamed:@"home_living" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { if (videoItem != nil) { self.livingView.videoItem = videoItem; [self.livingView startAnimation]; } } failureBlock:nil]; } return self; } #pragma mark - Private Method - (void)initSubViews { [self.contentView addSubview:self.bgView]; [self.bgView addSubview:self.avatarImageView]; [self.bgView addSubview:self.onlineImageView]; [self.bgView addSubview:self.nameStackView]; [self.bgView addSubview:self.constellationStackView]; [self.bgView addSubview:self.signLabel]; [self.bgView addSubview:self.livingView]; [self.bgView addSubview:self.chatImageView]; [self.bgView addSubview:self.statusLabel]; [self.nameStackView addArrangedSubview:self.nobleImageView]; [self.nameStackView addArrangedSubview:self.nickLabel]; [self.constellationStackView addArrangedSubview:self.sexBtn]; [self.constellationStackView addArrangedSubview:self.constellationLabel]; } - (void)initSubViewConstraints { [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(25); make.right.mas_equalTo(-15); make.top.mas_equalTo(6); make.bottom.mas_equalTo(-6); }]; [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(-10); make.centerY.mas_equalTo(self.bgView); make.size.mas_equalTo(CGSizeMake(72, 72)); }]; [self.onlineImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.avatarImageView.mas_right).offset(-4); make.bottom.mas_equalTo(self.avatarImageView.mas_bottom).offset(-7); make.size.mas_equalTo(CGSizeMake(12, 12)); }]; [self.nameStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.avatarImageView.mas_right).offset(12); make.top.mas_equalTo(self.avatarImageView.mas_top).offset(4); make.height.mas_equalTo(21); }]; [self.nobleImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(self.nobleImageView.mas_height); }]; [self.constellationStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.avatarImageView); make.left.mas_equalTo(self.nameStackView); }]; [self.sexBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(15); }]; [self.signLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.nameStackView); make.bottom.mas_equalTo(self.avatarImageView.mas_bottom).offset(-4); make.right.mas_equalTo(self.livingView.mas_left).offset(-10); }]; [self.livingView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-15); make.centerY.mas_equalTo(self.bgView).mas_offset(-8); make.size.mas_equalTo(CGSizeMake(20, 20)); }]; [self.chatImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.livingView); }]; [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.livingView.mas_bottom).offset(2); make.centerX.mas_equalTo(self.livingView); }]; } #pragma mark - 计算星座 -(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; } - (NSString *)calculateConstellationWithMonth:(long)time { NSString *astroString = @"魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯"; NSString *astroFormat = @"102123444543"; NSString *result; NSInteger month = [self getMonth:time]; NSInteger day = [self getDay:time]; if (month<1 || month>12 || day<1 || day>31){ return @"错误日期格式!"; } if(month==2 && day>29) { return @"错误日期格式!!"; }else if(month==4 || month==6 || month==9 || month==11) { if (day>30) { return @"错误日期格式!!!"; } } result=[NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(month*2-(day < [[astroFormat substringWithRange:NSMakeRange((month-1), 1)] intValue] - (-19))*2,2)]]; return [NSString stringWithFormat:@"%@座",result]; } - (NSString *)calculateAge:(long)time { NSDate *date = [NSDate dateWithTimeIntervalSince1970:time/1000]; NSCalendar *birthCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierISO8601]; NSDateComponents *birthCompomemts = [birthCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekday | NSCalendarUnitDay fromDate:date]; NSInteger year = birthCompomemts.year; NSInteger month = birthCompomemts.month; NSInteger day = birthCompomemts.day; NSLog(@"出生于%ld年%ld月%ld日", year, month, day); NSDate *nowDate = [NSDate date]; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierISO8601]; NSDateComponents *compomemts = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekday | NSCalendarUnitDay fromDate:nowDate]; NSInteger nowYear = compomemts.year; NSInteger nowMonth = compomemts.month; NSInteger nowDay = compomemts.day; NSLog(@"今天是%ld年%ld月%ld日", nowYear, nowMonth, nowDay); // 计算年龄 NSInteger userAge = nowYear - year - 1; if ((nowMonth > month) || (nowMonth == month && nowDay >= day)) { userAge++; } NSLog(@"用户年龄是%ld",userAge); return [NSString stringWithFormat:@"%ld", userAge]; } #pragma mark - Getters And Setters - (void)setRoomInfo:(UserInfoModel *)roomInfo { self.nickLabel.text = roomInfo.nick; if (roomInfo.gender == GenderType_Female) { [self.sexBtn setImage:[UIImage imageNamed:@"home_sex_female"] forState:UIControlStateNormal]; self.sexBtn.backgroundColor = [ThemeColor colorWithHexString:@"#FF9CCE"]; }else{ [self.sexBtn setImage: [UIImage imageNamed:@"home_sex_man"] forState:UIControlStateNormal]; self.sexBtn.backgroundColor = [ThemeColor colorWithHexString:@"#65D3F7"]; } if (roomInfo.birth) { self.constellationLabel.text = [self calculateConstellationWithMonth:roomInfo.birth]; [self.sexBtn setTitle:[self calculateAge:roomInfo.birth] forState:UIControlStateNormal]; }else{ self.constellationLabel.text = @""; [self.sexBtn setTitle:@"0" forState:UIControlStateNormal]; } self.signLabel.text = roomInfo.userDesc; if (roomInfo.roomUid.length <= 0) { self.livingView.hidden = YES; self.statusLabel.text = @"和TA聊"; self.chatImageView.hidden = NO; }else{ self.livingView.hidden = NO; self.statusLabel.text = @"直播中"; self.chatImageView.hidden = YES; } if (roomInfo.userVipInfoVO) { self.nobleImageView.hidden = NO; self.nobleImageView.imageUrl = roomInfo.userVipInfoVO.vipIcon; if (roomInfo.userVipInfoVO.friendNickColour) { self.nickLabel.textColor = [ThemeColor colorWithHexString:roomInfo.userVipInfoVO.friendNickColour]; }else{ self.nickLabel.textColor = [ThemeColor mainTextColor]; } } else { self.nobleImageView.hidden = YES; self.nickLabel.textColor = [ThemeColor mainTextColor]; } } - (UIView *)bgView { if (!_bgView) { _bgView = [[UIView alloc] init]; _bgView.backgroundColor = [ThemeColor appCellBackgroundColor]; _bgView.layer.cornerRadius = 10; } return _bgView; } - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig * config = [[NetImageConfig alloc] init]; config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; config.imageType = ImageTypeUserIcon; _avatarImageView = [[NetImageView alloc] initWithConfig:config]; _avatarImageView.userInteractionEnabled = YES; _avatarImageView.layer.masksToBounds = YES; _avatarImageView.layer.cornerRadius = 36; _avatarImageView.contentMode = UIViewContentModeScaleAspectFill; // UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapAvatarGuest)]; // [_avatarImageView addGestureRecognizer:tap]; } return _avatarImageView; } - (UIImageView *)onlineImageView { if (!_onlineImageView) { _onlineImageView = [[UIImageView alloc] init]; _onlineImageView.backgroundColor = [ThemeColor colorWithHexString:@"#6CE19A"]; _onlineImageView.layer.cornerRadius = 6; _onlineImageView.layer.borderWidth = 2; _onlineImageView.layer.borderColor = UIColor.whiteColor.CGColor; _onlineImageView.clipsToBounds = YES; } return _onlineImageView; } - (UIStackView *)nameStackView { if (!_nameStackView) { _nameStackView = [[UIStackView alloc] init]; _nameStackView.axis = UILayoutConstraintAxisHorizontal; _nameStackView.distribution = UIStackViewDistributionFill; _nameStackView.alignment = UIStackViewAlignmentFill; _nameStackView.spacing = 3; } return _nameStackView; } - (NetImageView *)nobleImageView { if (!_nobleImageView) { _nobleImageView = [[NetImageView alloc] init]; _nobleImageView.contentMode = UIViewContentModeScaleAspectFit; } return _nobleImageView; } - (UILabel *)nickLabel { if (!_nickLabel) { _nickLabel = [[UILabel alloc] init]; _nickLabel.textColor = [ThemeColor mainTextColor]; _nickLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium]; } return _nickLabel; } - (UIStackView *)constellationStackView { if (!_constellationStackView) { _constellationStackView = [[UIStackView alloc] init]; _constellationStackView.axis = UILayoutConstraintAxisHorizontal; _constellationStackView.distribution = UIStackViewDistributionFill; _constellationStackView.alignment = UIStackViewAlignmentFill; _constellationStackView.spacing = 9; } return _constellationStackView; } - (UIButton *)sexBtn { if (!_sexBtn) { _sexBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _sexBtn.titleLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular]; _sexBtn.layer.cornerRadius = 7.5; _sexBtn.clipsToBounds = YES; _sexBtn.userInteractionEnabled = NO; _sexBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 4); // _sexBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0); } return _sexBtn; } - (UILabel *)constellationLabel { if (!_constellationLabel) { _constellationLabel = [[UILabel alloc] init]; _constellationLabel.textColor = [ThemeColor textThirdColor]; _constellationLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular]; } return _constellationLabel; } - (UILabel *)signLabel { if (!_signLabel) { _signLabel = [[UILabel alloc] init]; _signLabel.textColor = [ThemeColor textThirdColor]; _signLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular]; } return _signLabel; } - (SVGAPlayer *)livingView { if (!_livingView) { _livingView = [[SVGAPlayer alloc] init]; _livingView.hidden = YES; } return _livingView; } - (UIImageView *)chatImageView { if (!_chatImageView) { _chatImageView = [[UIImageView alloc] init]; _chatImageView.contentMode = UIViewContentModeScaleAspectFit; _chatImageView.image = [UIImage imageNamed:@"home_chat"]; _chatImageView.hidden = YES; } return _chatImageView; } - (UILabel *)statusLabel { if (!_statusLabel) { _statusLabel = [[UILabel alloc] init]; _statusLabel.textColor = [ThemeColor textThirdColor]; _statusLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular]; } return _statusLabel; } - (UIStackView *)statusStackView { if (!_statusStackView) { _statusStackView = [[UIStackView alloc] init]; _statusStackView.axis = UILayoutConstraintAxisVertical; _statusStackView.distribution = UIStackViewDistributionFill; _statusStackView.alignment = UIStackViewAlignmentFill; _statusStackView.spacing = 5; } return _statusStackView; } @end