Files
peko-ios/YuMi/Modules/YMMessage/View/Session/Content/MessageContentTweetView.m

247 lines
9.8 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// MessageContentTweetView.m
// YUMI
//
// Created by YUMI on 2022/4/28.
//
#import "MessageContentTweetView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "NetImageView.h"
#import "NSObject+MJExtension.h"
#import "XCCurrentVCStackManager.h"
#import "YUMIConstant.h"
///Model
#import "MessageTweetModel.h"
#import "ContentTweetModel.h"
///View
#import "XPWebViewController.h"
#import "XPRoomViewController.h"
@interface MessageContentTweetView ()
///
@property (nonatomic,strong) NetImageView *logoImageView;
///
@property (nonatomic,strong) UILabel *titleLabel;
///线
@property (nonatomic,strong) UIView * lineView;
///
@property (nonatomic,strong) UILabel *subTitleLabel;
///
@property (nonatomic,strong) UIButton *checkButton;
///
@property (nonatomic, strong) UIImageView *isNewImageView;
///
@property (nonatomic,strong) ContentTweetModel *tweetModel;
///ID
@property (nonatomic, copy) NSString *messageId;
@end
@implementation MessageContentTweetView
- (void)render:(MessageBaseModel *)model1 {
2023-10-31 11:09:04 +08:00
MessageTweetModel *obj = (MessageTweetModel *)model1;
ContentTweetModel * model = obj.tweetInfo;
self.tweetModel = model;
2023-07-14 18:50:55 +08:00
self.messageId = model1.message.messageId;
2023-10-31 11:09:04 +08:00
self.logoImageView.imageUrl = model.picUrl;
self.titleLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:model.title attributes:[self messageTextAttibutes:[UIFont systemFontOfSize:16] color:[DJDKMIMOMColor mainTextColor]]];
self.subTitleLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:model.desc attributes:[self messageTextAttibutes:[UIFont systemFontOfSize:13] color:[DJDKMIMOMColor secondTextColor]]];
CGFloat oneHeight = [YMLocalizedString(@"MessageContentTweetView0") boundingRectWithSize:CGSizeMake(240, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
attributes:[self messageTextAttibutes:[UIFont systemFontOfSize:16] color:[DJDKMIMOMColor mainTextColor]] context:nil].size.height + 2.5;
CGFloat titleHeight = [model.title boundingRectWithSize:CGSizeMake(240, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
attributes:[self messageTextAttibutes:[UIFont systemFontOfSize:16] color:[DJDKMIMOMColor mainTextColor]] context:nil].size.height;
if (titleHeight <= oneHeight * 2) {
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(titleHeight + 5);
}];
} else{
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(oneHeight * 2);
}];
}
CGFloat desHeight = [model.desc boundingRectWithSize:CGSizeMake(240, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
2024-02-21 10:18:59 +08:00
attributes:[self messageTextAttibutes:[UIFont systemFontOfSize:13] color:[DJDKMIMOMColor mainTextColor]] context:nil].size.height + 10;
2023-10-31 11:09:04 +08:00
[self.subTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(desHeight);
}];
2023-07-14 18:50:55 +08:00
NSArray *redPacketHistory = [[NSUserDefaults standardUserDefaults] objectForKey:kTuWenMessageHistory];
2023-10-31 11:09:04 +08:00
if ( [redPacketHistory containsObject: model1.message.messageId]) {
2023-07-14 18:50:55 +08:00
self.isNewImageView.hidden = YES;
2023-10-31 11:09:04 +08:00
[self.isNewImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.backView);
make.centerY.equalTo(self.titleLabel);
make.size.mas_equalTo(CGSizeMake(0, 10));
}];
2023-07-14 18:50:55 +08:00
} else {
self.isNewImageView.hidden = NO;
2023-10-31 11:09:04 +08:00
[self.isNewImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.backView);
make.centerY.equalTo(self.titleLabel);
make.size.mas_equalTo(CGSizeMake(24, 10));
}];
2023-07-14 18:50:55 +08:00
}
}
- (NSDictionary<NSAttributedStringKey, id> *)messageTextAttibutes:(UIFont *)font color:(UIColor *)color {
2023-10-31 11:09:04 +08:00
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:2.5];
return @{
NSFontAttributeName:font,
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName:color
};
2023-07-14 18:50:55 +08:00
}
- (void)initSubViews {
2023-10-31 11:09:04 +08:00
[super initSubViews];
[self.backView addSubview:self.titleLabel];
[self.backView addSubview:self.logoImageView];
[self.backView addSubview:self.lineView];
[self.backView addSubview:self.subTitleLabel];
[self.backView addSubview:self.checkButton];
2023-07-14 18:50:55 +08:00
[self.backView addSubview:self.isNewImageView];
}
- (void)initSubViewConstraints {
2023-10-31 11:09:04 +08:00
[super initSubViewConstraints];
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(280);
make.bottom.mas_equalTo(self.checkButton);
}];
2023-07-14 18:50:55 +08:00
[self.isNewImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.backView);
2023-10-31 11:09:04 +08:00
make.centerY.equalTo(self.titleLabel);
2023-07-14 18:50:55 +08:00
make.size.mas_equalTo(CGSizeMake(24, 10));
}];
2023-10-31 11:09:04 +08:00
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backView);
make.right.equalTo(self.isNewImageView.mas_left);
make.top.mas_equalTo(self.backView);
make.height.mas_equalTo(18);
}];
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backView);
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
make.height.mas_equalTo(87);
}];
[self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backView);
make.top.mas_equalTo(self.logoImageView.mas_bottom).offset(10);
make.height.mas_equalTo(18);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backView);
make.height.mas_equalTo(0.5);
make.top.mas_equalTo(self.subTitleLabel.mas_bottom).offset(5);
}];
[self.checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backView);
make.top.mas_equalTo(self.lineView.mas_bottom).offset(10);
make.height.mas_equalTo(20);
}];
2023-07-14 18:50:55 +08:00
}
#pragma mark - Event Response
- (void)checkButtonAction:(UIButton *)sender {
//
NSArray *history = [[NSUserDefaults standardUserDefaults] objectForKey:kTuWenMessageHistory];
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:history];
if (![tempArray containsObject:self.messageId]) {
[tempArray addObject:self.messageId];
[[NSUserDefaults standardUserDefaults] setObject:tempArray forKey:kTuWenMessageHistory];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if (self.tweetModel.routerType == 1) {
[XPRoomViewController openRoom:self.tweetModel.routerValue viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
} else if (self.tweetModel.routerType == 2) {
XPWebViewController * webVC = [[XPWebViewController alloc] init];
webVC.url = self.tweetModel.routerValue;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
} else {
if ([self.tweetModel.webUrl hasPrefix:@"http"]) {
XPWebViewController * webVC = [[XPWebViewController alloc] init];
webVC.url = self.tweetModel.webUrl;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
}
}
}
#pragma mark - Getters And Setters
- (NetImageView *)logoImageView {
2023-10-31 11:09:04 +08:00
if (!_logoImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_logoImageView = [[NetImageView alloc] initWithConfig:config];
_logoImageView.layer.masksToBounds = YES;
_logoImageView.layer.cornerRadius = 10;
_logoImageView.contentMode = UIViewContentModeScaleAspectFill;
_logoImageView.layer.masksToBounds = YES;
}
return _logoImageView;
2023-07-14 18:50:55 +08:00
}
- (UILabel *)titleLabel {
2023-10-31 11:09:04 +08:00
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.numberOfLines = 2;
_titleLabel.preferredMaxLayoutWidth = 240;
}
return _titleLabel;
2023-07-14 18:50:55 +08:00
}
- (UIView *)lineView {
2023-10-31 11:09:04 +08:00
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [DJDKMIMOMColor dividerColor];
}
return _lineView;
2023-07-14 18:50:55 +08:00
}
- (UILabel *)subTitleLabel {
2023-10-31 11:09:04 +08:00
if (!_subTitleLabel) {
_subTitleLabel = [[UILabel alloc] init];
_subTitleLabel.numberOfLines = 0;
_subTitleLabel.preferredMaxLayoutWidth = 240;
}
return _subTitleLabel;
2023-07-14 18:50:55 +08:00
}
- (UIButton *)checkButton {
2023-10-31 11:09:04 +08:00
if (!_checkButton) {
_checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_checkButton setTitle:YMLocalizedString(@"MessageContentTweetView1") forState:UIControlStateNormal];
[_checkButton setTitleColor:UIColorFromRGB(0x4C5AF1) forState:UIControlStateNormal];
_checkButton.titleLabel.font = [UIFont systemFontOfSize:14];
[_checkButton addTarget:self action:@selector(checkButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _checkButton;
2023-07-14 18:50:55 +08:00
}
- (UIImageView *)isNewImageView {
if (!_isNewImageView) {
_isNewImageView = [[UIImageView alloc] init];
_isNewImageView.image = [UIImage imageNamed:@"gift_type_newIcon"];
_isNewImageView.hidden = YES;
}
return _isNewImageView;
}
@end