| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- //
- // MOLiveCell.m
- // MiMoLive
- //
- // Created by SuperC on 2023/10/18.
- //
- #define TitleFont 10.0
- #define ImageViewWidthAndHeight 15.0
- #define ImageViewX 10.0
- #import "MOLiveCell.h"
- #import "MOLiveBadge.h"
- #import "UIView+Extension.h"
- #import "UILabel+MOBezierAnimation.h"
- #import "MOLiveTagArrayView.h"
- @implementation MOStatusButton
- - (void)layoutSubviews{
- [super layoutSubviews];
-
- if(self.imageView.image != nil)
- {
- self.imageView.width = ImageViewWidthAndHeight;
- self.imageView.height = ImageViewWidthAndHeight;
- self.imageView.x = ImageViewX;
- self.imageView.y = 2.0;
- UIFont *customFont = [UIFont fontWithName:kNormalContentFontStr size:10.0];
- if(!customFont){
- customFont = [MOTextTools MODisplayFontWithSize:10.0 bold:YES itatic:YES weight:UIFontWeightMedium];
- }
-
- CGFloat width = [MOTools getWidthWithString:self.titleLabel.text font:customFont] + 2.0;
- CGFloat maxWidth = SCREENWIDTH - 15.0 * 2 - 30.0 - 100.0;
- if(width > maxWidth){
- width = maxWidth;
- }
-
- self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.imageView.frame) + 2, 0, width, (TitleFont + 2.0));
- self.titleLabel.centerY = self.imageView.centerY;
- self.titleLabel.textAlignment = NSTextAlignmentCenter;
- }
- }
- @end
- @interface MOLiveCell ()
- @property (nonatomic, strong) UIButton *multiButton;//多人直播标记
- @property (nonatomic, strong) UIButton *pkButton;//pk标记
- @property (nonatomic, strong) MOLiveTagArrayView *tagArrayView;
- @end
- @implementation MOLiveCell
- - (instancetype)initWithFrame:(CGRect)frame
- {
- if (self = [super initWithFrame:frame])
- {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI
- {
- [self.contentView addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView);
- }];
-
- self.bgView.layer.cornerRadius = 16.0;
- self.bgView.layer.masksToBounds = YES;
-
- [self.bgView addSubview:self.bgImgView];
- [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.bgView);
- }];
-
-
- [self.bgView addSubview:self.statusBtn];
- [self.statusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(8.0);
- make.left.equalTo(self.bgView).offset(8.0);
- make.width.equalTo(@50.0);
- make.height.equalTo(@19.0);
- }];
- self.statusBtn.layer.cornerRadius = 4.0;
- self.statusBtn.layer.masksToBounds = YES;
-
- [self.bgView addSubview:self.multiButton];
- [self.multiButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(30.0);
- make.left.equalTo(self.bgView).offset(8.0);
- make.width.equalTo(@75.0);
- make.height.equalTo(@18.0);
- }];
- self.multiButton.hidden = YES;
-
- [self.bgView addSubview:self.pkButton];
- [self.pkButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(30.0);
- make.left.equalTo(self.bgView).offset(8.0);
- make.width.equalTo(@38.0);
- make.height.equalTo(@18.0);
- }];
- self.pkButton.hidden = YES;
-
- [self.bgView addSubview:self.tagArrayView];
- [self.tagArrayView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(8);
- make.right.mas_equalTo(-8);
- make.height.mas_equalTo(18);
- }];
-
- CGFloat collectionWidth = (SCREENWIDTH - 13.0 * 2 - 7.0) / 2.0;
- [self.bgView addSubview:self.shadowView];
- [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.bgView);
- make.height.equalTo(@60.0);
- }];
- NSArray *colorArr = @[[MOTools colorWithHexString:@"#0000000" alpha:0.0],[MOTools colorWithHexString:@"#000000" alpha:0.5]];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, collectionWidth, 60.0) Colors:colorArr GradientType:1];
- [self.shadowView setImage:image];
-
- [self.bgView addSubview:self.moreBtn];
- [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.bgView).offset(-3.0);
- make.width.height.equalTo(@20.0);
- make.bottom.equalTo(self.bgView).offset(-7.0);
- }];
-
- [self.bgView addSubview:self.countryImgView];
- [self.countryImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgView).offset(8.0);
- make.bottom.equalTo(self.bgView).offset(-10.0);
- make.width.equalTo(@16.0);
- make.height.equalTo(@16.0);
- }];
-
- [self.bgView addSubview:self.numButton];
- [self.numButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.countryImgView);
- make.right.mas_equalTo(-8);
- // make.width.mas_lessThanOrEqualTo(27);
- }];
-
- [self.bgView addSubview:self.nameLab];
- [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgView).offset(30.0);
- make.right.equalTo(self.numButton.mas_left).offset(-5.0);
- make.centerY.equalTo(self.countryImgView.mas_centerY);
- make.height.equalTo(@15.0);
- }];
-
- [self.bgView addSubview:self.titleLab];
- [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgView).offset(8.0);
- make.right.equalTo(self.bgView).offset(-20.0);
- make.height.equalTo(@20.0);
- make.bottom.equalTo(self.countryImgView.mas_top).offset(-6.0);
- }];
-
- [self.bgView addSubview:self.hotImgView];
- [self.hotImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgView).offset(-1.0);
- make.right.equalTo(self.bgView).offset(1.0);
- make.top.equalTo(self.bgView).offset(-1.0);
- make.bottom.equalTo(self.bgView).offset(1.0);
- }];
- self.hotImgView.hidden = YES;
-
- [self.bgView addSubview:self.moreView];
- [self.moreView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.bgView);
- }];
-
- [self.moreView addSubview:self.noLikeBtn];
- [self.noLikeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(36.0);
- make.center.equalTo(self.moreView);
- make.width.mas_equalTo(140);
- }];
- }
- - (void)setModel:(MOLiveList *)model{
- _model = model;
-
- self.titleLab.text = model.name;
- self.nameLab.text = model.anchorUser.nickname;
- [self.bgImgView sd_setImageWithURL:[NSURL URLWithString:model.logo] placeholderImage:[UIImage imageNamed:@"icon_base_img_placeHolder"]];
-
- MOCountryList *countryModel;
- if(model.anchorUser.country.length != 0){
- countryModel = (MOCountryList *)[[MODataCache sharedYYCache] objectForKey:[NSString stringWithFormat:@"%@_%@",kCountryArrInfo,model.anchorUser.country]];
- }
-
- if(countryModel){
- self.countryImgView.hidden = NO;
- __weak typeof(self) weakSelf = self;
- [self.countryImgView sd_setImageWithURL:[NSURL URLWithString:countryModel.icon] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- __strong typeof(self) strongSelf = weakSelf; if (!strongSelf) return;
- if (!image) return;
- [strongSelf.countryImgView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(image.size.width * 16.0 / image.size.height));
- }];
- }];
- [self.nameLab mas_updateConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgView).offset(30.0);
- }];
- }
- else{
- self.countryImgView.hidden = YES;
- [self.countryImgView sd_setImageWithURL:[NSURL URLWithString:@""]];
- [self.nameLab mas_updateConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgView).offset(8.0);
- }];
- }
-
- NSString *numText = [NSString stringWithFormat:@"%.f",model.visitNum];
- CGFloat numTextWidth = [MOTools getWidthWithString:numText font:self.numButton.titleLabel.font] + 16.0;
- [self.numButton setTitle:numText forState:UIControlStateNormal];
- [self.numButton mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.countryImgView);
- make.right.mas_equalTo(-8);
- make.width.equalTo(@(numTextWidth));
- }];
-
- [self.contentView setNeedsLayout];
- [self.contentView layoutIfNeeded];
-
- CGFloat multiBgViewTop = 30.0;
- CGFloat tagArrTop = 8.0;
-
- self.statusBtn.hidden = NO;
- if(model.liveBadge.type == 1){
- [self.statusBtn sd_setImageWithURL:[NSURL URLWithString:model.liveBadge.icon] forState:UIControlStateNormal];
- [self.statusBtn setTitle:model.liveBadge.name forState:UIControlStateNormal];
-
- [self.statusBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:@""] forState:UIControlStateNormal];
-
- if(model.liveBadge.bgColor.length > 0){
- self.statusBtn.backgroundColor = [MOTools colorWithHexString:model.liveBadge.bgColor alpha:1.0];
- }
- else{
- self.statusBtn.backgroundColor = [MOTools colorWithHexString:@"#120817" alpha:0.6];
- }
-
- CGFloat statusBtnWidth = [MOTools getWidthWithString:model.liveBadge.name font:[MOTextTools getTheFontWithSize:StatusFont AndFontName:kNormalContentFontStr]] + 10.0 + 30.0;
- CGFloat maxWidth = SCREENWIDTH - 15.0 * 2 - 30.0 - 100.0;
- if(statusBtnWidth > maxWidth){
- statusBtnWidth = maxWidth;
- }
-
- [self.statusBtn mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(statusBtnWidth));
- }];
-
- if(model.liveBadge.liveTag){
- self.statusBtn.hidden = YES;
- multiBgViewTop = 8.0;
- }
- }
- else{
- self.statusBtn.backgroundColor = [UIColor clearColor];
- [self.statusBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:model.liveBadge.bgImg] forState:UIControlStateNormal];
-
- [self.statusBtn setTitle:@"" forState:UIControlStateNormal];
- [self.statusBtn sd_setImageWithURL:[NSURL URLWithString:model.liveBadge.icon] forState:UIControlStateNormal];
-
- [self.statusBtn mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(90.0));
- }];
- }
-
- self.multiButton.hidden = YES;
- if(model.multiple){
- self.multiButton.hidden = NO;
- if (!self.statusBtn.hidden) {
- [self.multiButton mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(30.0);
- }];
- } else {
- [self.multiButton mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(8.0);
- }];
- }
- }
-
- self.pkButton.hidden = YES;
- if (model.pk) {
- self.pkButton.hidden = NO;
- if (!self.statusBtn.hidden) {
- [self.pkButton mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(30.0);
- }];
- } else {
- [self.pkButton mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(8.0);
- }];
- }
- }
-
- self.tagArrayView.hidden = YES;
- NSMutableArray *tempArr = [NSMutableArray array];
- if(model.redEnvelope){
- [tempArr addObject:[UIImage imageNamed:@"icon_room_tag_red"]];
- }
-
- if(model.roomType == 2){
- [tempArr addObject:[UIImage imageNamed:@"icon_room_tag_ticket"]];
- }
-
- if(model.roomType == 3){
- [tempArr addObject:[UIImage imageNamed:@"icon_room_tag_psw"]];
- }
- if (tempArr.count > 0) {
- self.tagArrayView.hidden = NO;
- [self.tagArrayView setIcons:tempArr];
- }
-
- if(model.isViewSelect){
- self.moreView.hidden = NO;
- }
- else{
- self.moreView.hidden = YES;
- }
-
- if(model.bgBorder.length > 0){
- self.hotImgView.hidden = NO;
- [self.hotImgView sd_setImageWithURL:[NSURL URLWithString:model.bgBorder]];
- }
- else{
- self.hotImgView.hidden = YES;
- }
- }
- #pragma mark - Lazy
- - (UIView *)bgView
- {
- if (_bgView == nil)
- {
- _bgView = [UIView new];
- _bgView.backgroundColor = [MOTools colorWithHexString:@"#F5F1F6" alpha:1.0];
- }
- return _bgView;
- }
- - (UIButton *)pkButton {
- if (!_pkButton) {
- _pkButton = [[UIButton alloc] init];
- _pkButton.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.4];
- _pkButton.layer.masksToBounds = YES;
- _pkButton.layer.cornerRadius = 8;
- [_pkButton setImage:[UIImage imageNamed:@"icon_room_tag_pk"] forState:UIControlStateNormal];
- [_pkButton setTitle:@" PK" forState:UIControlStateNormal];
- [_pkButton setTitleColor:[MOTools colorWithHexString:@"#1AFFB3"] forState:UIControlStateNormal];
- _pkButton.titleLabel.font = [MOTextTools mediumFont:10];
- _pkButton.userInteractionEnabled = NO;
- }
- return _pkButton;
- }
- - (UIButton *)multiButton {
- if (!_multiButton) {
- _multiButton = [[UIButton alloc] init];
- _multiButton.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.4];
- _multiButton.layer.masksToBounds = YES;
- _multiButton.layer.cornerRadius = 8;
- [_multiButton setImage:[UIImage imageNamed:@"icon_link_mic"] forState:UIControlStateNormal];
- [_multiButton setTitle:@" Multi-call" forState:UIControlStateNormal];
- [_multiButton setTitleColor:[MOTools colorWithHexString:@"#1AFFB3"] forState:UIControlStateNormal];
- _multiButton.titleLabel.font = [MOTextTools mediumFont:10];
- _multiButton.userInteractionEnabled = NO;
- }
- return _multiButton;
- }
- - (UIView *)moreView
- {
- if (_moreView == nil)
- {
- _moreView = [UIView new];
- _moreView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.4];
- _moreView.hidden = YES;
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancelBtnClick)];
- [_moreView addGestureRecognizer:tap];
- }
- return _moreView;
- }
- - (UIImageView *)bgImgView{
- if (!_bgImgView)
- {
- _bgImgView = [[UIImageView alloc] init];
- _bgImgView.clipsToBounds = YES;
- _bgImgView.userInteractionEnabled = NO;
- _bgImgView.contentMode = UIViewContentModeScaleAspectFill;
- [_bgImgView setImage:[UIImage imageNamed:@""]];
-
- _bgView.userInteractionEnabled = YES;
- UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(moreBtnClick)];
- [_bgView addGestureRecognizer:longPress];
- }
- return _bgImgView;
- }
- - (UIImageView *)hotImgView{
- if (!_hotImgView)
- {
- _hotImgView = [[UIImageView alloc] init];
- _hotImgView.clipsToBounds = YES;
- _hotImgView.userInteractionEnabled = NO;
- _hotImgView.contentMode = UIViewContentModeScaleToFill;
- [_hotImgView setImage:[UIImage imageNamed:@""]];
- }
- return _hotImgView;
- }
- - (UIImageView *)shadowView{
- if (!_shadowView)
- {
- _shadowView = [[UIImageView alloc] init];
- _shadowView.clipsToBounds = YES;
- _shadowView.userInteractionEnabled = NO;
- _shadowView.contentMode = UIViewContentModeScaleAspectFill;
- }
- return _shadowView;
- }
- - (MOStatusButton *)statusBtn
- {
- if (!_statusBtn)
- {
- _statusBtn = [MOStatusButton buttonWithType:UIButtonTypeCustom];
- _statusBtn.frame = CGRectMake(0, 0, 100, 19.0);
- _statusBtn.backgroundColor = [MOTools colorWithHexString:@"#120817" alpha:0.6];
- _statusBtn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
- _statusBtn.userInteractionEnabled = NO;
- [_statusBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- _statusBtn.titleLabel.font = [MOTextTools getTheFontWithSize:StatusFont AndFontName:kNormalContentFontStr];
- _statusBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
- _statusBtn.contentMode = UIViewContentModeScaleAspectFill;
- }
- return _statusBtn;
- }
- - (UILabel *)titleLab
- {
- if(!_titleLab)
- {
- _titleLab = [UILabel new];
- _titleLab.textColor = UIColorFromHex(0xFFFFFF);
- _titleLab.textAlignment = NSTextAlignmentLeft;
- _titleLab.font = [MOTextTools poppinsSemiBoldFont:14];
- _titleLab.backgroundColor = [UIColor clearColor];
- }
- return _titleLab;
- }
- - (UIImageView *)countryImgView{
- if(!_countryImgView){
- _countryImgView = [[UIImageView alloc] init];
- }
- return _countryImgView;
- }
- - (UILabel *)nameLab
- {
- if(!_nameLab)
- {
- _nameLab = [UILabel new];
- _nameLab.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:0.8];
- _nameLab.textAlignment = NSTextAlignmentLeft;
- _nameLab.font = [MOTextTools regularFont:10];
- _nameLab.backgroundColor = [UIColor clearColor];
- }
- return _nameLab;
- }
- - (BigBtn *)numButton {
- if (!_numButton) {
- _numButton = [[BigBtn alloc] init];
- [_numButton setImage:[UIImage imageNamed:@"icon_online_num"] forState:UIControlStateNormal];
- _numButton.titleLabel.font = [MOTextTools regularFont:10];
- [_numButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:0.8] forState:UIControlStateNormal];
- _numButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- }
- return _numButton;
- }
- - (void)moreBtnClick{
-
- self.moreView.hidden = NO;
- self.model.isViewSelect = YES;
-
- self.moreBtnBlock ? self.moreBtnBlock(self.model) : nil;
- }
- - (UIButton *)noLikeBtn
- {
- if (!_noLikeBtn)
- {
- _noLikeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _noLikeBtn.backgroundColor = [UIColor whiteColor];
- _noLikeBtn.layer.cornerRadius = 36.0 / 2.0;
- _noLikeBtn.layer.masksToBounds = YES;
- [_noLikeBtn setFont:[MOTextTools regularFont:14]];
- [_noLikeBtn setTitle:NSLocalString(@"mimo_room_not_interested") forState:UIControlStateNormal];
- [_noLikeBtn setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
- [_noLikeBtn addTarget:self action:@selector(noLikeBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [_noLikeBtn setImage:[UIImage imageNamed:@"icon_not_insterest"] forState:UIControlStateNormal];
- [_noLikeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 3, 0, 0)];
- [_noLikeBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 3)];
- }
- return _noLikeBtn;
- }
- - (void)noLikeBtnClick{
- [self toSubmitTheNoLikeRoom];
- }
- - (void)toSubmitTheNoLikeRoom{
-
- if(self.model.id.length == 0){
- return;
- }
-
- NSDictionary *dict = @{@"id":self.model.id};
-
- WEAKSELF
- [kHttpManager toSubmitTheDisinterestRoomWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_success")];
-
- weakSelf.noLikeBlock ? weakSelf.noLikeBlock(weakSelf.model) : nil;
- }
- else{
- MOLogV(@"toSubmitTheNoLikeRoom 接口报错了");
- kShowNetError(data)
- }
- }];
- }
- - (void)cancelBtnClick{
- self.moreView.hidden = YES;
- self.model.isViewSelect = NO;
-
- self.cancelBtnBlock ? self.cancelBtnBlock(self.model) : nil;
- }
- - (MOLiveTagArrayView *)tagArrayView{
- if(!_tagArrayView){
- _tagArrayView = [[MOLiveTagArrayView alloc] init];
- _tagArrayView.layer.masksToBounds = YES;
- _tagArrayView.layer.cornerRadius = 8;
- _tagArrayView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.4];
- }
- return _tagArrayView;
- }
- @end
|