416 lines
15 KiB
Objective-C
416 lines
15 KiB
Objective-C
//
|
|
// XPMonentsTableViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/5/11.
|
|
//
|
|
|
|
#import "XPMonentsTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
|
|
///Tool
|
|
#import "NetImageView.h"
|
|
#import "XPMonentsLayoutConfig.h"
|
|
#import "SDPhotoBrowser.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
///Model
|
|
#import "MonentsInfoModel.h"
|
|
///View
|
|
#import "XPMonentsUserInfoView.h"
|
|
#import "XPMonentsPhotoView.h"
|
|
#import "XPMonentsTooBarView.h"
|
|
#import "XPMoentsTopicView.h"
|
|
#import "XPMonentsContentView.h"
|
|
#import "XPMonentsLayoutConfig.h"
|
|
#import "XPMonentTopicContainerViewController.h"
|
|
#import "XPMineUserInfoViewController.h"
|
|
#import "XPRoomViewController.h"
|
|
@interface XPMonentsTableViewCell ()<XPMonentsTooBarViewDelegate, XPMonentsTooBarViewDelegate, XPMonentsPhotoViewDelegate, SDPhotoBrowserDelegate, XPMonentsUserInfoViewDelegate, XPMonentsContentViewDelegate>
|
|
///显示颜色的 有的时候stackView 不能显示颜色
|
|
@property (nonatomic,strong) UIView * backView;
|
|
///容器
|
|
@property (nonatomic,strong) UIStackView *stackView;
|
|
///用户信息
|
|
@property (nonatomic,strong) XPMonentsUserInfoView * userInfoView;
|
|
///显示内容的
|
|
@property (nonatomic,strong) XPMonentsContentView *textView;
|
|
///图片
|
|
@property (nonatomic,strong) XPMonentsPhotoView *photoView;
|
|
///显示底部的操作栏
|
|
@property (nonatomic,strong) XPMonentsTooBarView *toolBarView;
|
|
///话题
|
|
@property (nonatomic,strong) XPMoentsTopicView *topicView;
|
|
@property (nonatomic,strong) UIView *lineView;
|
|
|
|
@end
|
|
|
|
@implementation XPMonentsTableViewCell
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
if ([reuseIdentifier isEqualToString:@"XPMonentsDynamicTableViewCell"]) {
|
|
[self initDynamicSubViews];
|
|
[self initDynamicSubViewConstraints];
|
|
|
|
}else{
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
|
|
- (void)initDynamicSubViews {
|
|
self.backgroundColor = [UIColor clearColor];
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
[self.contentView addSubview:self.backView];
|
|
|
|
|
|
[self.backView addSubview:self.stackView];
|
|
[self.backView addSubview:self.toolBarView];
|
|
|
|
[self.stackView addArrangedSubview:self.textView];
|
|
[self.stackView addArrangedSubview:self.photoView];
|
|
[self.stackView addArrangedSubview:self.topicView];
|
|
|
|
[self.contentView addSubview:self.lineView];
|
|
}
|
|
|
|
- (void)initDynamicSubViewConstraints {
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(15);
|
|
make.trailing.mas_equalTo(-15);
|
|
make.top.bottom.equalTo(self.contentView);
|
|
}];
|
|
|
|
|
|
|
|
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(20);
|
|
}];
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.backView).offset(12);
|
|
make.trailing.mas_equalTo(self.backView).offset(-12);
|
|
make.top.mas_equalTo(13);
|
|
}];
|
|
|
|
[self.topicView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(kMONENTS_TEXT_TOPIC_HEIGHT);
|
|
}];
|
|
[self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(KScreenWidth-30);
|
|
}];
|
|
[self.toolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.mas_equalTo(self.backView);
|
|
make.top.mas_equalTo(self.stackView.mas_bottom).mas_offset(10);
|
|
make.height.mas_equalTo(18);
|
|
}];
|
|
|
|
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(kGetScaleWidth(1));
|
|
make.leading.trailing.equalTo(self.toolBarView).inset(12);
|
|
make.bottom.equalTo(self.contentView);
|
|
}];
|
|
}
|
|
|
|
- (void)initSubViews {
|
|
self.backgroundColor = [UIColor clearColor];
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
[self.contentView addSubview:self.backView];
|
|
|
|
[self.backView addSubview:self.userInfoView];
|
|
[self.backView addSubview:self.stackView];
|
|
[self.backView addSubview:self.toolBarView];
|
|
|
|
[self.stackView addArrangedSubview:self.textView];
|
|
[self.stackView addArrangedSubview:self.photoView];
|
|
[self.stackView addArrangedSubview:self.topicView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.contentView);
|
|
}];
|
|
|
|
[self.userInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.top.mas_equalTo(self.backView);
|
|
make.height.mas_equalTo(kMONENTS_USER_INFO_HEIGHT);
|
|
}];
|
|
|
|
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(20);
|
|
}];
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.backView).offset(kMONENTS_CONTENT_LEFT_PADDING);
|
|
make.trailing.mas_equalTo(self.backView).offset(-kMONENTS_CONTENT_RIGHT_PADDING);
|
|
make.top.mas_equalTo(self.userInfoView.mas_bottom).offset(kMONENTS_CONTENT_SPACAE_HEIGHT);
|
|
}];
|
|
|
|
[self.topicView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(kMONENTS_TEXT_TOPIC_HEIGHT);
|
|
}];
|
|
|
|
[self.toolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.mas_equalTo(self.backView);
|
|
make.top.mas_equalTo(self.stackView.mas_bottom);
|
|
make.height.mas_equalTo(kMONENTS_TOOL_BAR_HEIGHT);
|
|
}];
|
|
|
|
|
|
}
|
|
#pragma mark - XPMonentsUserInfoViewDelegate
|
|
- (void)xPMonentsUserInfoView:(XPMonentsUserInfoView *)view didClickEnterRoom:(MonentsInfoModel *)monents {
|
|
if (monents.inRoomUid.integerValue > 0) {
|
|
[XPRoomViewController openRoom:monents.inRoomUid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
|
|
}
|
|
}
|
|
|
|
- (void)xPMonentsUserInfoView:(XPMonentsUserInfoView *)view didClickAvatar:(MonentsInfoModel *)monents {
|
|
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
|
|
userInfoVC.uid = monents.uid.integerValue;
|
|
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:userInfoVC animated:YES];
|
|
}
|
|
|
|
- (void)xPMonentsTooBarView:(XPMonentsUserInfoView *)view didClickDelete:(MonentsInfoModel *)monentsInfo {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClicDelete:)]) {
|
|
[self.delegate xPMonentsTableViewCell:self didClicDelete:monentsInfo];
|
|
}
|
|
}
|
|
|
|
#pragma mark - XPMonentsTooBarViewDelegate
|
|
- (void)xPMonentsTooBarView:(XPMonentsTooBarView *)view didClickLike:(MonentsInfoModel *)monentsInfo {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClickLike:)]) {
|
|
[self.delegate xPMonentsTableViewCell:self didClickLike:monentsInfo];
|
|
}
|
|
}
|
|
|
|
- (void)xPMonentsTooBarView:(XPMonentsTooBarView *)view didClickCommon:(MonentsInfoModel *)monentsInfo {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClicCommon:)]) {
|
|
[self.delegate xPMonentsTableViewCell:self didClicCommon:monentsInfo];
|
|
}
|
|
}
|
|
- (void)xPMonentsTooBarView:(XPMonentsTooBarView *)view didClickShielding:(MonentsInfoModel *)monentsInfo{
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClicShielding:)]) {
|
|
[self.delegate xPMonentsTableViewCell:self didClicShielding:monentsInfo];
|
|
}
|
|
}
|
|
#pragma mark - XPMonentsContentViewDelegate
|
|
- (void)xPMonentsContentView:(XPMonentsContentView *)view didClickFold:(MonentsInfoModel *)monentsInfo {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClicFold:)]) {
|
|
[self.delegate xPMonentsTableViewCell:self didClicFold:monentsInfo];
|
|
}
|
|
}
|
|
|
|
#pragma mark - SDPhotoBrowserDelegate
|
|
- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
|
|
|
|
NSArray *list = self.monentsInfo != nil ? self.monentsInfo.dynamicResList : self.mineMonentsInfo.dynamicResList;
|
|
if(index < list.count){
|
|
MonentsPicInfoModel *picinfo = [list safeObjectAtIndex1:index];
|
|
return [NSURL URLWithString:picinfo.resUrl];
|
|
}
|
|
return [NSURL URLWithString:@""];;
|
|
}
|
|
|
|
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
|
|
return [UIImageConstant defalutBannerPlaceholder];
|
|
}
|
|
|
|
#pragma mark - XPMonentsPhotoViewDelegate
|
|
- (void)xPMonentsPhotoView:(XPMonentsPhotoView *)view didClickImage:(NSInteger)index {
|
|
NSInteger count = self.monentsInfo != nil ? self.monentsInfo.dynamicResList.count : self.mineMonentsInfo.dynamicResList.count;
|
|
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init];
|
|
browser.sourceImagesContainerView = self;
|
|
browser.delegate = self;
|
|
browser.imageCount = count;
|
|
browser.currentImageIndex = index;
|
|
browser.isMe = NO;
|
|
[browser show];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)didTapTopicRecognizer {
|
|
long worldId = self.monentsInfo != nil ? self.monentsInfo.worldId : self.mineMonentsInfo.worldId;
|
|
if (worldId > 0) {
|
|
XPMonentTopicContainerViewController * topicListVC = [[XPMonentTopicContainerViewController alloc] init];
|
|
topicListVC.worldId = [NSString stringWithFormat:@"%ld", worldId];
|
|
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:topicListVC animated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setIsFillet:(BOOL)isFillet{
|
|
_isFillet = isFillet;
|
|
|
|
if(_isFillet == YES){
|
|
_lineView.hidden = YES;
|
|
[_backView setCornerWithLeftTopCorner:0 rightTopCorner:0 bottomLeftCorner:8 bottomRightCorner:8 size:CGSizeMake(KScreenWidth-30, self.frame.size.height)];
|
|
}else{
|
|
_lineView.hidden = NO;
|
|
if(_backView.layer.mask != nil){
|
|
_backView.layer.mask = nil;
|
|
}
|
|
|
|
}
|
|
}
|
|
-(void)setMineMonentsInfo:(MonentsInfoModel *)mineMonentsInfo{
|
|
_mineMonentsInfo = mineMonentsInfo;
|
|
if (_mineMonentsInfo) {
|
|
self.userInfoView.monentsInfo = _mineMonentsInfo;
|
|
self.textView.monentsInfo = _mineMonentsInfo;
|
|
self.photoView.mineDynamicResList = _mineMonentsInfo.dynamicResList;
|
|
self.topicView.monentsInfo = _mineMonentsInfo;
|
|
self.toolBarView.monentsInfo = _mineMonentsInfo;
|
|
if (_mineMonentsInfo.type == MonentsContentType_Picture) {
|
|
self.photoView.hidden = NO;
|
|
CGFloat picHeight = _mineMonentsInfo.picHeight <=0 ? [XPMonentsLayoutConfig monentsPicHeight:_mineMonentsInfo] : _mineMonentsInfo.picHeight;
|
|
[self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(picHeight);
|
|
}];
|
|
} else {
|
|
self.photoView.hidden = YES;
|
|
[self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(0);
|
|
}];
|
|
}
|
|
|
|
CGFloat contentHeight = [XPMonentsLayoutConfig monentsContentHeight:_mineMonentsInfo] + 24;
|
|
|
|
self.topicView.hidden = _mineMonentsInfo.worldId <= 0;
|
|
|
|
if(_mineMonentsInfo.squareTop && _mineMonentsInfo.content.length == 0){
|
|
[self.textView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(contentHeight + 20);
|
|
}];
|
|
}else{
|
|
[self.textView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(contentHeight);
|
|
}];
|
|
}
|
|
|
|
}
|
|
}
|
|
- (void)setMonentsInfo:(MonentsInfoModel *)monentsInfo {
|
|
_monentsInfo = monentsInfo;
|
|
if (_monentsInfo) {
|
|
self.userInfoView.monentsInfo = _monentsInfo;
|
|
self.textView.isTopic = _isTopic;
|
|
self.textView.monentsInfo = _monentsInfo;
|
|
self.photoView.dynamicResList = _monentsInfo.dynamicResList;
|
|
self.topicView.monentsInfo = _monentsInfo;
|
|
self.toolBarView.monentsInfo = _monentsInfo;
|
|
if (_monentsInfo.type == MonentsContentType_Picture) {
|
|
self.photoView.hidden = NO;
|
|
CGFloat picHeight = _monentsInfo.picHeight <=0 ? [XPMonentsLayoutConfig monentsPicHeight:_monentsInfo] : _monentsInfo.picHeight;
|
|
[self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(picHeight);
|
|
}];
|
|
} else {
|
|
self.photoView.hidden = YES;
|
|
[self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(0);
|
|
}];
|
|
}
|
|
|
|
CGFloat contentHeight = [XPMonentsLayoutConfig monentsContentHeight:_monentsInfo] + 24;
|
|
|
|
self.topicView.hidden = monentsInfo.worldId <= 0;
|
|
|
|
if(_monentsInfo.topicTop && _monentsInfo.content.length == 0){
|
|
[self.textView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(contentHeight + 20);
|
|
}];
|
|
}else{
|
|
[self.textView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(contentHeight);
|
|
}];
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
- (UIView *)backView {
|
|
if (!_backView) {
|
|
_backView = [[UIView alloc] init];
|
|
_backView.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
|
|
}
|
|
return _backView;
|
|
}
|
|
|
|
- (XPMonentsUserInfoView *)userInfoView {
|
|
if (!_userInfoView) {
|
|
_userInfoView = [[XPMonentsUserInfoView alloc] init];
|
|
_userInfoView.delegate = self;
|
|
}
|
|
return _userInfoView;
|
|
}
|
|
|
|
- (XPMonentsPhotoView *)photoView {
|
|
if (!_photoView) {
|
|
_photoView = [[XPMonentsPhotoView alloc] init];
|
|
_photoView.delegate = self;
|
|
}
|
|
return _photoView;
|
|
}
|
|
|
|
- (UIStackView *)stackView {
|
|
if (!_stackView) {
|
|
_stackView = [[UIStackView alloc] init];
|
|
_stackView.axis = UILayoutConstraintAxisVertical;
|
|
_stackView.distribution = UIStackViewDistributionFill;
|
|
_stackView.alignment = UIStackViewAlignmentFill;
|
|
_stackView.spacing = 8;
|
|
}
|
|
return _stackView;
|
|
}
|
|
|
|
- (XPMonentsContentView *)textView {
|
|
if (!_textView) {
|
|
_textView = [[XPMonentsContentView alloc] init];
|
|
_textView.delegate = self;
|
|
}
|
|
return _textView;
|
|
}
|
|
|
|
- (XPMoentsTopicView *)topicView {
|
|
if (!_topicView) {
|
|
_topicView = [[XPMoentsTopicView alloc] initWithFrame:CGRectZero];
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapTopicRecognizer)];
|
|
[_topicView addGestureRecognizer:tap];
|
|
}
|
|
return _topicView;
|
|
}
|
|
|
|
- (XPMonentsTooBarView *)toolBarView {
|
|
if (!_toolBarView) {
|
|
if ([self.reuseIdentifier isEqualToString:@"XPMonentsDynamicTableViewCell"]){
|
|
_toolBarView = [[XPMonentsTooBarView alloc]initDynamicWithFrame:CGRectZero];
|
|
}else{
|
|
_toolBarView = [[XPMonentsTooBarView alloc] init];
|
|
}
|
|
|
|
_toolBarView.delegate = self;
|
|
}
|
|
return _toolBarView;
|
|
}
|
|
- (UIView *)lineView{
|
|
if (!_lineView){
|
|
_lineView = [UIView new];
|
|
_lineView.backgroundColor = UIColorFromRGB(0xF7F7F7);
|
|
}
|
|
return _lineView;
|
|
}
|
|
|
|
|
|
@end
|