// // EventCenterEventCell.m // YuMi // // Created by P on 2025/4/29. // #import "EventCenterEventCell.h" #import "EventItemModel.h" @interface EventCenterEventCell() @property (nonatomic, strong) EventItemModel *model; @property (nonatomic, strong) NetImageView *bgImageView; @property (nonatomic, strong) NetImageView *avatarImageView; @property (nonatomic, strong) UILabel *nameLabel; @property (nonatomic, strong) UILabel *idLabel; @property (nonatomic, strong) UILabel *eventDescLabel; @property (nonatomic, strong) UILabel *timeLabel; @property (nonatomic, strong) UILabel *subLabel; @property (nonatomic, strong) UIImageView *sexImageView; @property (nonatomic, strong) UIImageView *clockImageView; @property (nonatomic, strong) UIImageView *ringImageView; @property (nonatomic, strong) UIButton *statusButton; @property (nonatomic, strong) UIButton *deleteButton; @property (nonatomic, assign) EventCellActions action; @end @implementation EventCenterEventCell + (CGFloat)cellHeight { return 130; } + (void)registerTo:(UITableView *)tableView { [tableView registerClass:[self class] forCellReuseIdentifier:NSStringFromClass([self class])]; } + (EventCenterEventCell *)cellFor:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath { return [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([self class]) forIndexPath:indexPath]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.separatorInset = UIEdgeInsetsZero; self.backgroundColor = [UIColor whiteColor]; self.contentView.backgroundColor = [UIColor whiteColor]; [self.contentView addSubview:self.bgImageView]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.contentView).inset(12); make.leading.trailing.mas_equalTo(self.contentView).inset(15); make.height.mas_equalTo(118); }]; UIView *mask_1 = [self blackMask]; [self.bgImageView addSubview:mask_1]; [mask_1 mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.bgImageView); }]; [self.contentView addSubview:self.avatarImageView]; [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.leading.mas_equalTo(self.bgImageView).offset(12); make.size.mas_equalTo(CGSizeMake(35, 35)); }]; [self.contentView addSubview:self.nameLabel]; [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.avatarImageView).offset(1); make.leading.mas_equalTo(self.avatarImageView.mas_trailing).offset(6); }]; [self.contentView addSubview:self.sexImageView]; [self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.nameLabel); make.leading.mas_equalTo(self.nameLabel.mas_trailing).offset(2); make.size.mas_equalTo(CGSizeMake(14, 14)); }]; [self.contentView addSubview:self.idLabel]; [self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(self.avatarImageView).offset(1); make.leading.mas_equalTo(self.nameLabel); }]; [self.contentView addSubview:self.eventDescLabel]; [self.eventDescLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.mas_equalTo(self.bgImageView).inset(12); make.top.mas_equalTo(self.avatarImageView.mas_bottom).offset(12); }]; UIView *mask_2 = [self blackMask]; [self.bgImageView addSubview:mask_2]; [mask_2 mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.leading.trailing.mas_equalTo(self.bgImageView); make.height.mas_equalTo(32); }]; [self.contentView addSubview:self.clockImageView]; [self.clockImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(mask_2); make.leading.mas_equalTo(mask_2).offset(13); make.size.mas_equalTo(CGSizeMake(14, 14)); }]; [self.contentView addSubview:self.timeLabel]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self.clockImageView.mas_trailing).offset(1); make.centerY.mas_equalTo(mask_2); }]; [self.contentView addSubview:self.subLabel]; [self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.trailing.mas_equalTo(mask_2).offset(-13); make.centerY.mas_equalTo(mask_2); }]; [self.contentView addSubview:self.ringImageView]; [self.ringImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(mask_2); make.trailing.mas_equalTo(self.subLabel.mas_leading).offset(-1); make.size.mas_equalTo(CGSizeMake(14, 14)); }]; [self.contentView addSubview:self.statusButton]; [self.statusButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.avatarImageView); make.trailing.mas_equalTo(self.bgImageView).offset(-13); make.height.mas_equalTo(26); make.width.mas_greaterThanOrEqualTo(40); }]; [self.contentView addSubview:self.deleteButton]; [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.avatarImageView); make.trailing.mas_equalTo(self.bgImageView).offset(-13); make.height.mas_equalTo(26); make.width.mas_equalTo(38); }]; } return self; } - (void)updateCell:(EventItemModel *)model { _model = model; self.bgImageView.imageUrl = model.eventBanner; self.avatarImageView.imageUrl = model.roomAvatar; self.nameLabel.text = model.nick; self.idLabel.text = [NSString stringWithFormat:@"ID:%@", @(model.roomErbanNo)]; self.eventDescLabel.text = model.eventTopic; self.subLabel.text = @(model.subNum).stringValue; self.sexImageView.image = model.gender == 1 ? kImage(@"common_male") : kImage(@"common_female"); [self updateTimeLabel]; [self updateStatusButton]; } - (void)updateTimeLabel { BOOL needUpdateStatus = YES; if (self.model.uid == [AccountInfoStorage instance].getUid.integerValue) { switch (self.model.eventStatus) { case 0: needUpdateStatus = NO; self.timeLabel.text = YMLocalizedString(@"20.20.59_text_30"); break; case 2: needUpdateStatus = NO; self.timeLabel.text = YMLocalizedString(@"20.20.59_text_31"); break; case 4: needUpdateStatus = NO; self.timeLabel.text = YMLocalizedString(@"20.20.59_text_25"); break; default: break; } } if (needUpdateStatus) { switch (self.model.liveStatus) { case 1: self.timeLabel.text = [NSString stringWithFormat:@"%@:%@", YMLocalizedString(@"20.20.59_text_15"), self.model.eventStartTimeStr]; break; case 2: self.timeLabel.text = YMLocalizedString(@"20.20.59_text_24"); break; case 3: self.timeLabel.text = YMLocalizedString(@"20.20.59_text_25"); break; default: break; } } } - (void)updateStatusButton { BOOL needUpdateStatus = YES; if (self.model.uid == [AccountInfoStorage instance].getUid.integerValue) { switch (self.model.eventStatus) { case 0: case 2: case 4: needUpdateStatus = NO; self.statusButton.hidden = YES; self.deleteButton.hidden = NO; // [self statusButtonUpdateToDelete]; break; default: break; } } if (needUpdateStatus) { self.statusButton.hidden = NO; self.deleteButton.hidden = YES; switch (self.model.liveStatus) { case 1: if (self.model.subStatus) { [self statusButtonUpdateToUnSub]; } else { [self statusButtonUpdateToSub]; } break; case 2: [self statusButtonUpdateToPatricipate]; break; case 3: if (self.model.subStatus) { [self statusButtonUpdateToUnSub]; } else { [self statusButtonUpdateToSub]; } break; default: break; } } } - (void)statusButtonUpdateToSub { self.action = EventCellAction_sub; [self.statusButton setImage:kImage(@"event_ring_sub") forState:UIControlStateNormal]; [self.statusButton setTitle:YMLocalizedString(@"20.20.59_text_5") forState:UIControlStateNormal]; // 恢复默认insets [self resetStatusButtonInsets]; } - (void)statusButtonUpdateToUnSub { self.action = EventCellAction_unsub; [self.statusButton setImage:kImage(@"event_ring_unsub") forState:UIControlStateNormal]; [self.statusButton setTitle:YMLocalizedString(@"20.20.59_text_6") forState:UIControlStateNormal]; // 恢复默认insets [self resetStatusButtonInsets]; } - (void)statusButtonUpdateToPatricipate { self.action = EventCellAction_participate; [self.statusButton setImage:kImage(@"room_icon") forState:UIControlStateNormal]; [self.statusButton setTitle:YMLocalizedString(@"20.20.59_text_7") forState:UIControlStateNormal]; // 恢复默认insets [self resetStatusButtonInsets]; } - (void)statusButtonUpdateToDelete { self.action = EventCellAction_delete; [self.statusButton setImage:kImage(@"event_delete") forState:UIControlStateNormal]; [self.statusButton setTitle:@"" forState:UIControlStateNormal]; // 重置insets,解决图片压缩问题 self.statusButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0); self.statusButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0); self.statusButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0); } // 添加重置按钮内边距的方法 - (void)resetStatusButtonInsets { CGFloat imageTitleSpacing = 4.0; self.statusButton.contentEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 8); self.statusButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, imageTitleSpacing); self.statusButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageTitleSpacing, 0, 0); } - (void)didTapStatusButton { if (self.statusButtonDidTap) { self.statusButtonDidTap(self.model, self.action); } } - (void)didTapDeleteButton { if (self.statusButtonDidTap) { TTAlertConfig *config = [[TTAlertConfig alloc]init]; config.actionStyle = TTAlertActionBothStyle; config.title = YMLocalizedString(@"20.20.59_text_28.1"); config.message = YMLocalizedString(@"20.20.59_text_28.2"); TTAlertButtonConfig *buttonConfig = config.confirmButtonConfig; buttonConfig.title = YMLocalizedString(@"XPMineCollectRoomListViewController7"); config.confirmButtonConfig = buttonConfig; @kWeakify(self); [TTPopup alertWithConfig:config showBorder:NO confirmHandler:^{ @kStrongify(self); self.statusButtonDidTap(self.model, EventCellAction_delete); } cancelHandler:^{ }]; } } #pragma mark - - (NetImageView *)bgImageView { if (!_bgImageView) { NetImageConfig *config = [[NetImageConfig alloc] init]; config.placeHolder = [UIImageConstant defaultBannerPlaceholder]; _bgImageView = [[NetImageView alloc] initWithConfig:config]; [_bgImageView setCornerRadius:12]; } return _bgImageView; } - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig *config = [[NetImageConfig alloc] init]; config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _avatarImageView = [[NetImageView alloc] initWithConfig:config]; [_avatarImageView setCornerRadius:35/2 corners:kCALayerMaxXMaxYCorner | kCALayerMaxXMinYCorner | kCALayerMinXMaxYCorner | kCALayerMinXMinYCorner borderWidth:1 borderColor:[UIColor whiteColor]]; } return _avatarImageView; } - (UILabel *)nameLabel { if (!_nameLabel) { _nameLabel = [UILabel labelInitWithText:@"" font:kFontRegular(14) textColor:[UIColor whiteColor]]; } return _nameLabel; } - (UILabel *)idLabel { if (!_idLabel) { _idLabel = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:[UIColor colorWithWhite:1 alpha:0.6]]; } return _idLabel; } - (UILabel *)eventDescLabel { if (!_eventDescLabel) { _eventDescLabel = [UILabel labelInitWithText:@"" font:kFontMedium(14) textColor:[UIColor colorWithWhite:1 alpha:1]]; _eventDescLabel.numberOfLines = 0; } return _eventDescLabel; } - (UILabel *)timeLabel { if (!_timeLabel) { _timeLabel = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:[UIColor colorWithWhite:1 alpha:0.6]]; } return _timeLabel; } - (UILabel *)subLabel { if (!_subLabel) { _subLabel = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:[UIColor colorWithWhite:1 alpha:0.6]]; } return _subLabel; } - (UIImageView *)sexImageView { if (!_sexImageView) { _sexImageView = [UIImageView new]; } return _sexImageView; } - (UIImageView *)clockImageView { if (!_clockImageView) { _clockImageView = [[UIImageView alloc] initWithImage:kImage(@"event_clock")]; } return _clockImageView; } - (UIImageView *)ringImageView { if (!_ringImageView) { _ringImageView = [[UIImageView alloc] initWithImage:kImage(@"event_ring")]; } return _ringImageView; } - (UIView *)blackMask { UIView *v = [[UIView alloc] init]; v.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; return v; } - (UIButton *)statusButton { if (!_statusButton) { _statusButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_statusButton addTarget:self action:@selector(didTapStatusButton) forControlEvents:UIControlEventTouchUpInside]; [_statusButton setCornerRadius:13]; [_statusButton setBackgroundColor:[UIColor whiteColor]]; [_statusButton.titleLabel setFont:kFontMedium(13)]; [_statusButton setTitleColor:UIColorFromRGB(0x313131) forState:UIControlStateNormal]; } return _statusButton; } - (UIButton *)deleteButton { if (!_deleteButton) { _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_deleteButton addTarget:self action:@selector(didTapDeleteButton) forControlEvents:UIControlEventTouchUpInside]; [_deleteButton setCornerRadius:13]; [_deleteButton setBackgroundColor:UIColorFromRGB(0xffe5e5)]; [_deleteButton setImage:kImage(@"event_delete") forState:UIControlStateNormal]; } return _deleteButton; } @end