Files
yinmeng-ios/xplan-ios/Main/Monents/View/Cell/XPMonentsTableViewCell.m

265 lines
9.0 KiB
Mathematica
Raw Normal View History

2022-05-11 16:32:10 +08:00
//
// XPMonentsTableViewCell.m
// xplan-ios
//
// Created by on 2022/5/11.
//
#import "XPMonentsTableViewCell.h"
2022-05-12 18:15:15 +08:00
///Third
#import <Masonry/Masonry.h>
2022-05-13 11:32:35 +08:00
2022-05-12 18:15:15 +08:00
///Tool
#import "ThemeColor.h"
#import "NetImageView.h"
#import "XPMonentsLayoutConfig.h"
2022-06-27 20:04:54 +08:00
#import "SDPhotoBrowser.h"
2022-08-18 16:39:14 +08:00
#import "XCCurrentVCStackManager.h"
2022-11-11 17:46:37 +08:00
#import "NSArray+Safe.h"
2022-05-12 18:15:15 +08:00
///Model
#import "MonentsInfoModel.h"
///View
#import "XPMonentsUserInfoView.h"
#import "XPMonentsPhotoView.h"
#import "XPMonentsTooBarView.h"
#import "XPMoentsTopicView.h"
2022-05-13 11:32:35 +08:00
#import "XPMonentsContentView.h"
#import "XPMonentsLayoutConfig.h"
2022-08-18 16:39:14 +08:00
#import "XPMonentTopicContainerViewController.h"
2022-08-24 15:51:41 +08:00
#import "XPMineUserInfoViewController.h"
#import "XPRoomViewController.h"
2022-08-25 21:17:23 +08:00
@interface XPMonentsTableViewCell ()<XPMonentsTooBarViewDelegate, XPMonentsTooBarViewDelegate, XPMonentsPhotoViewDelegate, SDPhotoBrowserDelegate, XPMonentsUserInfoViewDelegate, XPMonentsContentViewDelegate>
2022-05-12 18:15:15 +08:00
/// stackView
@property (nonatomic,strong) UIView * backView;
///
@property (nonatomic,strong) UIStackView *stackView;
///
@property (nonatomic,strong) XPMonentsUserInfoView * userInfoView;
2022-05-13 11:32:35 +08:00
///
@property (nonatomic,strong) XPMonentsContentView *textView;
2022-05-12 18:15:15 +08:00
///
@property (nonatomic,strong) XPMonentsPhotoView *photoView;
///
@property (nonatomic,strong) XPMonentsTooBarView *toolBarView;
///
@property (nonatomic,strong) XPMoentsTopicView *topicView;
2022-05-11 16:32:10 +08:00
@end
@implementation XPMonentsTableViewCell
2022-05-12 18:15:15 +08:00
- (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 = [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];
2022-05-13 11:32:35 +08:00
[self.stackView addArrangedSubview:self.textView];
2022-05-12 18:15:15 +08:00
[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) {
2022-05-13 11:32:35 +08:00
make.left.right.top.mas_equalTo(self.backView);
2022-05-12 18:15:15 +08:00
make.height.mas_equalTo(kMONENTS_USER_INFO_HEIGHT);
}];
2022-08-26 17:13:20 +08:00
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(20);
}];
2022-05-12 18:15:15 +08:00
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backView).offset(kMONENTS_CONTENT_LEFT_PADDING);
2022-05-17 00:20:01 +08:00
make.right.mas_equalTo(self.backView).offset(-kMONENTS_CONTENT_RIGHT_PADDING);
2022-05-12 18:15:15 +08:00
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.left.right.mas_equalTo(self.backView);
make.top.mas_equalTo(self.stackView.mas_bottom);
make.height.mas_equalTo(kMONENTS_TOOL_BAR_HEIGHT);
}];
}
2022-08-24 15:51:41 +08:00
#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];
}
2022-05-12 18:15:15 +08:00
2022-06-24 18:51:04 +08:00
#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];
}
}
2022-08-24 15:51:41 +08:00
- (void)xPMonentsTooBarView:(XPMonentsTooBarView *)view didClickDelete:(MonentsInfoModel *)monentsInfo {
2022-08-25 21:17:23 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClicDelete:)]) {
2022-08-24 15:51:41 +08:00
[self.delegate xPMonentsTableViewCell:self didClicDelete:self.monentsInfo];
}
}
2022-08-25 21:17:23 +08:00
- (void)xPMonentsTooBarView:(XPMonentsTooBarView *)view didClickCommon:(MonentsInfoModel *)monentsInfo {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClicCommon:)]) {
[self.delegate xPMonentsTableViewCell:self didClicCommon:self.monentsInfo];
}
}
#pragma mark - XPMonentsContentViewDelegate
- (void)xPMonentsContentView:(XPMonentsContentView *)view didClickFold:(MonentsInfoModel *)monentsInfo {
2022-08-26 17:13:20 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClicFold:)]) {
[self.delegate xPMonentsTableViewCell:self didClicFold:monentsInfo];
}
2022-08-25 21:17:23 +08:00
}
2022-06-27 20:04:54 +08:00
#pragma mark - SDPhotoBrowserDelegate
- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
2022-11-11 17:46:37 +08:00
MonentsPicInfoModel *picinfo = [self.monentsInfo.dynamicResList safeObjectAtIndex1:index];
2022-06-27 20:04:54 +08:00
return [NSURL URLWithString:picinfo.resUrl];
}
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
return [UIImageConstant defalutBannerPlaceholder];
}
#pragma mark - XPMonentsPhotoViewDelegate
- (void)xPMonentsPhotoView:(XPMonentsPhotoView *)view didClickImage:(NSInteger)index {
NSInteger count = self.monentsInfo.dynamicResList.count;
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init];
browser.sourceImagesContainerView = self;
browser.delegate = self;
browser.imageCount = count;
browser.currentImageIndex = index;
browser.isMe = NO;
[browser show];
}
2022-08-18 16:39:14 +08:00
#pragma mark - Event Response
- (void)didTapTopicRecognizer {
if (self.monentsInfo.worldId > 0) {
XPMonentTopicContainerViewController * topicListVC = [[XPMonentTopicContainerViewController alloc] init];
2022-08-24 15:51:41 +08:00
topicListVC.worldId = [NSString stringWithFormat:@"%ld", self.monentsInfo.worldId];
2022-08-18 16:39:14 +08:00
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:topicListVC animated:YES];
}
}
2022-05-12 18:15:15 +08:00
#pragma mark - Getters And Setters
- (void)setMonentsInfo:(MonentsInfoModel *)monentsInfo {
_monentsInfo = monentsInfo;
if (_monentsInfo) {
self.userInfoView.monentsInfo = _monentsInfo;
2022-05-13 11:32:35 +08:00
self.textView.monentsInfo = _monentsInfo;
2022-05-12 18:15:15 +08:00
self.photoView.dynamicResList = _monentsInfo.dynamicResList;
self.topicView.monentsInfo = _monentsInfo;
self.toolBarView.monentsInfo = _monentsInfo;
2022-08-26 17:13:20 +08:00
if (_monentsInfo.type == MonentsContentType_Picture) {
self.photoView.hidden = NO;
CGFloat picHeight = _monentsInfo.picHeight <=0 ? [XPMonentsLayoutConfig monentsPicHeight:_monentsInfo] : _monentsInfo.picHeight;
2022-05-17 00:20:01 +08:00
[self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
2022-08-26 17:13:20 +08:00
make.height.mas_equalTo(picHeight);
2022-05-13 11:32:35 +08:00
}];
} else {
2022-08-31 18:27:27 +08:00
self.photoView.hidden = YES;
2022-05-17 00:20:01 +08:00
[self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
2022-08-26 17:13:20 +08:00
make.height.mas_equalTo(0);
2022-05-13 11:32:35 +08:00
}];
}
2022-08-31 18:27:27 +08:00
CGFloat contentHeight = [XPMonentsLayoutConfig monentsContentHeight:_monentsInfo];
2022-05-17 00:20:01 +08:00
[self.textView mas_updateConstraints:^(MASConstraintMaker *make) {
2022-05-13 11:32:35 +08:00
make.height.mas_equalTo(contentHeight);
}];
2022-05-12 18:15:15 +08:00
}
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [ThemeColor appCellBackgroundColor];
}
return _backView;
}
- (XPMonentsUserInfoView *)userInfoView {
if (!_userInfoView) {
_userInfoView = [[XPMonentsUserInfoView alloc] init];
2022-08-24 15:51:41 +08:00
_userInfoView.delegate = self;
2022-05-12 18:15:15 +08:00
}
return _userInfoView;
}
- (XPMonentsPhotoView *)photoView {
if (!_photoView) {
_photoView = [[XPMonentsPhotoView alloc] init];
2022-06-27 20:04:54 +08:00
_photoView.delegate = self;
2022-05-12 18:15:15 +08:00
}
return _photoView;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
2022-05-13 11:32:35 +08:00
_stackView.axis = UILayoutConstraintAxisVertical;
2022-05-12 18:15:15 +08:00
_stackView.distribution = UIStackViewDistributionFill;
2022-05-17 00:20:01 +08:00
_stackView.alignment = UIStackViewAlignmentFill;
2022-05-12 18:15:15 +08:00
_stackView.spacing = kMONENTS_CONTENT_SPACAE_HEIGHT;
}
return _stackView;
}
2022-05-13 11:32:35 +08:00
- (XPMonentsContentView *)textView {
if (!_textView) {
_textView = [[XPMonentsContentView alloc] init];
2022-08-25 21:17:23 +08:00
_textView.delegate = self;
2022-05-13 11:32:35 +08:00
}
return _textView;
}
2022-05-12 18:15:15 +08:00
- (XPMoentsTopicView *)topicView {
if (!_topicView) {
_topicView = [[XPMoentsTopicView alloc] init];
2022-08-18 16:39:14 +08:00
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapTopicRecognizer)];
[_topicView addGestureRecognizer:tap];
2022-05-12 18:15:15 +08:00
}
return _topicView;
}
2022-05-11 16:32:10 +08:00
2022-05-12 18:15:15 +08:00
- (XPMonentsTooBarView *)toolBarView {
if (!_toolBarView) {
_toolBarView = [[XPMonentsTooBarView alloc] init];
2022-06-24 18:51:04 +08:00
_toolBarView.delegate = self;
2022-05-12 18:15:15 +08:00
}
return _toolBarView;
}
2022-05-11 16:32:10 +08:00
@end