Files
peko-ios/YuMi/Modules/YMMessage/View/Session/Cell/MSSessionPublicChatHalIRightmageCell.m

186 lines
6.3 KiB
Mathematica
Raw Normal View History

2024-05-17 11:27:36 +08:00
//
// MSSessionPublicChatHalIRightmageCell.m
// YuMi
//
// Created by duoban on 2024/5/16.
//
#import "MSSessionPublicChatHalIRightmageCell.h"
#import "DJDKMIMOMColor.h"
#import "NSObject+MJExtension.h"
#import "QEmotionHelper.h"
#import <NIMSDK/NIMSDK.h>
#import <Masonry/Masonry.h>
#import "SpriteSheetImageManager.h"
#import "MessageHeadlinesTextModel.h"
#import "XPMessageRemoteExtModel.h"
#import "MSSessionPublicChatHalImageCell.h"
#import "MSSessionPublicChatHalImageModel.h"
#import "SDPhotoBrowser.h"
#import "MessageContentChatHallHeadView.h"
@interface MSSessionPublicChatHalIRightmageCell()
@property(nonatomic,strong) MSSessionPublicChatHalImageModel * imageModel;
@property(nonatomic,strong) MessageContentChatHallHeadView *avatarView;
@property(nonatomic,strong) UIImageView *bgImageView;
///
@property (nonatomic,strong) NetImageView *bubbleImageView;
@property(nonatomic,strong) NetImageView *picImageView;
@end
@implementation MSSessionPublicChatHalIRightmageCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
self.contentView.backgroundColor = [UIColor clearColor];
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = 0;
[self.contentView addSubview:self.avatarView];
[self.contentView addSubview:self.bgImageView];
[self.contentView addSubview:self.bubbleImageView];
[self.contentView addSubview:self.picImageView];
}
-(void)installConstraints{
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.trailing.top.equalTo(self.contentView);
make.height.mas_equalTo(kGetScaleWidth(48));
}];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-kGetScaleWidth(72));
make.width.mas_equalTo(kGetScaleWidth(52));
make.height.mas_equalTo(kGetScaleWidth(36));
make.top.mas_equalTo(kGetScaleWidth(55));
}];
[self.bubbleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.bgImageView);
}];
[self.picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.bgImageView).with.insets(UIEdgeInsetsMake(kGetScaleWidth(10),kGetScaleWidth(10),kGetScaleWidth(10),kGetScaleWidth(10)));
}];
}
#pragma mark -
- (void)render:(nonnull MessageBaseModel *)model {
MSSessionPublicChatHalImageModel * imageModel = (MSSessionPublicChatHalImageModel *)model;
self.imageModel = imageModel;
XPMessageRemoteExtModel *extModel = imageModel.extModel;
if(extModel == nil)return;
[self.avatarView render:model];
[self.picImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(model.contentSize.height);
make.width.mas_equalTo(model.contentSize.width);
}];
if (imageModel.image) {
self.picImageView.image = imageModel.image;
}else {
[self.picImageView loadImageWithUrl:imageModel.imageUrl completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
self.picImageView.image = image;
}];
}
[self.bgImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(55));
make.trailing.mas_equalTo(-kGetScaleWidth(72));
make.width.mas_equalTo(model.contentSize.width+kGetScaleWidth(10));
make.height.mas_equalTo(model.contentSize.height+kGetScaleWidth(10));
make.bottom.mas_equalTo(-kGetScaleWidth(10));
}];
}
#pragma mark - SDPhotoBrowserDelegate
- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
return [NSURL URLWithString:self.imageModel.url];
}
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
return [UIImageConstant defalutBannerPlaceholder];
}
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageForIndex:(NSInteger)index{
if(self.imageModel.url == nil && self.imageModel.image != nil){
return self.imageModel.image;
}
return nil;
}
-(void)didLeftTapImage{
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init];
browser.sourceImagesContainerView = self;
browser.delegate = self;
browser.imageCount = 1;
browser.currentImageIndex = 0;
browser.isMe = NO;
[browser show];
}
-(void)didRigthTapImage{
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init];
browser.sourceImagesContainerView = self;
browser.delegate = self;
browser.imageCount = 1;
browser.currentImageIndex = 0;
browser.isMe = NO;
[browser show];
}
- (UIImage*)resizableImage:(UIImage *)image {
//
CGFloat top = (image.size.height - 1) / 2;
CGFloat left = (image.size.width - 1) / 2;
CGFloat right = (image.size.width - 1) / 2;
CGFloat bottom = (image.size.height - 1) / 2;
return [image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch];
}
- (MessageContentChatHallHeadView *)avatarView{
if(!_avatarView){
_avatarView = [[MessageContentChatHallHeadView alloc]initWithFrame:CGRectZero isSelf:NO];
}
return _avatarView;
}
- (UIImageView *)bgImageView{
if(!_bgImageView){
_bgImageView = [UIImageView new];
_bgImageView.userInteractionEnabled = YES;
_bgImageView.image = [self resizableImage:kImage(@"ms_message_headlines_text_left")];
}
return _bgImageView;
}
- (NetImageView *)bubbleImageView{
if(!_bubbleImageView){
_bubbleImageView = [[NetImageView alloc] init];
}
return _bubbleImageView;
}
- (NetImageView *)picImageView{
if(!_picImageView){
_picImageView = [NetImageView new];
_picImageView.userInteractionEnabled = YES;
_picImageView.layer.masksToBounds = YES;
_picImageView.contentMode = UIViewContentModeScaleAspectFill;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didLeftTapImage)];
[_picImageView addGestureRecognizer:tap];
}
return _picImageView;
}
@end