241 lines
8.2 KiB
Objective-C
241 lines
8.2 KiB
Objective-C
//
|
|
// XPMomentListCollectionViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by XY on 2023/2/16.
|
|
//
|
|
|
|
#import "XPMomentListCollectionViewCell.h"
|
|
#import "ThemeColor.h"
|
|
#import <Masonry.h>
|
|
#import <SVGA.h>
|
|
#import "NetImageView.h"
|
|
#import "NSArray+Safe.h"
|
|
#import "UIButton+EnlargeTouchArea.h"
|
|
|
|
#import "MonentsInfoModel.h"
|
|
|
|
@interface XPMomentListCollectionViewCell()
|
|
|
|
/// 文字底部渐变背景
|
|
@property (nonatomic, strong) CAGradientLayer *bgLayer;
|
|
/// 封面图
|
|
@property (nonatomic, strong) NetImageView *coverImageView;
|
|
/// 点赞图标
|
|
@property (nonatomic, strong) UIButton *likeBtn;
|
|
/// 点赞数量
|
|
@property (nonatomic, strong) UILabel *countLabel;
|
|
/// 标题
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
/// 头像
|
|
@property (nonatomic, strong) NetImageView *avatarImageView;
|
|
/// 昵称
|
|
@property (nonatomic, strong) UILabel *nickLabel;
|
|
@property (nonatomic, strong) UIView *livingView;
|
|
@property (nonatomic, strong) SVGAPlayer *noteView;
|
|
|
|
@end
|
|
|
|
@implementation XPMomentListCollectionViewCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
self.contentView.layer.cornerRadius = 12;
|
|
self.contentView.clipsToBounds = YES;
|
|
[self createUI];
|
|
|
|
SVGAParser *parser = [[SVGAParser alloc] init];
|
|
[parser parseWithNamed:@"moment_living" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
if (videoItem != nil) {
|
|
self.noteView.videoItem = videoItem;
|
|
[self.noteView startAnimation];
|
|
}
|
|
} failureBlock:nil];
|
|
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)layoutSubviews {
|
|
[super layoutSubviews];
|
|
self.bgLayer.frame = CGRectMake(0, self.contentView.bounds.size.height-78, self.contentView.bounds.size.width, 78);
|
|
}
|
|
|
|
- (void)createUI {
|
|
[self.contentView addSubview:self.coverImageView];
|
|
[self.contentView.layer addSublayer:self.bgLayer];
|
|
[self.contentView addSubview:self.likeBtn];
|
|
[self.contentView addSubview:self.countLabel];
|
|
[self.contentView addSubview:self.titleLabel];
|
|
[self.contentView addSubview:self.avatarImageView];
|
|
[self.contentView addSubview:self.nickLabel];
|
|
|
|
[self.avatarImageView addSubview:self.livingView];
|
|
[self.livingView addSubview:self.noteView];
|
|
|
|
[self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.contentView);
|
|
}];
|
|
[self.likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.countLabel.mas_left).offset(-2);
|
|
make.centerY.mas_equalTo(self.countLabel);
|
|
make.width.mas_equalTo(14);
|
|
make.height.mas_equalTo(14);
|
|
}];
|
|
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.avatarImageView);
|
|
make.right.mas_equalTo(-10);
|
|
}];
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(10);
|
|
make.bottom.mas_equalTo(self.avatarImageView.mas_top).offset(-4);
|
|
make.right.mas_equalTo(-10);
|
|
}];
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(10);
|
|
make.bottom.mas_equalTo(-10);
|
|
make.width.height.mas_equalTo(24);
|
|
}];
|
|
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.avatarImageView);
|
|
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(4);
|
|
}];
|
|
[self.livingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.bottom.mas_equalTo(0);
|
|
make.height.mas_equalTo(10);
|
|
}];
|
|
[self.noteView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.center.mas_equalTo(0);
|
|
make.size.mas_equalTo(CGSizeMake(8, 8));
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Action
|
|
///点赞
|
|
- (void)likeBtnAction {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMomentListCollectionViewCellDidClickLike:)]) {
|
|
[self.delegate xPMomentListCollectionViewCellDidClickLike:self.monentsInfo];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setMonentsInfo:(MonentsInfoModel *)monentsInfo {
|
|
_monentsInfo = monentsInfo;
|
|
if (_monentsInfo) {
|
|
if (_monentsInfo.dynamicResList.count > 0) {
|
|
MonentsPicInfoModel * picInfo = [_monentsInfo.dynamicResList safeObjectAtIndex1:0];
|
|
self.coverImageView.imageUrl = picInfo.resUrl;
|
|
}else{
|
|
self.coverImageView.imageUrl = _monentsInfo.avatar;
|
|
}
|
|
self.avatarImageView.imageUrl = _monentsInfo.avatar;
|
|
NSString *nick = _monentsInfo.nick;
|
|
if (nick.length > 6) {
|
|
nick = [NSString stringWithFormat:@"%@…", [nick substringToIndex:6]];
|
|
}
|
|
self.nickLabel.text = nick.length > 0 ? nick : @"";
|
|
self.titleLabel.text = _monentsInfo.content;
|
|
self.likeBtn.selected = _monentsInfo.isLike;
|
|
self.countLabel.text = _monentsInfo.likeCount.length > 0 ? _monentsInfo.likeCount : @"0";
|
|
if ([_monentsInfo.inRoomUid integerValue] == 0) {
|
|
self.livingView.hidden = YES;
|
|
}else{
|
|
self.livingView.hidden = NO;
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark - 懒加载
|
|
|
|
- (CAGradientLayer *)bgLayer {
|
|
if (!_bgLayer) {
|
|
_bgLayer = [[CAGradientLayer alloc] init];
|
|
_bgLayer.colors = @[(__bridge id)[UIColor.blackColor colorWithAlphaComponent:0].CGColor, (__bridge id)[UIColor.blackColor colorWithAlphaComponent:0.4].CGColor];
|
|
_bgLayer.locations = @[@0, @1];
|
|
_bgLayer.startPoint = CGPointMake(0.5, 0);
|
|
_bgLayer.endPoint = CGPointMake(0.5, 1);
|
|
}
|
|
return _bgLayer;
|
|
}
|
|
|
|
- (NetImageView *)coverImageView {
|
|
if (!_coverImageView) {
|
|
_coverImageView = [[NetImageView alloc] init];
|
|
_coverImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
}
|
|
return _coverImageView;
|
|
}
|
|
|
|
- (UIButton *)likeBtn {
|
|
if (!_likeBtn) {
|
|
_likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_likeBtn setImage:[UIImage imageNamed:@"monents_info_like_count_normal"] forState:UIControlStateNormal];
|
|
[_likeBtn setImage:[UIImage imageNamed:@"monents_info_like_count_select"] forState:UIControlStateSelected];
|
|
[_likeBtn addTarget:self action:@selector(likeBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
|
[_likeBtn setEnlargeEdgeWithTop:8 right:8 bottom:8 left:8];
|
|
}
|
|
return _likeBtn;
|
|
}
|
|
|
|
- (UILabel *)countLabel {
|
|
if (!_countLabel) {
|
|
_countLabel = [[UILabel alloc] init];
|
|
_countLabel.textColor = UIColor.whiteColor;
|
|
_countLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
}
|
|
return _countLabel;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.textColor = UIColor.whiteColor;
|
|
_titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (NetImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc] init];
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
config.imageType = ImageTypeUserIcon;
|
|
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_avatarImageView.userInteractionEnabled = YES;
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
_avatarImageView.layer.cornerRadius = 24/2;
|
|
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_avatarImageView.layer.borderWidth = 1;
|
|
_avatarImageView.layer.borderColor = [UIColor colorWithWhite:0.8 alpha:1].CGColor;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UILabel *)nickLabel {
|
|
if (!_nickLabel) {
|
|
_nickLabel = [[UILabel alloc] init];
|
|
_nickLabel.textColor = UIColor.whiteColor;
|
|
_nickLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
|
|
}
|
|
return _nickLabel;
|
|
}
|
|
|
|
- (UIView *)livingView {
|
|
if (!_livingView) {
|
|
_livingView = [[UIView alloc] init];
|
|
_livingView.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
|
|
_livingView.hidden = YES;
|
|
}
|
|
return _livingView;
|
|
}
|
|
|
|
- (SVGAPlayer *)noteView {
|
|
if (!_noteView) {
|
|
_noteView = [[SVGAPlayer alloc] init];
|
|
}
|
|
return _noteView;
|
|
}
|
|
|
|
@end
|