155 lines
5.0 KiB
Objective-C
155 lines
5.0 KiB
Objective-C
//
|
|
// MessageContentTreasureFairyView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2023/2/23.
|
|
//
|
|
|
|
#import "MessageContentTreasureFairyView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "NetImageView.h"
|
|
#import "NSObject+MJExtension.h"
|
|
#import "TTPopup.h"
|
|
#import "MessageTreasureFairyModel.h"
|
|
///Model
|
|
#import "TreasureFairyBallInfoModel.h"
|
|
#import "ContentTreasureFairyModel.h"
|
|
///View
|
|
#import "XPTreasureFairyMessageSendView.h"
|
|
@interface MessageContentTreasureFairyView ()
|
|
///显示内容
|
|
@property (nonatomic,strong) NetImageView *ballImageView;
|
|
///
|
|
@property (nonatomic,strong) UIStackView *stackView;
|
|
///显示标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
///查看
|
|
@property (nonatomic,strong) UILabel *checkLabel;
|
|
///消息
|
|
@property (nonatomic,strong) NIMMessage *message;
|
|
@property (nonatomic,strong) ContentTreasureFairyModel *fairyInfo;
|
|
@end
|
|
|
|
@implementation MessageContentTreasureFairyView
|
|
+ (CGFloat)measureHeight:(NIMMessage *)message {
|
|
|
|
return 78 + CONTENT_PADDING_V_TOTAL;
|
|
}
|
|
- (void)initSubViews {
|
|
[super initSubViews];
|
|
[self addSubview:self.backView];
|
|
|
|
[self.backView addSubview:self.ballImageView];
|
|
[self.backView addSubview:self.stackView];
|
|
[self.stackView addArrangedSubview:self.titleLabel];
|
|
[self.stackView addArrangedSubview:self.checkLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[super initSubViewConstraints];
|
|
[self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.bottom.trailing.equalTo(self);
|
|
make.leading.mas_equalTo(self).offset(10);
|
|
make.height.mas_equalTo(78);
|
|
make.width.mas_equalTo(235);
|
|
}];
|
|
|
|
[self.ballImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(62, 62));
|
|
make.leading.mas_equalTo(self.backView);
|
|
make.centerY.mas_equalTo(self.backView);
|
|
}];
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.ballImageView.mas_trailing).offset(12);
|
|
make.centerY.mas_equalTo(self.ballImageView);
|
|
make.trailing.mas_equalTo(self.backView).offset(-10);
|
|
}];
|
|
}
|
|
|
|
- (void)render:(MessageTreasureFairyModel *)model {
|
|
self.message = model.message;
|
|
NIMCustomObject *obj = (NIMCustomObject *)model.message.messageObject;
|
|
AttachmentModel * attach = (AttachmentModel *)obj.attachment;
|
|
ContentTreasureFairyModel * info;
|
|
if (model.message.localExt) {
|
|
info = [ContentTreasureFairyModel modelWithDictionary:model.message.localExt];
|
|
} else {
|
|
info = [ContentTreasureFairyModel modelWithDictionary:attach.data];
|
|
}
|
|
self.fairyInfo = info;
|
|
self.checkLabel.hidden = (attach.second == Custom_Message_Sub_Treasure_Fairy_Send_Fairy || info.isSended || self.message.isOutgoingMsg);
|
|
self.ballImageView.imageUrl = info.elfPicUrl;
|
|
self.titleLabel.text = info.msgContent;
|
|
}
|
|
|
|
- (void)checkRecognizer {
|
|
if (!self.titleLabel.isHidden) {
|
|
XPTreasureFairyMessageSendView * view = [[XPTreasureFairyMessageSendView alloc] init];
|
|
view.fairyInfo = self.fairyInfo;
|
|
@kWeakify(self);
|
|
view.finish = ^(BOOL success,ContentTreasureFairyModel * fairyInfo) {
|
|
@kStrongify(self);
|
|
fairyInfo.isSended = YES;
|
|
self.fairyInfo.isSended = fairyInfo;
|
|
self.message.localExt = [self.fairyInfo model2dictionary];
|
|
[[NIMSDK sharedSDK].conversationManager updateMessage:self.message forSession:self.message.session completion:^(NSError * _Nullable error) {
|
|
if (self.customMessageDelegate && [self.customMessageDelegate respondsToSelector:@selector(updateMessageSuccess:)]) {
|
|
[self.customMessageDelegate updateMessageSuccess:self.message];
|
|
}
|
|
}];
|
|
};
|
|
[TTPopup popupView:view style:TTPopupStyleAlert];
|
|
}
|
|
}
|
|
|
|
- (NetImageView *)ballImageView {
|
|
if (!_ballImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_ballImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_ballImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_ballImageView.layer.masksToBounds = YES;
|
|
}
|
|
return _ballImageView;
|
|
}
|
|
|
|
- (UIStackView *)stackView {
|
|
if (!_stackView) {
|
|
_stackView = [[UIStackView alloc] init];
|
|
_stackView.axis = UILayoutConstraintAxisVertical;
|
|
_stackView.distribution = UIStackViewDistributionFill;
|
|
_stackView.alignment = UIStackViewAlignmentFill;
|
|
_stackView.spacing = 10;
|
|
}
|
|
return _stackView;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.font = [UIFont systemFontOfSize:13];
|
|
_titleLabel.textColor = [DJDKMIMOMColor mainTextColor];
|
|
_titleLabel.numberOfLines = 2;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UILabel *)checkLabel {
|
|
if (!_checkLabel) {
|
|
_checkLabel = [[UILabel alloc] init];
|
|
_checkLabel.text = YMLocalizedString(@"MessageContentTreasureFairyView0");
|
|
_checkLabel.textColor = [DJDKMIMOMColor colorWithHexString:@"#5FCCE4"];
|
|
_checkLabel.font = [UIFont systemFontOfSize:13];
|
|
_checkLabel.textAlignment = NSTextAlignmentLeft;
|
|
_checkLabel.userInteractionEnabled = YES;
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkRecognizer)];
|
|
[_checkLabel addGestureRecognizer:tap];
|
|
}
|
|
return _checkLabel;
|
|
}
|
|
|
|
@end
|