Files
peko-ios/YuMi/Modules/YMNewHome/View/Cell/XPNewHomePartyTableViewCell.m
2023-09-21 17:44:59 +08:00

403 lines
14 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.

//
// XPNewHomePartyTableViewCell.m
// YuMi
//
// Created by YuMi on 2022/10/8.
//
#import "XPNewHomePartyTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "NetImageView.h"
///Model
#import "HomePlayRoomModel.h"
#import "HomeRecommendRoomModel.h"
#import "XPNewHomePartyTagView.h"
#import "XPNewHomePartyAudioView.h"
@interface XPNewHomePartyTableViewCell ()<XPNewHomePartyAudioViewDelegate>
///头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///背景
@property (nonatomic,strong) UIView *bgView;
///房间标题
@property (nonatomic,strong) UILabel *titleLabel;
///点击房间标题
@property(nonatomic,strong) UIButton *nameTapBtn;
///标签
@property(nonatomic,strong) XPNewHomePartyTagView *tagView;
///小绿点
@property(nonatomic,strong) UIView *greenView;
///边框
@property (nonatomic,strong) UIImageView *borderImageView;
///游戏背景
@property(nonatomic,strong) UIImageView *gameBgView;
///游戏图标
@property(nonatomic,strong) UIImageView *gameIconView;
///声音、签名
@property(nonatomic,strong) XPNewHomePartyAudioView *audioView;
///聊天
@property(nonatomic,strong) UIButton *chatBtn;
///生日
@property(nonatomic,strong) UIButton *birthdayView;
///财富
@property(nonatomic,strong) NetImageView *wealthView;
///魅力
@property(nonatomic,strong) NetImageView *charmView;
@property(nonatomic,strong) NSDateFormatter *dateFormatter;
@end
@implementation XPNewHomePartyTableViewCell
- (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.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.bgView];
[self.bgView addSubview:self.borderImageView];
[self.bgView addSubview:self.avatarImageView];
[self.bgView addSubview:self.gameBgView];
[self.bgView addSubview:self.gameIconView];
[self.bgView addSubview:self.greenView];
[self.bgView addSubview:self.tagView];
[self.bgView addSubview:self.audioView];
[self.bgView addSubview:self.chatBtn];
[self.bgView addSubview:self.titleLabel];
[self.bgView addSubview:self.birthdayView];
[self.bgView addSubview:self.wealthView];
[self.bgView addSubview:self.charmView];
[self.bgView addSubview:self.nameTapBtn];
}
- (void)initSubViewConstraints {
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(0));
make.width.mas_equalTo(kGetScaleWidth(351));
make.height.mas_equalTo(kGetScaleWidth(96));
make.centerX.equalTo(self.contentView);
}];
[self.borderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(10));
make.width.height.mas_equalTo(kGetScaleWidth(68));
make.top.mas_equalTo(kGetScaleWidth(14));
}];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(60), kGetScaleWidth(60)));
make.center.equalTo(self.borderImageView);
}];
[self.greenView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(10));
make.leading.mas_equalTo(kGetScaleWidth(60));
make.top.mas_equalTo(kGetScaleWidth(64));
}];
[self.gameBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(48));
make.leading.mas_equalTo(kGetScaleWidth(14));
make.width.mas_equalTo(kGetScaleWidth(60));
make.height.mas_equalTo(kGetScaleWidth(30));
}];
[self.gameIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(57));
make.leading.mas_equalTo(kGetScaleWidth(26));
make.width.mas_equalTo(kGetScaleWidth(37));
make.height.mas_equalTo(kGetScaleWidth(17));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(10));
make.leading.mas_equalTo(kGetScaleWidth(84));
make.height.mas_equalTo(kGetScaleWidth(20));
}];
[self.birthdayView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(28));
make.height.mas_equalTo(kGetScaleWidth(14));
make.leading.equalTo(self.titleLabel.mas_trailing).mas_offset(kGetScaleWidth(4));
make.centerY.equalTo(self.titleLabel);
}];
[self.wealthView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(36));
make.height.mas_equalTo(kGetScaleWidth(18));
make.leading.equalTo(self.birthdayView.mas_trailing).mas_offset(kGetScaleWidth(4));
make.centerY.equalTo(self.titleLabel);
}];
[self.charmView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(36));
make.height.mas_equalTo(kGetScaleWidth(18));
make.leading.equalTo(self.wealthView.mas_trailing).mas_offset(kGetScaleWidth(4));
make.centerY.equalTo(self.titleLabel);
}];
[self.chatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(34));
make.trailing.mas_equalTo(-kGetScaleWidth(10));
make.height.mas_equalTo(kGetScaleWidth(28));
make.width.mas_equalTo(kGetScaleWidth(60));
}];
[self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(84));
make.top.mas_equalTo(kGetScaleWidth(34));
make.height.mas_equalTo(kGetScaleWidth(18));
make.trailing.equalTo(self.chatBtn.mas_leading).mas_offset(-kGetScaleWidth(5));
}];
[self.audioView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(84));
make.height.mas_equalTo(kGetScaleWidth(26));
make.top.equalTo(self.tagView.mas_bottom).mas_offset(kGetScaleWidth(6));
make.trailing.equalTo(self.tagView);
}];
[self.nameTapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.leading.equalTo(self.titleLabel);
make.trailing.equalTo(self.charmView);
}];
}
#pragma mark - Getters And Setters
- (void)setRoomInfo:(HomePlayRoomModel *)roomInfo {
_roomInfo = roomInfo;
if (_roomInfo) {
self.avatarImageView.imageUrl = _roomInfo.avatar;
NSString *nick = _roomInfo.nick;
if(nick.length > 7){
nick = [NSString stringWithFormat:@"%@...",[_roomInfo.nick substringToIndex:7]];
}
self.titleLabel.text = nick;
_tagView.itemWidthist = _roomInfo.labelsWidthList;
_tagView.itemList = [NSMutableArray arrayWithArray:_roomInfo.labels];
[_birthdayView setTitle:[NSString getAgeWithBirth:_roomInfo.birth] forState:UIControlStateNormal];
_birthdayView.backgroundColor = _roomInfo.gender == GenderType_Male ? UIColorFromRGB(0x6BB3FF) :UIColorFromRGB(0xFF80CC);
_gameBgView.hidden = YES;
_gameIconView.hidden = YES;
_borderImageView.hidden = YES;
_greenView.hidden = YES;
[_chatBtn setTitle:YMLocalizedString(@"XPSessionSayHelloTableViewCell0") forState:UIControlStateNormal];
if(_roomInfo.inMic == YES){
_gameBgView.hidden = NO;
_gameIconView.hidden = NO;
_borderImageView.hidden = NO;
[_chatBtn setTitle:YMLocalizedString(@"XPSessionFindNewAlertView2") forState:UIControlStateNormal];
}else{
if(_roomInfo.inOnline == YES){
_greenView.hidden = NO;
}
}
_wealthView.imageUrl = _roomInfo.userLevelVo.experUrl;
_charmView.imageUrl = _roomInfo.userLevelVo.charmUrl;
if(_roomInfo.userVoice.length > 0){
_audioView.voiceDura = _roomInfo.voiceDura;
_audioView.userVoice = _roomInfo.userVoice;
_audioView.isHiddenVew = NO;
}else{
if(_roomInfo.userDesc.length > 0){
_audioView.isHiddenVew = NO;
_audioView.userDesc = _roomInfo.userDesc;
}else{
_audioView.isHiddenVew = YES;
}
}
}
}
///声音卡时svga是否播放动画
-(void)setPlaySoundStatus:(BOOL)isPlay{
_audioView.isPlay = isPlay;
if(isPlay == NO){
_audioView.voiceDura = _roomInfo.voiceDura;
}
}
///声音卡倒计时
-(void)setPlaySoundTime:(NSInteger)time{
_audioView.voiceDura = @(time).stringValue;
}
- (void)setRoomInfo1:(HomeRecommendRoomModel *)roomInfo1 {
_roomInfo1 = roomInfo1;
if (_roomInfo1) {
}
}
-(void)didSelectItemAction{
if(self.delegate && [self.delegate respondsToSelector:@selector(xPNewHomePartyTableViewCell:didSelectItem:)]){
[self.delegate xPNewHomePartyTableViewCell:self didSelectItem:self.roomInfo];
}
}
-(void)didSelectChatAction{
if(self.delegate && [self.delegate respondsToSelector:@selector(xPNewHomePartyTableViewCell:didSelectChat:)]){
[self.delegate xPNewHomePartyTableViewCell:self didSelectChat:self.roomInfo];
}
}
#pragma mark - XPNewHomePartyAudioViewDelegate
- (void)xPNewHomePartyAudioView:(XPNewHomePartyAudioView *)view didClickPlaySound:(BOOL)isPlay{
if(self.delegate && [self.delegate respondsToSelector:@selector(xPNewHomePartyTableViewCell:didPlayVoice:didClickPlaySound:)]){
[self.delegate xPNewHomePartyTableViewCell:self didPlayVoice:self.roomInfo didClickPlaySound:isPlay];
}
}
- (NetImageView *)avatarImageView {
if (!_avatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
_avatarImageView.layer.masksToBounds = YES;
_avatarImageView.layer.cornerRadius = kGetScaleWidth(60)/2;
_avatarImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didSelectItemAction)];
[_avatarImageView addGestureRecognizer:tap];
}
return _avatarImageView;
}
- (UIView *)bgView {
if (!_bgView) {
_bgView = [[UIView alloc] init];
_bgView.backgroundColor = [UIColor whiteColor];
_bgView.layer.masksToBounds = YES;
_bgView.layer.cornerRadius = kGetScaleWidth(12);
}
return _bgView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = kFontMedium(14);
_titleLabel.textColor = [DJDKMIMOMColor mainTextColor];
}
return _titleLabel;
}
- (UIImageView *)borderImageView {
if (!_borderImageView) {
_borderImageView = [[UIImageView alloc] init];
_borderImageView.userInteractionEnabled = YES;
_borderImageView.layer.cornerRadius = kGetScaleWidth(68)/2;
_borderImageView.layer.masksToBounds = YES;
_borderImageView.layer.borderWidth = kGetScaleWidth(2);
_borderImageView.layer.borderColor = UIColorFromRGB(0xA974FF).CGColor;
}
return _borderImageView;
}
- (UIView *)greenView{
if(!_greenView){
_greenView = [UIView new];
_greenView.backgroundColor = UIColorFromRGB(0x3FE05F);
_greenView.layer.cornerRadius = kGetScaleWidth(10)/2;
_greenView.layer.masksToBounds = YES;
_greenView.layer.borderWidth = 1;
_greenView.layer.borderColor = [UIColor whiteColor].CGColor;
}
return _greenView;
}
- (UIImageView *)gameBgView{
if(!_gameBgView){
_gameBgView = [UIImageView new];
_gameBgView.image = kImage(@"home_palying_bg");
}
return _gameBgView;
}
- (UIImageView *)gameIconView{
if(!_gameIconView){
_gameIconView = [UIImageView new];
_gameIconView.image = kImage(@"home_palying_icon");
}
return _gameIconView;
}
- (UIButton *)chatBtn{
if(!_chatBtn){
_chatBtn = [UIButton new];
_chatBtn.backgroundColor = UIColorFromRGB(0x9168FA);
[_chatBtn setTitle:YMLocalizedString(@"XPSessionSayHelloTableViewCell0") forState:UIControlStateNormal];
_chatBtn.titleLabel.font = kFontMedium(12);
[_chatBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_chatBtn.layer.cornerRadius = kGetScaleWidth(28)/2;
_chatBtn.layer.masksToBounds = YES;
[_chatBtn addTarget:self action:@selector(didSelectChatAction) forControlEvents:UIControlEventTouchUpInside];
}
return _chatBtn;
}
- (UIButton *)birthdayView{
if(!_birthdayView){
_birthdayView = [UIButton new];
[_birthdayView setImage:kImage(@"home_age_boy_icon") forState:UIControlStateNormal];
[_birthdayView setImage:kImage(@"home_age_girl_icon") forState:UIControlStateSelected];
_birthdayView.titleLabel.font = kFontMedium(10);
[_birthdayView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_birthdayView.imageEdgeInsets = UIEdgeInsetsMake(0, -kGetScaleWidth(2), 0, 0);
_birthdayView.layer.cornerRadius = kGetScaleWidth(14)/2;
_birthdayView.layer.masksToBounds = YES;
}
return _birthdayView;
}
- (NetImageView *)wealthView{
if(!_wealthView){
_wealthView = [[NetImageView alloc]init];
}
return _wealthView;
}
- (NetImageView *)charmView{
if(!_charmView){
_charmView = [[NetImageView alloc]init];
}
return _charmView;
}
- (NSDateFormatter *)dateFormatter {
if (!_dateFormatter) {
_dateFormatter = [[NSDateFormatter alloc] init];
_dateFormatter.dateFormat = @"yyyy-MM-dd";
}
return _dateFormatter;
}
- (XPNewHomePartyTagView *)tagView{
if(!_tagView){
_tagView = [[XPNewHomePartyTagView alloc]initWithFrame:CGRectZero];
}
return _tagView;
}
- (XPNewHomePartyAudioView *)audioView{
if(!_audioView){
_audioView = [[XPNewHomePartyAudioView alloc]initWithFrame:CGRectZero];
_audioView.delegate = self;
}
return _audioView;
}
- (UIButton *)nameTapBtn{
if(!_nameTapBtn){
_nameTapBtn = [UIButton new];
[_nameTapBtn addTarget:self action:@selector(didSelectItemAction) forControlEvents:UIControlEventTouchUpInside];
}
return _nameTapBtn;
}
@end