2022-06-22 20:38:57 +08:00
|
|
|
//
|
|
|
|
// XPMonentsCommentTableViewCell.m
|
|
|
|
// xplan-ios
|
|
|
|
//
|
|
|
|
// Created by 冯硕 on 2022/6/22.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "XPMonentsCommentTableViewCell.h"
|
|
|
|
///Third
|
|
|
|
#import <Masonry/Masonry.h>
|
2022-08-17 18:55:45 +08:00
|
|
|
#import <YYText/YYText.h>
|
2022-06-22 20:38:57 +08:00
|
|
|
///Tool
|
|
|
|
#import "NetImageView.h"
|
|
|
|
#import "ThemeColor.h"
|
|
|
|
#import "XPMonentsLayoutConfig.h"
|
2022-06-24 18:51:04 +08:00
|
|
|
#import "NSString+Utils.h"
|
2022-08-17 18:55:45 +08:00
|
|
|
#import "QEmotionHelper.h"
|
2022-08-25 21:17:23 +08:00
|
|
|
#import "AccountInfoStorage.h"
|
2022-11-11 17:46:37 +08:00
|
|
|
#import "NSArray+Safe.h"
|
2022-06-22 20:38:57 +08:00
|
|
|
///Model
|
|
|
|
#import "MonentsCommentModel.h"
|
|
|
|
///View
|
|
|
|
#import "XPMonentsReplyTableViewCell.h"
|
|
|
|
#import "XPMonentsReplyMoreTableViewCell.h"
|
|
|
|
|
2022-08-26 17:13:20 +08:00
|
|
|
@interface XPMonentsCommentTableViewCell ()<UITableViewDelegate, UITableViewDataSource, XPMonentsReplyMoreTableViewCellDelegate, XPMonentsReplyTableViewCellDelegate>
|
2022-06-22 20:38:57 +08:00
|
|
|
///容器
|
|
|
|
@property (nonatomic,strong) UIStackView *stackView;
|
|
|
|
///评论者
|
|
|
|
@property (nonatomic,strong) UIView * commentUserView;
|
|
|
|
///评论者的头像
|
|
|
|
@property (nonatomic,strong) NetImageView *commentAvatarView;
|
|
|
|
///评论者的昵称
|
|
|
|
@property (nonatomic,strong) UILabel *commentNickLabel;
|
2022-08-25 21:17:23 +08:00
|
|
|
///楼主
|
|
|
|
@property (nonatomic,strong) UIImageView *ownerImageView;
|
2022-06-22 20:38:57 +08:00
|
|
|
///评论的内容
|
2022-08-17 18:55:45 +08:00
|
|
|
@property (nonatomic,strong) YYLabel *commentLabel;
|
2022-06-22 20:38:57 +08:00
|
|
|
///时间
|
|
|
|
@property (nonatomic,strong) UILabel *commentDateLabel;
|
|
|
|
///列表
|
|
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
|
|
///容器
|
|
|
|
@property (nonatomic,strong) UIView * lineContainerView;
|
|
|
|
///分割线
|
|
|
|
@property (nonatomic,strong) UIView * lineView;
|
|
|
|
///数据源
|
|
|
|
@property (nonatomic,strong) NSArray *datasource;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XPMonentsCommentTableViewCell
|
|
|
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
|
|
[self initSubViews];
|
|
|
|
[self initSubViewConstraints];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Private Method
|
|
|
|
|
|
|
|
- (void)initSubViews {
|
|
|
|
self.backgroundColor = [ThemeColor appCellBackgroundColor];
|
|
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
[self.contentView addSubview:self.stackView];
|
|
|
|
[self.stackView addArrangedSubview:self.commentUserView];
|
|
|
|
[self.stackView addArrangedSubview:self.tableView];
|
|
|
|
[self.stackView addArrangedSubview:self.lineContainerView];
|
|
|
|
|
|
|
|
[self.lineContainerView addSubview:self.lineView];
|
|
|
|
|
|
|
|
[self.commentUserView addSubview:self.commentAvatarView];
|
|
|
|
[self.commentUserView addSubview:self.commentNickLabel];
|
2022-08-25 21:17:23 +08:00
|
|
|
[self.commentUserView addSubview:self.ownerImageView];
|
2022-06-22 20:38:57 +08:00
|
|
|
[self.commentUserView addSubview:self.commentLabel];
|
|
|
|
[self.commentUserView addSubview:self.commentDateLabel];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.right.left.mas_equalTo(self.contentView).inset(15);
|
|
|
|
make.top.bottom.mas_equalTo(self.contentView);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.lineContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.height.mas_equalTo(1);
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.commentNickLabel);
|
|
|
|
make.top.bottom.right.mas_equalTo(self.lineContainerView);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.commentAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.size.mas_equalTo(CGSizeMake(KMONENTS_COMMENT_AVATAR_WIDTH, KMONENTS_COMMENT_AVATAR_WIDTH));
|
|
|
|
make.left.mas_equalTo(self.commentUserView);
|
|
|
|
make.top.mas_equalTo(self.commentUserView).offset(10);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.commentNickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.commentAvatarView.mas_right).offset(10);
|
|
|
|
make.top.mas_equalTo(self.commentUserView).offset(10);
|
|
|
|
make.height.mas_equalTo(15);
|
2022-08-25 21:17:23 +08:00
|
|
|
}];
|
|
|
|
|
|
|
|
[self.ownerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.size.mas_equalTo(CGSizeMake(32, 15));
|
|
|
|
make.centerY.mas_equalTo(self.commentNickLabel);
|
|
|
|
make.left.mas_equalTo(self.commentNickLabel.mas_right).offset(5);
|
2022-06-22 20:38:57 +08:00
|
|
|
}];
|
|
|
|
|
|
|
|
[self.commentDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.right.mas_equalTo(self.commentUserView);
|
|
|
|
make.centerY.mas_equalTo(self.commentNickLabel);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.commentNickLabel);
|
|
|
|
make.top.mas_equalTo(self.commentNickLabel.mas_bottom).offset(10);
|
|
|
|
make.right.mas_equalTo(self.commentUserView).offset(-kMONENTS_COMMENT_RIGHT_PADDING);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
if (section == 0) {
|
|
|
|
return self.datasource.count;
|
|
|
|
}
|
|
|
|
return self.commentInfo.replyInfo.leftCount > 0 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
if (indexPath.section == 0) {
|
2022-11-11 17:46:37 +08:00
|
|
|
MonentsReplyModel * replayinfo = [self.datasource safeObjectAtIndex1:indexPath.row];
|
2022-06-22 20:38:57 +08:00
|
|
|
return replayinfo.replyRowHeight;
|
|
|
|
}
|
|
|
|
return 44;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
if (indexPath.section == 0) {
|
|
|
|
XPMonentsReplyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsReplyTableViewCell class])];
|
2022-11-11 17:46:37 +08:00
|
|
|
cell.replyInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
|
2022-08-26 17:13:20 +08:00
|
|
|
cell.delegate = self;
|
2022-06-22 20:38:57 +08:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
XPMonentsReplyMoreTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsReplyMoreTableViewCell class])];
|
|
|
|
cell.leftCount = self.commentInfo.replyInfo.leftCount;
|
2022-06-24 18:51:04 +08:00
|
|
|
cell.delegate = self;
|
2022-06-22 20:38:57 +08:00
|
|
|
return cell;
|
2022-08-25 21:17:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
|
if (indexPath.section == 0 && self.datasource.count > 0) {
|
2022-11-11 17:46:37 +08:00
|
|
|
MonentsReplyModel * replyInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
|
2022-08-25 21:17:23 +08:00
|
|
|
if (replyInfo.uid.integerValue != [AccountInfoStorage instance].getUid.integerValue && self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsCommentTableViewCell:didClickCommon:)]) {
|
|
|
|
[self.delegate xPMonentsCommentTableViewCell:self didClickCommon:replyInfo];
|
|
|
|
}
|
|
|
|
}
|
2022-06-22 20:38:57 +08:00
|
|
|
}
|
|
|
|
|
2022-08-26 17:13:20 +08:00
|
|
|
#pragma mark - XPMonentsReplyTableViewCellDelegate
|
|
|
|
- (void)xPMonentsReplyTableViewCell:(XPMonentsReplyTableViewCell *)view didClickAvatar:(MonentsReplyModel *)replyInfo {
|
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsCommentTableViewCell:didClickAvatar:)]) {
|
|
|
|
[self.delegate xPMonentsCommentTableViewCell:self didClickAvatar:replyInfo.uid];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 18:51:04 +08:00
|
|
|
#pragma mark - XPMonentsReplyMoreTableViewCellDelegate
|
|
|
|
- (void)xPMonentsReplyMoreTableViewCellDidClickMoreReply:(XPMonentsReplyMoreTableViewCell *)view {
|
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsCommentTableViewCell:didClickMoreReply:)]) {
|
|
|
|
[self.delegate xPMonentsCommentTableViewCell:self didClickMoreReply:self.commentInfo];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-26 17:13:20 +08:00
|
|
|
#pragma mark - Event Response
|
|
|
|
- (void)tapAvatarRecognizer {
|
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsCommentTableViewCell:didClickAvatar:)]) {
|
|
|
|
[self.delegate xPMonentsCommentTableViewCell:self didClickAvatar:self.commentInfo.uid];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-22 20:38:57 +08:00
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
- (void)setCommentInfo:(MonentsCommentModel *)commentInfo {
|
|
|
|
_commentInfo = commentInfo;
|
|
|
|
if (_commentInfo) {
|
2022-08-25 21:17:23 +08:00
|
|
|
self.ownerImageView.hidden = !_commentInfo.landLordFlag;
|
2022-06-22 20:38:57 +08:00
|
|
|
self.commentAvatarView.imageUrl = _commentInfo.avatar;
|
|
|
|
NSString * nick = _commentInfo.nick;
|
|
|
|
if (nick.length > 8) {
|
|
|
|
nick = [nick substringToIndex:8];
|
|
|
|
}
|
2022-08-17 18:55:45 +08:00
|
|
|
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
|
|
|
|
///内容
|
|
|
|
NSMutableAttributedString * attribute = [faceManager attributedStringByText:_commentInfo.content font:[UIFont systemFontOfSize:15]];
|
|
|
|
self.commentLabel.attributedText = attribute;
|
2022-06-22 20:38:57 +08:00
|
|
|
self.commentNickLabel.text = nick;
|
2022-06-24 18:51:04 +08:00
|
|
|
self.commentDateLabel.text = [NSString stringWithTimeStamp:_commentInfo.publishTime];
|
2022-06-22 20:38:57 +08:00
|
|
|
self.tableView.hidden = _commentInfo.replyInfo.replyList.count <=0;
|
|
|
|
self.datasource = _commentInfo.replyInfo.replyList;
|
|
|
|
[self.tableView reloadData];
|
|
|
|
if (_commentInfo.replyInfo.replyList.count > 0) {
|
|
|
|
NSString * content = _commentInfo.content.length > 0 ? _commentInfo.content : @"";
|
|
|
|
CGFloat commentHeight = [content boundingRectWithSize:CGSizeMake(KMONENTS_COMMENT_MAX_WIDTH, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.height + 5;
|
|
|
|
commentHeight = MAX(commentHeight, 15);
|
|
|
|
[self.commentUserView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.height.mas_equalTo(commentHeight + 10 + 15 + 10);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStackView *)stackView {
|
|
|
|
if (!_stackView) {
|
|
|
|
_stackView = [[UIStackView alloc] init];
|
|
|
|
_stackView.axis = UILayoutConstraintAxisVertical;
|
|
|
|
_stackView.distribution = UIStackViewDistributionFill;
|
|
|
|
_stackView.alignment = UIStackViewAlignmentFill;
|
|
|
|
_stackView.spacing = 10;
|
|
|
|
}
|
|
|
|
return _stackView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)commentUserView {
|
|
|
|
if (!_commentUserView) {
|
|
|
|
_commentUserView = [[UIView alloc] init];
|
|
|
|
_commentUserView.backgroundColor = [UIColor clearColor];
|
|
|
|
}
|
|
|
|
return _commentUserView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NetImageView *)commentAvatarView {
|
|
|
|
if (!_commentAvatarView) {
|
|
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
|
|
config.imageType = ImageTypeUserIcon;
|
|
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
|
|
_commentAvatarView = [[NetImageView alloc] initWithConfig:config];
|
|
|
|
_commentAvatarView.layer.masksToBounds = YES;
|
|
|
|
_commentAvatarView.layer.cornerRadius = 45/2.0;
|
2022-08-26 17:13:20 +08:00
|
|
|
_commentAvatarView.userInteractionEnabled = YES;
|
|
|
|
UITapGestureRecognizer * tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAvatarRecognizer)];
|
|
|
|
[_commentAvatarView addGestureRecognizer:tap];
|
2022-06-22 20:38:57 +08:00
|
|
|
}
|
|
|
|
return _commentAvatarView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UILabel *)commentNickLabel {
|
|
|
|
if (!_commentNickLabel) {
|
|
|
|
_commentNickLabel = [[UILabel alloc] init];
|
|
|
|
_commentNickLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
|
|
|
_commentNickLabel.textColor = [ThemeColor mainTextColor];
|
|
|
|
[_commentNickLabel sizeToFit];
|
|
|
|
}
|
|
|
|
return _commentNickLabel;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:55:45 +08:00
|
|
|
- (YYLabel *)commentLabel {
|
2022-06-22 20:38:57 +08:00
|
|
|
if (!_commentLabel) {
|
2022-08-17 18:55:45 +08:00
|
|
|
_commentLabel = [[YYLabel alloc] init];
|
2022-06-22 20:38:57 +08:00
|
|
|
_commentLabel.font = [UIFont systemFontOfSize:15];
|
|
|
|
_commentLabel.numberOfLines = 0;
|
|
|
|
_commentLabel.textColor = [ThemeColor secondTextColor];
|
2022-08-17 18:55:45 +08:00
|
|
|
_commentLabel.preferredMaxLayoutWidth = KMONENTS_COMMENT_MAX_WIDTH;
|
2022-06-22 20:38:57 +08:00
|
|
|
}
|
|
|
|
return _commentLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UILabel *)commentDateLabel {
|
|
|
|
if (!_commentDateLabel) {
|
|
|
|
_commentDateLabel = [[UILabel alloc] init];
|
|
|
|
_commentDateLabel.font = [UIFont systemFontOfSize:12];
|
|
|
|
_commentDateLabel.textColor = [ThemeColor textThirdColor];
|
|
|
|
}
|
|
|
|
return _commentDateLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableView *)tableView {
|
|
|
|
if (!_tableView) {
|
|
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
|
|
_tableView.delegate = self;
|
|
|
|
_tableView.dataSource = self;
|
|
|
|
_tableView.tableFooterView = [UIView new];
|
|
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
|
|
_tableView.scrollEnabled = NO;
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
|
}
|
|
|
|
[_tableView registerClass:[XPMonentsReplyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsReplyTableViewCell class])];
|
|
|
|
[_tableView registerClass:[XPMonentsReplyMoreTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsReplyMoreTableViewCell class])];
|
|
|
|
}
|
|
|
|
return _tableView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)lineView {
|
|
|
|
if (!_lineView) {
|
|
|
|
_lineView = [[UIView alloc] init];
|
|
|
|
_lineView.backgroundColor = [ThemeColor dividerColor];
|
|
|
|
}
|
|
|
|
return _lineView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)lineContainerView {
|
|
|
|
if (!_lineContainerView) {
|
|
|
|
_lineContainerView = [[UIView alloc] init];
|
|
|
|
_lineContainerView.backgroundColor = [UIColor clearColor];
|
|
|
|
}
|
|
|
|
return _lineContainerView;
|
|
|
|
}
|
|
|
|
|
2022-08-25 21:17:23 +08:00
|
|
|
- (UIImageView *)ownerImageView {
|
|
|
|
if (!_ownerImageView) {
|
|
|
|
_ownerImageView = [[UIImageView alloc] init];
|
|
|
|
_ownerImageView.userInteractionEnabled = YES;
|
|
|
|
_ownerImageView.image = [UIImage imageNamed:@"monents_common_landLordFlag"];
|
|
|
|
_ownerImageView.hidden = YES;
|
|
|
|
}
|
|
|
|
return _ownerImageView;
|
|
|
|
}
|
|
|
|
|
2022-06-22 20:38:57 +08:00
|
|
|
@end
|