182 lines
7.3 KiB
Objective-C
182 lines
7.3 KiB
Objective-C
//
|
||
// MessageNotificationCell.m
|
||
// Youth
|
||
//
|
||
// Created by ko1o on 2022/1/9.
|
||
//
|
||
|
||
#import "MessageNotificationCell.h"
|
||
#import "NSDateDeal.h"
|
||
#import <YYText.h>
|
||
@interface MessageNotificationCell ()
|
||
|
||
@property (nonatomic, strong) AvatarView *iconView;
|
||
|
||
@property (nonatomic, strong) UILabel *titleLabel;
|
||
|
||
@property (nonatomic, strong) PYThemeButton *actionButton;
|
||
|
||
@property (nonatomic, strong) UILabel *contentLabel;
|
||
@property (nonatomic, strong) YYLabel *yy_contentLabel;
|
||
|
||
@property (nonatomic, strong) UILabel *timeLabel;
|
||
|
||
@property (nonatomic, strong) UIView *lineView;
|
||
|
||
@end
|
||
|
||
@implementation MessageNotificationCell
|
||
|
||
- (void)setupUI {
|
||
[super setupUI];
|
||
self.backgroundColor = BG_COLOR;
|
||
AvatarView *iconView = [AvatarView avatarWithUser:nil];
|
||
iconView.size = CGSizeMake(FIX_SIZE(44), FIX_SIZE(44));
|
||
iconView.y = FIX_SIZE(12);
|
||
iconView.x = FIX_SIZE(15);
|
||
iconView.layer.cornerRadius = FIX_SIZE(8);
|
||
[self.contentView addSubview:iconView];
|
||
self.iconView = iconView;
|
||
|
||
UILabel *titleLabel = [[UILabel alloc] init];
|
||
titleLabel.font = MT_FONT_REGULAR_SIZE(13);
|
||
titleLabel.textColor = TITLE_COLOR;
|
||
titleLabel.x = iconView.right + FIX_SIZE(12);
|
||
titleLabel.y = iconView.y + FIX_SIZE(3);
|
||
titleLabel.numberOfLines = 0;
|
||
[self.contentView addSubview:titleLabel];
|
||
self.titleLabel = titleLabel;
|
||
WeakSelf(self);
|
||
PYThemeButton *actionButton = [PYThemeButton smallButtonWithTitle:@"" action:self.action];
|
||
self.actionButton = actionButton;
|
||
actionButton.right = SCREEN_WIDTH - FIX_SIZE(15);
|
||
[self.contentView addSubview:actionButton];
|
||
|
||
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.x, 0, SCREEN_WIDTH - titleLabel.x - FIX_SIZE(15), 20)];
|
||
contentLabel.font = MT_FONT_REGULAR_SIZE(11);
|
||
contentLabel.textColor = COLOR_WITH_RGB(0xB3B3B3);
|
||
contentLabel.numberOfLines = 0;
|
||
// contentLabel.x = titleLabel.x;
|
||
// contentLabel.width = SCREEN_WIDTH - titleLabel.x - FIX_SIZE(15);
|
||
contentLabel.userInteractionEnabled = YES;
|
||
UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(contentLabelHandleLongPress:)];
|
||
recognizer.minimumPressDuration = 0.5; //设置最小长按时间;默认为0.5秒
|
||
[contentLabel addGestureRecognizer:recognizer];
|
||
|
||
YYLabel* yy_contentLabel = [[YYLabel alloc]initWithFrame:contentLabel.frame];
|
||
yy_contentLabel.numberOfLines = 0;
|
||
yy_contentLabel.font = MT_FONT_REGULAR_SIZE(11);
|
||
yy_contentLabel.numberOfLines = 0;
|
||
yy_contentLabel.userInteractionEnabled = YES;
|
||
yy_contentLabel.hidden = YES;
|
||
UILongPressGestureRecognizer *yy_recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(contentLabelHandleLongPress:)];
|
||
yy_recognizer.minimumPressDuration = 0.5; //设置最小长按时间;默认为0.5秒
|
||
[yy_contentLabel addGestureRecognizer:yy_recognizer];
|
||
self.yy_contentLabel = yy_contentLabel;
|
||
self.contentLabel = contentLabel;
|
||
[self.contentView addSubview:yy_contentLabel];
|
||
[self.contentView addSubview:contentLabel];
|
||
|
||
UILabel *timeLabel = [[UILabel alloc] init];
|
||
timeLabel.x = contentLabel.x;
|
||
timeLabel.width = contentLabel.width;
|
||
timeLabel.font = MT_FONT_REGULAR_SIZE(11);
|
||
timeLabel.textColor = COLOR_WITH_RGB(0x737373);
|
||
self.timeLabel = timeLabel;
|
||
[self.contentView addSubview:timeLabel];
|
||
|
||
UIView *line = [UIView lineViewWithWidth:SCREEN_WIDTH];
|
||
line.x = timeLabel.x;
|
||
[self.contentView addSubview:line];
|
||
self.lineView = line;
|
||
}
|
||
|
||
- (void)setAction:(void (^)(UIButton * _Nonnull))action
|
||
{
|
||
[self.actionButton setAction:action];
|
||
}
|
||
|
||
- (void)setModel:(MessageNotification *)model {
|
||
[super setModel:model];
|
||
BOOL isVIP = model.user_v_info.vip_kind != VIPKindNone;
|
||
if (model.isSystemNotification || model.user.isSelf || model.user.ID <= 0) {
|
||
self.actionButton.hidden = YES;
|
||
self.titleLabel.width = self.actionButton.right - self.titleLabel.x;
|
||
self.iconView.imageUrl = model.iconUrl;
|
||
} else {
|
||
self.actionButton.hidden = NO;
|
||
self.iconView.user = model.user;
|
||
self.titleLabel.width = self.actionButton.x - self.titleLabel.x - FIX_SIZE(5);
|
||
BOOL isFollowing = [model.user_v_info isFollowing];
|
||
[self.actionButton setTitle:isFollowing ? @"聊天" : @"关注" forState:UIControlStateNormal];
|
||
[self.actionButton setTitleColor:(isFollowing ? THEME_COLOR : COLOR_WITH_RGB(0x040000)) forState:UIControlStateNormal];
|
||
if (isFollowing) {
|
||
self.actionButton.backgroundColor = COLOR_WITH_RGB_A(0xFFBE00, 0.2);
|
||
} else {
|
||
self.actionButton.backgroundColor = THEME_COLOR;
|
||
}
|
||
}
|
||
|
||
|
||
CGFloat maxWidth = self.titleLabel.right;
|
||
self.titleLabel.text = model.title;
|
||
|
||
[self.titleLabel sizeToFit];
|
||
if (model.content.length) {
|
||
self.contentLabel.hidden = model.url.length > 0?YES:NO;
|
||
self.yy_contentLabel.hidden = model.url.length > 0?NO:YES;
|
||
self.contentLabel.width = maxWidth - self.contentLabel.x;
|
||
NSRange tempRan = [model.content rangeOfString:model.url
|
||
options:NSCaseInsensitiveSearch];
|
||
NSMutableAttributedString* mAString = [[NSMutableAttributedString alloc]initWithString:model.content attributes:@{NSForegroundColorAttributeName:HEX_COLOR(0xB3B3B3),NSFontAttributeName:self.contentLabel.font}];
|
||
[mAString yy_setTextHighlightRange:tempRan color:[UIColor blueColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
||
// [PYAppService openWebVCWithTitle:@"网页" url:model.url];
|
||
//内部跳转.
|
||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:model.url] options:@{} completionHandler:^(BOOL success) {
|
||
}];
|
||
}];
|
||
if (model.url.length > 0) {
|
||
self.yy_contentLabel.attributedText = mAString;
|
||
self.yy_contentLabel.userInteractionEnabled = YES;
|
||
}else{
|
||
self.yy_contentLabel.userInteractionEnabled = NO;
|
||
}
|
||
self.contentLabel.text = model.content;
|
||
self.contentLabel.y = self.titleLabel.bottom + FIX_SIZE(5);
|
||
[self.contentLabel sizeToFit];
|
||
} else {
|
||
self.contentLabel.hidden = YES;
|
||
self.yy_contentLabel.hidden = YES;
|
||
self.contentLabel.height = 0;
|
||
self.contentLabel.y = self.titleLabel.bottom;
|
||
}
|
||
self.yy_contentLabel.frame = self.contentLabel.frame;
|
||
[self.yy_contentLabel sizeToFit];
|
||
self.timeLabel.text = model.time;
|
||
self.timeLabel.y = self.contentLabel.bottom + FIX_SIZE(5);
|
||
[self.timeLabel sizeToFit];
|
||
self.lineView.y = self.timeLabel.bottom + FIX_SIZE(14.5);
|
||
|
||
self.actionButton.centerY = self.lineView.bottom * 0.5;
|
||
self.titleLabel.textColor = TITLE_COLOR;
|
||
if (isVIP) {
|
||
self.titleLabel.textColor = COLOR_WITH_RGB(0xFDCF7F);
|
||
}
|
||
[self.iconView setVIPTagImageURL:model.user_v_info.vip_flag_img];
|
||
}
|
||
|
||
- (CGSize)sizeThatFits:(CGSize)size {
|
||
return CGSizeMake(SCREEN_WIDTH, self.lineView.bottom);
|
||
}
|
||
|
||
-(void)contentLabelHandleLongPress:(UILabel*)contentLab{
|
||
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
||
if (contentLab.text.length>0) {
|
||
pasteboard.string = contentLab.text;
|
||
[SVProgressHUD showSuccessWithStatus:@"复制成功"];
|
||
}
|
||
|
||
}
|
||
|
||
@end
|