Files
yinmeng-ios/xplan-ios/Main/Home/View/XPFindNewFriendTableViewCell.m
2023-08-31 17:50:20 +08:00

538 lines
19 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// XPFindNewFriendTableViewCell.m
// xplan-ios
//
// Created by XY on 2023/3/3.
//
#import "XPFindNewFriendTableViewCell.h"
/// Third
#import <Masonry.h>
#import <SVGAParser.h>
#import <SVGAPlayer.h>
/// 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) XPButton *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;
///陪玩标签
@property(nonatomic,strong) UIImageView *gameIconView;
///陪玩背景
@property(nonatomic,strong) UIView *gameBgView;
///陪玩类型
@property(nonatomic,strong) UILabel *gameView;
///陪玩类型图标
@property(nonatomic,strong) NetImageView *gameImageView;
@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.gameIconView];
[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.bgView addSubview:self.gameBgView];
[self.gameBgView addSubview:self.gameImageView];
[self.gameBgView addSubview:self.gameView];
[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(22);
make.right.mas_equalTo(-14);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(-10);
}];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(-8);
make.centerY.mas_equalTo(self.bgView);
make.size.mas_equalTo(CGSizeMake(64, 64));
}];
[self.gameIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(48);
make.height.mas_equalTo(16);
make.centerX.equalTo(self.avatarImageView);
make.centerY.equalTo(self.avatarImageView.mas_bottom);
}];
[self.onlineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.avatarImageView.mas_right).offset(-6);
make.top.mas_equalTo(self.avatarImageView.mas_top).offset(2);
make.size.mas_equalTo(CGSizeMake(11, 11));
}];
[self.gameBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-10);
make.top.mas_equalTo(self.avatarImageView.mas_top).offset(5);
make.height.mas_equalTo(20);
make.width.mas_greaterThanOrEqualTo(kGetScaleWidth(100));
}];
[self.gameView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-8);
make.left.mas_equalTo(26);
make.centerY.equalTo(self.gameBgView);
}];
[self.gameImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(14);
make.centerY.equalTo(self.gameBgView);
make.left.mas_equalTo(10);
}];
[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.right.mas_lessThanOrEqualTo(self.gameBgView.mas_left).offset(-2);
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).mas_offset(5);
make.left.mas_equalTo(self.nameStackView);
}];
[self.sexBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(15);
make.width.mas_greaterThanOrEqualTo(32);
}];
[self.constellationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(15);
make.width.mas_greaterThanOrEqualTo(38);
}];
[self.signLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.nameStackView);
make.top.equalTo(self.constellationStackView.mas_bottom).mas_offset(10);
make.right.mas_equalTo(self.livingView.mas_left).offset(-10);
}];
[self.livingView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-15);
make.top.equalTo(self.gameBgView.mas_bottom).mas_offset(12);
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);
}];
}
- (void)didTapAvatarGuest {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPFindNewFriendTableViewCellClickAvatar:)]) {
[self.delegate xPFindNewFriendTableViewCellClickAvatar:self.roomInfo];
}
}
#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 {
_roomInfo = roomInfo;
self.avatarImageView.imageUrl = roomInfo.avatar;
NSString *nick = roomInfo.nick;
if(nick.length > 7){
nick = [NSString stringWithFormat:@"%@...",[nick substringToIndex:7]];
}
self.nickLabel.text = 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) {
roomInfo.birth = -28800000; //默认的1970/01/01
}
self.constellationLabel.text = [self calculateConstellationWithMonth:roomInfo.birth];
[self.sexBtn setTitle:[self calculateAge:roomInfo.birth] forState:UIControlStateNormal];
self.signLabel.text = roomInfo.userDesc;
if (roomInfo.inRoomUid.length == 0) {
self.livingView.hidden = YES;
self.statusLabel.text = @"和TA聊";
self.chatImageView.hidden = NO;
self.onlineImageView.hidden = YES;
}else{
self.livingView.hidden = NO;
self.statusLabel.text = @"直播中";
self.chatImageView.hidden = YES;
self.onlineImageView.hidden = NO;
}
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];
}
_gameIconView.hidden = YES;
_gameBgView.hidden = YES;
if(_roomInfo.userGamePartnerVo){
_gameIconView.hidden = NO;
_gameBgView.hidden = NO;
_gameImageView.imageUrl = _roomInfo.userGamePartnerVo.firstLogo;
NSString *gameName = @"";
if(_roomInfo.userGamePartnerVo.firstGameName.length > 0 && _roomInfo.userGamePartnerVo.secondGameName.length > 0){
gameName = [NSString stringWithFormat:@"%@%@",_roomInfo.userGamePartnerVo.firstGameName,_roomInfo.userGamePartnerVo.secondGameName];
}else if(_roomInfo.userGamePartnerVo.firstGameName.length > 0){
gameName = _roomInfo.userGamePartnerVo.firstGameName;
}else if(_roomInfo.userGamePartnerVo.secondGameName.length > 0){
gameName = _roomInfo.userGamePartnerVo.secondGameName;
}
_gameView.text = gameName;
}
}
- (UIView *)bgView {
if (!_bgView) {
_bgView = [[UIView alloc] init];
_bgView.backgroundColor = [ThemeColor appCellBackgroundColor];
_bgView.layer.cornerRadius = 15;
}
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 = 32;
_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 = 5.5;
_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;
}
- (XPButton *)sexBtn {
if (!_sexBtn) {
_sexBtn = [XPButton 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.imageTitleSpace = 2;
// _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];
_constellationLabel.backgroundColor = [ThemeColor colorWithHexString:@"#F6F7F9"];
_constellationLabel.layer.cornerRadius = 7.5;
_constellationLabel.clipsToBounds = YES;
_constellationLabel.textAlignment = NSTextAlignmentCenter;
}
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;
}
-(UIImageView *)gameIconView{
if(!_gameIconView){
_gameIconView = [UIImageView new];
_gameIconView.image = kImage(@"home_gamge_icon");
_gameIconView.hidden = YES;
}
return _gameIconView;
}
- (UIView *)gameBgView{
if(!_gameBgView){
_gameBgView = [UIView new];
_gameBgView.backgroundColor = UIColorFromRGB(0xF8F8FA);
_gameBgView.layer.cornerRadius = kGetScaleWidth(10);
_gameBgView.layer.masksToBounds = YES;
_gameBgView.hidden = YES;
}
return _gameBgView;
}
- (UILabel *)gameView{
if(!_gameView){
_gameView = [UILabel new];
_gameView.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular];
_gameView.text = @"";
_gameView.textColor = UIColorFromRGB(0x696D7A);
}
return _gameView;
}
- (NetImageView *)gameImageView{
if(!_gameImageView){
NetImageConfig *config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
_gameImageView = [[NetImageView alloc]initWithConfig:config];
_gameImageView.layer.cornerRadius = 7;
_gameImageView.layer.masksToBounds = YES;
}
return _gameImageView;
}
@end