123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- //
- // YMDynamicDetailInfoCell.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/21.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMDynamicDetailInfoCell.h"
- #import "YMDynamicDetailInfoCellViewModel.h"
- #import "YMDynamicDetailInfoAlbumCell.h"
- #import "CHTCollectionViewWaterfallLayout.h"
- @interface YMDynamicDetailInfoCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,CHTCollectionViewDelegateWaterfallLayout,YBImageBrowserDelegate>
- /// ViewModel
- @property (nonatomic, strong) YMDynamicDetailInfoCellViewModel *viewModel;
- /// 基础视图
- @property (nonatomic, strong) UIView *baseView;
- /// 用户头像视图
- @property (nonatomic, strong) UIImageView *userAvatarView;
- /// 用户昵称标签
- @property (nonatomic, strong) UILabel *userNicknameLb;
- /// 用户描述标签
- @property (nonatomic, strong) UILabel *userDescLb;
- /// VIP图标
- @property (nonatomic, strong) UIImageView *userVIPIcon;
- /// 心动按钮
- @property (nonatomic, strong) UIButton *heartbeatBtn;
- /// 用户内容标签
- @property (nonatomic, strong) UILabel *userContentLb;
- /// 用户相册排版
- @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *albumLayout;
- /// 用户相册容器列表
- @property (nonatomic, strong) UICollectionView *albumCollectionView;
- /// 日期标签
- @property (nonatomic, strong) UILabel *dateLb;
- /// 评论按钮
- @property (nonatomic, strong) UIButton *commentsBtn;
- /// 点赞按钮
- @property (nonatomic, strong) UIButton *likesBtn;
- @end
- @implementation YMDynamicDetailInfoCell
- - (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
- }
- - (void)ym_setupViews{
- self.contentView.backgroundColor = UIColor.clearColor;
- self.backgroundColor = UIColor.clearColor;
-
- [self.contentView addSubview:self.baseView];
- [self.baseView addSubview:self.userAvatarView];
- [self.baseView addSubview:self.userNicknameLb];
- [self.baseView addSubview:self.userDescLb];
- [self.baseView addSubview:self.userVIPIcon];
- [self.baseView addSubview:self.heartbeatBtn];
- [self.baseView addSubview:self.userContentLb];
- [self.baseView addSubview:self.albumCollectionView];
- [self.baseView addSubview:self.dateLb];
- [self.baseView addSubview:self.commentsBtn];
- [self.baseView addSubview:self.likesBtn];
-
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints {
- [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(adapt(10));
- make.left.equalTo(self.contentView);
- make.right.equalTo(self.contentView);
- make.bottom.equalTo(self.contentView);
- }];
-
- [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.baseView).offset(adapt(15));
- make.left.equalTo(self.baseView).offset(adapt(15));
- make.width.height.mas_equalTo(adapt(40));
- }];
-
- [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userAvatarView.mas_top);
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- }];
-
- [self.userDescLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userNicknameLb.mas_bottom).offset(adapt(5));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- }];
-
- [self.userVIPIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.userNicknameLb.mas_centerY);
- make.left.equalTo(self.userNicknameLb.mas_right).offset(adapt(10));
- make.width.mas_equalTo(adapt(40));
- make.height.mas_equalTo(adapt(15));
- }];
-
- [self.heartbeatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.userNicknameLb.mas_centerY);
- make.right.equalTo(self.baseView).offset(adapt(-15));
- make.width.mas_equalTo(adapt(70));
- make.height.mas_equalTo(adapt(25));
- }];
-
- [self.userContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userDescLb.mas_bottom).offset(adapt(20));
- make.left.equalTo(self.baseView).offset(adapt(15));
- make.right.equalTo(self.baseView).offset(adapt(-15));
- }];
-
- [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userContentLb.mas_bottom).offset(adapt(10));
- make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
- make.right.equalTo(self.baseView).offset(adapt(-15));
- }];
-
- [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.albumCollectionView.mas_bottom).offset(adapt(10));
- make.left.equalTo(self.albumCollectionView.mas_left);
- }];
-
- [self.commentsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.likesBtn.mas_centerY);
- make.right.equalTo(self.likesBtn.mas_left).offset(adapt(-10));
- make.width.mas_equalTo(adapt(70));
- make.height.mas_equalTo(adapt(30));
- }];
-
- [self.likesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.dateLb.mas_bottom).offset(adapt(10));
- make.right.equalTo(self.baseView).offset(adapt(-15));
- make.bottom.equalTo(self.baseView).offset(adapt(-15)).priorityHigh();
- make.width.mas_equalTo(adapt(70));
- make.height.mas_equalTo(adapt(30));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMDynamicDetailInfoCellViewModel*)viewModel{
- if (!viewModel) {
- return;
- }
- _viewModel = viewModel;
-
- [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.userAvatar]];
-
- self.userNicknameLb.text = self.viewModel.userNickname;
- self.userNicknameLb.textColor = self.viewModel.userNicknameColor;
-
- self.userDescLb.text = self.viewModel.userDesc;
-
- self.userVIPIcon.hidden = self.viewModel.isHideVIPIcon;
-
- self.heartbeatBtn.hidden = self.viewModel.isHideHeartbeatButton;
-
- self.userContentLb.text = self.viewModel.userContent;
-
- self.dateLb.text = self.viewModel.date;
-
- [self.commentsBtn setTitle:self.viewModel.commentsNumber forState:UIControlStateNormal];
- [self.commentsBtn setImage:self.viewModel.commentsImage forState:UIControlStateNormal];
-
- [self.likesBtn setTitle:self.viewModel.likesNumber forState:UIControlStateNormal];
- [self.likesBtn setImage:self.viewModel.likesImage forState:UIControlStateNormal];
-
- [self.albumCollectionView reloadData];
- [self.albumCollectionView layoutIfNeeded];
- [self.baseView layoutIfNeeded];
-
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.viewModel.albumDataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- YMDynamicDetailInfoAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMDynamicDetailInfoAlbumCell class]) forIndexPath:indexPath];
- [cell ym_bindViewModel:self.viewModel.albumDataArray[indexPath.item]];
- return cell;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
- UICollectionReusableView *reusableView = nil;
- reusableView.backgroundColor = [UIColor clearColor];
- return reusableView;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
- return CGSizeZero;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
- return CGSizeZero;
- }
- #pragma mark - UICollectionViewDelegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- NSMutableArray *tempArr = [NSMutableArray array];
- for (YMDynamicListAlbumCellViewModel *model in self.viewModel.albumDataArray) {
- if ([model.albumType isEqualToString:@"mp4"]) {
- YBIBVideoData *data = [YBIBVideoData new];
- data.videoURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,model.albumUrl]];
- [collectionView cellForItemAtIndexPath:indexPath];
- [tempArr addObject:data];
- } else {
- YBIBImageData *data = [YBIBImageData new];
- data.imageURL = [LCTools getImageUrlWithAddress:model.albumUrl];
- data.projectiveView = [collectionView cellForItemAtIndexPath:indexPath];
- [tempArr addObject:data];
- }
- }
- YBImageBrowser *browser = [YBImageBrowser new];
- browser.delegate = self;
- browser.dataSourceArray = tempArr;
- browser.currentPage = indexPath.item;
- [browser show];
- }
- #pragma mark - CHTCollectionViewDelegateWaterfallLayout
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (self.viewModel.albumDataArray.count >= 2) {
- return CGSizeMake(adapt(100), adapt(100));
- } else {
- CGSize albumSize = self.viewModel.albumDataArray[indexPath.item].albumSize;
- return CGSizeMake(adapt(albumSize.width), adapt(albumSize.height));
- }
- }
- - (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority {
- CGSize size = [super systemLayoutSizeFittingSize:targetSize withHorizontalFittingPriority:horizontalFittingPriority verticalFittingPriority:verticalFittingPriority];
-
- self.baseView.frame = CGRectMake(0, 0, targetSize.width, adapt(44));
- [self.baseView layoutIfNeeded];
-
- self.albumCollectionView.frame = CGRectMake(0, 0, targetSize.width - CGRectGetWidth(self.userAvatarView.frame) - adapt(10) - adapt(15)*2, adapt(44));
- [self.albumCollectionView layoutIfNeeded];
-
- CGSize collectionViewSize = self.albumCollectionView.collectionViewLayout.collectionViewContentSize;
-
- return CGSizeMake(size.width, size.height + collectionViewSize.height);
- }
- - (UIView *)baseView{
- if (!_baseView) {
- _baseView = [[UIView alloc]init];
- _baseView.backgroundColor = HexColorFromRGB(0xFFFFFF);
- }
- return _baseView;
- }
- - (UIImageView *)userAvatarView{
- if (!_userAvatarView) {
- _userAvatarView = [[UIImageView alloc]init];
- _userAvatarView.backgroundColor = UIColor.lightGrayColor;
- _userAvatarView.contentMode = UIViewContentModeScaleAspectFill;
- _userAvatarView.layer.cornerRadius = adapt(40)/2;
- _userAvatarView.clipsToBounds = YES;
- _userAvatarView.userInteractionEnabled = YES;
- WS(weakSelf)
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
- [_userAvatarView addGestureRecognizer:tap];
- [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- [weakSelf.viewModel.gotoPersonalPageSubject sendNext:@(weakSelf.viewModel.userId)];
- }];
- }
- return _userAvatarView;
- }
- - (UILabel *)userNicknameLb{
- if (!_userNicknameLb) {
- _userNicknameLb = [[UILabel alloc]init];
- _userNicknameLb.font = LCFont(15);
- _userNicknameLb.textColor = HexColorFromRGB(0x333333);
- _userNicknameLb.textAlignment = NSTextAlignmentLeft;
- _userNicknameLb.text = @"******";
- }
- return _userNicknameLb;
- }
- - (UILabel *)userDescLb{
- if (!_userDescLb) {
- _userDescLb = [[UILabel alloc]init];
- _userDescLb.font = LCFont(12);
- _userDescLb.textColor = HexColorFromRGB(0x9c9c9c);
- _userDescLb.textAlignment = NSTextAlignmentLeft;
- _userDescLb.text = @"******";
- }
- return _userDescLb;
- }
- - (UIImageView *)userVIPIcon{
- if (!_userVIPIcon) {
- _userVIPIcon = [[UIImageView alloc]init];
- _userVIPIcon.image = ImageByName(@"ym_dynamic_vip_icon");
- }
- return _userVIPIcon;
- }
- - (UIButton *)heartbeatBtn{
- if (!_heartbeatBtn) {
- _heartbeatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _heartbeatBtn.titleLabel.font = LCFont(13);
- [_heartbeatBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
- [_heartbeatBtn setTitle:@"心动" forState:UIControlStateNormal];
- [_heartbeatBtn setImage:ImageByName(@"ym_common_heartbeat_or_accost_icon") forState:UIControlStateNormal];
- _heartbeatBtn.backgroundColor = HexColorFromRGB(0xfd7bc5);
- _heartbeatBtn.layer.cornerRadius = adapt(25)/2;
- _heartbeatBtn.layer.masksToBounds = YES;
- _heartbeatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- [_heartbeatBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
- CGFloat margin = 5;
- _heartbeatBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
- // WS(weakSelf)
- [[[_heartbeatBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
-
- }];
- }
- return _heartbeatBtn;
- }
- - (UILabel *)userContentLb{
- if (!_userContentLb) {
- _userContentLb = [[UILabel alloc]init];
- _userContentLb.font = LCFont(14);
- _userContentLb.textColor = HexColorFromRGB(0x333333);
- _userContentLb.textAlignment = NSTextAlignmentLeft;
- _userContentLb.numberOfLines = 0;
- _userContentLb.text = @"******";
- }
- return _userContentLb;
- }
- - (CHTCollectionViewWaterfallLayout *)albumLayout{
- if (!_albumLayout) {
- _albumLayout = [[CHTCollectionViewWaterfallLayout alloc] init];
- _albumLayout.columnCount = 3;
- _albumLayout.sectionInset = UIEdgeInsetsMake(adapt(5), adapt(5), adapt(5), adapt(5));
- }
- return _albumLayout;
- }
- - (UICollectionView *)albumCollectionView{
- if (!_albumCollectionView) {
- _albumCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.albumLayout];
- _albumCollectionView.delegate = self;
- _albumCollectionView.dataSource = self;
- _albumCollectionView.showsVerticalScrollIndicator = NO;
- _albumCollectionView.showsHorizontalScrollIndicator = NO;
- _albumCollectionView.backgroundColor = UIColor.whiteColor;
- [_albumCollectionView registerClass:[YMDynamicDetailInfoAlbumCell class] forCellWithReuseIdentifier:NSStringFromClass([YMDynamicDetailInfoAlbumCell class])];
- }
- return _albumCollectionView;
- }
- - (UILabel *)dateLb{
- if (!_dateLb) {
- _dateLb = [[UILabel alloc]init];
- _dateLb.font = LCFont(12);
- _dateLb.textColor = HexColorFromRGB(0x9c9c9c);
- _dateLb.textAlignment = NSTextAlignmentLeft;
- _dateLb.text = @"****-**-**";
- }
- return _dateLb;
- }
- - (UIButton *)commentsBtn{
- if (!_commentsBtn) {
- _commentsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _commentsBtn.titleLabel.font = LCFont(13);
- [_commentsBtn setTitleColor:HexColorFromRGB(0x9c9c9c) forState:UIControlStateNormal];
- [_commentsBtn setTitle:@"评论" forState:UIControlStateNormal];
- [_commentsBtn setImage:ImageByName(@"ym_dynamic_comments_icon") forState:UIControlStateNormal];
- _commentsBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [_commentsBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
- CGFloat margin = 5;
- _commentsBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
- // WS(weakSelf)
- [[[_commentsBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
-
- }];
- }
- return _commentsBtn;
- }
- - (UIButton *)likesBtn{
- if (!_likesBtn) {
- _likesBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _likesBtn.titleLabel.font = LCFont(13);
- [_likesBtn setTitleColor:HexColorFromRGB(0x9c9c9c) forState:UIControlStateNormal];
- [_likesBtn setTitle:@"点赞" forState:UIControlStateNormal];
- [_likesBtn setImage:ImageByName(@"ym_dynamic_likes_normal_icon") forState:UIControlStateNormal];
- _likesBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [_likesBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
- CGFloat margin = 5;
- _likesBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
- // WS(weakSelf)
- [[[_likesBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
-
- }];
- }
- return _likesBtn;
- }
- @end
|