// // QXDynamicListCell.m // SweetParty // // Created by bj_szd on 2022/6/1. // #import "QXDynamicListCell.h" //#import "UILabel+ChangeSpace.h" //#import "KNPhotoBrowser.h" //#import "SPTrendReportVC.h" #import "QXSendGiftView.h" #import "YBImageBrowser.h" #import "QXDynamicNetwork.h" #import "QXShareView.h" #import "QXAlertView.h" #import "QXDynamicDetailViewController.h" #import "QXUserHomePageViewController.h" #import "QXDynamicLikeListView.h" #import "QXReportViewController.h" @interface QXDynamicListCell () @property (nonatomic, strong) NSMutableArray *imgViewsArray; @property (nonatomic, strong)QXSendGiftView *sendView; @end @implementation QXDynamicListCell - (void)awakeFromNib { [super awakeFromNib]; self.imgViewsArray = [NSMutableArray arrayWithCapacity:6]; self.zanBtn.needEventInterval = 0.5; [self createUI]; } -(void)setCellType:(QXDynamicListCellType)cellType{ _cellType = cellType; } - (void)setModel:(QXDynamicModel *)model { _model = model; [self.avatarImgV setHeadIcon:model.avatar dress:@""]; self.nicknameLab.text = model.nickname; NSDate *date = [NSDate dateWithTimeIntervalSince1970:model.createtime.longLongValue]; //此处根据项目需求,选择是否除以1000 , 如果时间戳精确到秒则去掉1000 NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; NSString*time = [formatter stringFromDate:date]; self.zanBtn.selected = model.is_like.integerValue == 0?NO:YES; self.timeLab.text = time; UIImage *sexImage = [UIImage imageNamed:model.sex.intValue==1?@"user_sex_boy":@"user_sex_girl"]; self.sexImageView.image = sexImage; // self.focusBtn.selected = model.is_follow; //// self.focusBtn.backgroundColor = model.is_follow ? HEXCOLOR(0x383841) : mainDeepColor; // // self.focusBtn.hidden = [BJUserManager.userInfo.uid integerValue] == [model.uid integerValue]; NSString *topic = @""; for (QXTopicModel *md in model.title) { if (topic.length == 0) { topic = [topic stringByAppendingFormat:@"%@",md.title]; }else{ topic = [topic stringByAppendingFormat:@" %@",md.title]; } } NSString *content = [NSString stringWithFormat:@"%@ %@",model.content,topic]; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:content]; [attr yy_setColor:QXConfig.themeColor range:[content rangeOfString:topic]]; self.contentLab.attributedText = attr; // [UILabel changeLineSpaceForLabel:self.contentLab WithSpace:5]; // // NSString *topic = [model.title stringByReplacingOccurrencesOfString:@"#" withString:@""]; // self.topicLabel.text = topic; [self.commentBtn setTitle:[NSString qx_showHotCountNum:model.comment_num.longLongValue] forState:UIControlStateNormal]; [self.zanBtn setTitle:[NSString stringWithFormat:@"%@", [NSString qx_showHotCountNum:model.like_num.longLongValue]] forState:UIControlStateNormal]; self.zanBtn.selected = [model.is_like isEqualToString:@"1"]?YES:NO; [self.giveBtn setTitle:[NSString qx_showHotCountNum:model.rewards_num.longLongValue] forState:(UIControlStateNormal)]; self.imgsBgView.hidden = YES; self.imgsBgViewHeightCon.constant = 0; for (UIImageView *imgV in self.imgViewsArray) { imgV.hidden = YES; } CGFloat imgWidth = (SCREEN_WIDTH-16*2-12*2-10*2)/3; UIImageView *firstImgV = self.imgViewsArray.firstObject; [firstImgV mas_updateConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(imgWidth, imgWidth)); }]; NSArray *images; if (model.images.length > 0) { images = [model.images componentsSeparatedByString:@","]; } if (images.count > 0) { for (NSInteger i = 0; i < images.count; i++) { if (i < self.imgViewsArray.count) { UIImageView *imgV = self.imgViewsArray[i]; imgV.hidden = NO; [imgV sd_setImageWithURL:[NSURL URLWithString:images[i]]]; } } if (images.count == 1) {//特殊 CGFloat itemW = (SCREEN_WIDTH-15-15-15)/2; CGFloat imgBgHeight = itemW; self.imgsBgView.hidden = NO; self.imgsBgViewHeightCon.constant = imgBgHeight; [firstImgV mas_updateConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(itemW, imgBgHeight)); }]; }else { CGFloat itemW = (SCREEN_WIDTH-16*2-12*2-10*2)/3; CGFloat imgBgHeight = 0; NSInteger lines = images.count%3 == 0 ? images.count/3 : images.count/3+1; imgBgHeight = itemW*lines + 10*(lines-1); self.imgsBgView.hidden = NO; self.imgsBgViewHeightCon.constant = imgBgHeight; } } if (model.room_id.intValue > 0) { [self setBtnTypeWithIsFollow:YES]; }else{ [self setBtnTypeWithIsFollow:NO]; } if (self.cellType == QXDynamicListCellDetail) { self.bgLeftCon.constant = 0; self.bgRightCon.constant = 0; if (model.like_list.count == 0) { self.userImageView1.hidden = YES; self.userImageView2.hidden = YES; self.userImageView3.hidden = YES; self.likeViewBtn.hidden = YES; self.likeCountLabel.hidden = YES; }else if (model.like_list.count == 1) { self.likeViewBtn.hidden = NO; self.likeCountLabel.hidden = NO; self.userImageView1.hidden = NO; QXDynamicLikeModel *md = model.like_list.firstObject; [self.userImageView1 sd_setImageWithURL:[NSURL URLWithString:md.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]]; self.userImageView2.hidden = YES; self.userImageView3.hidden = YES; self.likeCountLabel.text = [NSString localizedStringWithFormat:QXText(@"等%@人点赞"),self.zanBtn.titleLabel.text]; }else if(model.like_list.count == 2){ self.likeCountLabel.hidden = NO; self.userImageView1.hidden = NO; self.userImageView1.hidden = NO; self.userImageView2.hidden = NO; QXDynamicLikeModel *md1 = model.like_list.firstObject; [self.userImageView1 sd_setImageWithURL:[NSURL URLWithString:md1.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]]; QXDynamicLikeModel *md2 = model.like_list[1]; [self.userImageView2 sd_setImageWithURL:[NSURL URLWithString:md2.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]]; self.userImageView3.hidden = YES; self.likeCountLabel.text = [NSString localizedStringWithFormat:QXText(@"等%@人点赞"),self.zanBtn.titleLabel.text]; }else{ self.likeCountLabel.hidden = NO; self.userImageView1.hidden = NO; self.userImageView1.hidden = NO; self.userImageView2.hidden = NO; self.userImageView3.hidden = NO; QXDynamicLikeModel *md1 = model.like_list.firstObject; [self.userImageView1 sd_setImageWithURL:[NSURL URLWithString:md1.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]]; QXDynamicLikeModel *md2 = model.like_list[1]; [self.userImageView2 sd_setImageWithURL:[NSURL URLWithString:md2.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]]; QXDynamicLikeModel *md3 = model.like_list[2]; [self.userImageView3 sd_setImageWithURL:[NSURL URLWithString:md3.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]]; self.likeCountLabel.text = [NSString localizedStringWithFormat:QXText(@"等%@人点赞"),self.zanBtn.titleLabel.text]; } self.focusBtn.hidden = NO; }else if (self.cellType == QXDynamicListCellDynamic) { self.userImageView1.hidden = YES; self.userImageView2.hidden = YES; self.userImageView3.hidden = YES; self.likeViewBtn.hidden = YES; self.likeCountLabel.hidden = YES; self.focusBtn.hidden = NO; }else{ self.userImageView1.hidden = YES; self.userImageView2.hidden = YES; self.userImageView3.hidden = YES; self.likeViewBtn.hidden = YES; self.likeCountLabel.hidden = YES; self.focusBtn.hidden = YES; } if ([self.model.user_id isEqualToString:[QXGlobal shareGlobal].loginModel.user_id]) { self.focusBtn.hidden = YES; } } - (void)createUI { CGFloat imgWidth = (SCREEN_WIDTH-16*2-12*2-10*2)/3; for (NSInteger i = 0; i < 9; i++) { UIImageView *imgV = [[UIImageView alloc] init]; imgV.tag = i+100; imgV.userInteractionEnabled = YES; MJWeakSelf // [imgV dg_Tapped:^{ // [weakSelf onPreviewImage:imgV]; // }]; [imgV addTapBlock:^(id _Nonnull obj) { [weakSelf previewPhotoWithCurrentIndex:imgV.tag-100]; }]; imgV.hidden = YES; imgV.layer.masksToBounds = YES; imgV.layer.cornerRadius = 10; imgV.contentMode = UIViewContentModeScaleAspectFill; [self.imgsBgView addSubview:imgV]; [self.imgViewsArray addObject:imgV]; [imgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imgsBgView).offset((imgWidth+10)*(i/3)); make.left.equalTo(self.imgsBgView).offset((imgWidth+10)*(i%3)); make.size.mas_equalTo(CGSizeMake(imgWidth, imgWidth)); }]; } } -(void)previewPhotoWithCurrentIndex:(NSInteger)currentIndex{ NSArray *images = [self.model.images componentsSeparatedByString:@","]; YBImageBrowser *browser = [YBImageBrowser new]; NSMutableArray *sourceArray = [NSMutableArray array]; for (int i = 0 ; i 0) { // 去房间 [[QXGlobal shareGlobal] joinRoomWithRoomId:self.model.room_id isRejoin:NO navagationController:self.navigationController]; }else{ //去聊天 // 去聊天 [[QXGlobal shareGlobal] chatWithUserID:self.model.user_id nickname:self.model.nickname avatar:self.model.avatar navagationController:self.navigationController]; } } - (IBAction)commentAction:(id)sender { if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } switch (self.cellType) { case QXDynamicListCellDetail: break; case QXDynamicListCellDynamic:{ QXDynamicDetailViewController *vc = [[QXDynamicDetailViewController alloc] init]; vc.model = self.model; [self.navigationController pushViewController:vc animated:YES]; } break; case QXDynamicListCellHomePage:{ QXDynamicDetailViewController *vc = [[QXDynamicDetailViewController alloc] init]; vc.model = self.model; [self.navigationController pushViewController:vc animated:YES]; } break; default: break; } } - (IBAction)onZan:(UIButton*)sender { if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } BOOL isLike = !sender.selected; MJWeakSelf [QXDynamicNetwork likeDynamicWithId:self.model.id isLike:isLike successBlock:^(NSDictionary * _Nonnull dict) { weakSelf.zanBtn.selected = !weakSelf.zanBtn.selected; if (weakSelf.zanBtn.selected) { [weakSelf.zanBtn setTitle:[NSString stringWithFormat:@"%ld", weakSelf.model.like_num.integerValue+1] forState:UIControlStateNormal]; }else{ [weakSelf.zanBtn setTitle:[NSString stringWithFormat:@"%ld", weakSelf.model.like_num.integerValue] forState:UIControlStateNormal]; } } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } - (IBAction)onHomepage:(id)sender { if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } if (self.cellType == QXDynamicListCellHomePage) { return; } QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init]; vc.user_id = self.model.user_id; [self.navigationController pushViewController:vc animated:YES]; } - (IBAction)onMore:(id)sender { if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } QXShareView *shareView = [[QXShareView alloc] init]; shareView.shareType = QXShareViewTypeFind; shareView.delegate = self; shareView.dynamicModel = self.model; [shareView showInView:KEYWINDOW]; } - (IBAction)likeViewAction:(id)sender { if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } QXDynamicLikeListView *listView = [[QXDynamicLikeListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; listView.Id = self.model.id; listView.num = [NSString localizedStringWithFormat:QXText(@"已有%@人点赞"),self.zanBtn.titleLabel.text]; [listView showInView:KEYWINDOW]; } -(void)didClickShareModel:(QXShareViewModel *)model{ if ([model.name isEqualToString:QXText(@"删除")]) { MJWeakSelf QXAlertView *al = [[QXAlertView alloc] initWithFrame:CGRectMake(0, 0, ScaleWidth(300), ScaleWidth(175))]; al.type = QXAlertViewTypeDeleteDynamic; al.commitBlock = ^{ [weakSelf deleteDynamic]; }; [[QXGlobal shareGlobal] showView:al popType:(PopViewTypeTopToCenter) tapDismiss:NO finishBlock:^{ }]; }else if ([model.name isEqualToString:QXText(@"复制链接")]) { UIPasteboard *p = [UIPasteboard generalPasteboard]; p.string = [NSString stringWithFormat:@"%@", self.model.share_url]; showToast(@"复制成功"); }else if ([model.name isEqualToString:QXText(@"举报")]) { QXReportViewController *reportVC = [[QXReportViewController alloc] init]; reportVC.reportType = @"3"; reportVC.fromId = self.model.id; [self.navigationController pushViewController:reportVC animated:YES]; } } -(void)deleteDynamic{ MJWeakSelf [QXDynamicNetwork deleteDynamicWithId:self.model.id successBlock:^(NSDictionary * _Nonnull dict) { if (weakSelf.onDeleteBlock) { weakSelf.onDeleteBlock(weakSelf.model); } } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)onReport { // SPTrendReportVC *vc = [[SPTrendReportVC alloc] init]; // vc.userId = self.model.uid; // [vc pushSelf]; } - (IBAction)giveAction:(id)sender { // QXAlertViewController *al = [[QXAlertViewController alloc] init]; // al.alertView = sendView; // al.tapDismiss = YES; // al.popType = PopViewTypeBottomToUpActionSheet; // self.sendView.vc = self.viewController; if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } self.sendView.dynamicId = self.model.id; MJWeakSelf self.sendView.sendSuccessBlock = ^(NSString * _Nonnull dynamicId) { [weakSelf reloadDetail]; [weakSelf.sendView hide]; self->_sendView = nil; }; [self.sendView showInView:KEYWINDOW]; // al.modalPresentationStyle = UIModalPresentationOverFullScreen; // [self.viewController presentViewController:al animated:NO completion:nil]; } -(void)reloadDetail{ MJWeakSelf [QXDynamicNetwork dynamicPageWithId:self.model.id successBlock:^(QXDynamicModel * _Nonnull model) { weakSelf.model = model; [weakSelf setModel:model]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)setBtnTypeWithIsFollow:(BOOL)isFollow{ [self.focusBtn setTitle:isFollow?QXText(@"跟随"):QXText(@"私信") forState:(UIControlStateNormal)]; [self.focusBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)]; self.focusBtn.backgroundColor = RGB16(0x333333); self.focusBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.focusBtn addRoundedCornersWithRadius:12.5]; } -(QXSendGiftView *)sendView{ if (!_sendView) { _sendView = [[QXSendGiftView alloc] initWithType:(QXSendGiftViewTypeFind)]; // QXAlertViewController *al = [[QXAlertViewController alloc] init]; // al.alertView = sendView; // al.tapDismiss = YES; // al.popType = PopViewTypeBottomToUpActionSheet; [_sendView reloadData]; } return _sendView; } @end