chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:35:01 +08:00
commit a2e318a963
2974 changed files with 158180 additions and 0 deletions
@@ -0,0 +1,30 @@
//
// TLChatCellMenuView.h
// TLChat
//
// Created by 李伯坤 on 16/3/16.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLMessageConstants.h"
typedef NS_ENUM(NSInteger, TLChatMenuItemType) {
TLChatMenuItemTypeCancel,
TLChatMenuItemTypeCopy,
TLChatMenuItemTypeDelete,
};
@interface TLChatCellMenuView : UIView
@property (nonatomic, assign, readonly) BOOL isShow;
@property (nonatomic, assign) TLMessageType messageType;
@property (nonatomic, copy) void (^actionBlcok)();
- (void)showInView:(UIView *)view withMessageType:(TLMessageType)messageType rect:(CGRect)rect actionBlock:(void (^)(TLChatMenuItemType))actionBlock;
- (void)dismiss;
@end
@@ -0,0 +1,99 @@
//
// TLChatCellMenuView.m
// TLChat
//
// Created by 李伯坤 on 16/3/16.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLChatCellMenuView.h"
@interface TLChatCellMenuView ()
@property (nonatomic, strong) UIMenuController *menuController;
@end
@implementation TLChatCellMenuView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setBackgroundColor:[UIColor clearColor]];
self.menuController = [UIMenuController sharedMenuController];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
[self addGestureRecognizer:tapGR];
}
return self;
}
- (void)showInView:(UIView *)view withMessageType:(TLMessageType)messageType rect:(CGRect)rect actionBlock:(void (^)(TLChatMenuItemType))actionBlock
{
_isShow = YES;
[self setFrame:view.bounds];
[view addSubview:self];
[self setActionBlcok:actionBlock];
[self setMessageType:messageType];
[self.menuController setTargetRect:rect inView:self];
[self becomeFirstResponder];
[self.menuController setMenuVisible:YES animated:YES];
}
- (void)setMessageType:(TLMessageType)messageType
{
UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copyButtonDown:)];
UIMenuItem *transmit = [[UIMenuItem alloc] initWithTitle:@"转发" action:@selector(transmitButtonDown:)];
UIMenuItem *collect = [[UIMenuItem alloc] initWithTitle:@"收藏" action:@selector(collectButtonDown:)];
UIMenuItem *del = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteButtonDown:)];
[self.menuController setMenuItems:@[copy, transmit, collect, del]];
}
- (void)dismiss
{
_isShow = NO;
if (self.actionBlcok) {
self.actionBlcok(TLChatMenuItemTypeCancel);
}
[self.menuController setMenuVisible:NO animated:YES];
[self removeFromSuperview];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
#pragma mark - Event Response -
- (void)copyButtonDown:(UIMenuController *)sender
{
[self p_clickedMenuItemType:TLChatMenuItemTypeCopy];
}
- (void)transmitButtonDown:(UIMenuController *)sender
{
[self p_clickedMenuItemType:TLChatMenuItemTypeCopy];
}
- (void)collectButtonDown:(UIMenuController *)sender
{
[self p_clickedMenuItemType:TLChatMenuItemTypeCopy];
}
- (void)deleteButtonDown:(UIMenuController *)sender
{
[self p_clickedMenuItemType:TLChatMenuItemTypeDelete];
}
#pragma mark - Private Methods -
- (void)p_clickedMenuItemType:(TLChatMenuItemType)type
{
_isShow = NO;
[self removeFromSuperview];
if (self.actionBlcok) {
self.actionBlcok(type);
}
}
@end
@@ -0,0 +1,20 @@
//
// TLEmojiDisplayView.h
// TLChat
//
// Created by 李伯坤 on 16/3/16.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLExpressionModel.h"
@interface TLEmojiDisplayView : UIImageView
@property (nonatomic, strong) TLExpressionModel *emoji;
@property (nonatomic, assign) CGRect rect;
- (void)displayEmoji:(TLExpressionModel *)emoji atRect:(CGRect)rect;
@end
@@ -0,0 +1,117 @@
//
// TLEmojiDisplayView.m
// TLChat
//
// Created by 李伯坤 on 16/3/16.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiDisplayView.h"
#define SIZE_TIPS CGSizeMake(55, 100)
@interface TLEmojiDisplayView ()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *imageLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation TLEmojiDisplayView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:CGRectMake(0, 0, SIZE_TIPS.width, SIZE_TIPS.height)]) {
[self setImage:[UIImage imageNamed:@"emojiKB_tips"]];
[self addSubview:self.imageLabel];
[self addSubview:self.imageView];
[self addSubview:self.titleLabel];
[self p_addMasonry];
}
return self;
}
- (void)displayEmoji:(TLExpressionModel *)emoji atRect:(CGRect)rect
{
[self setRect:rect];
[self setEmoji:emoji];
}
- (void)setEmoji:(TLExpressionModel *)emoji
{
_emoji = emoji;
if (emoji.type == TLEmojiTypeEmoji) {
[self.imageLabel setHidden:NO];
[self.imageView setHidden:YES];
[self.titleLabel setHidden:YES];
[self.imageLabel setText:emoji.name];
}
else if (emoji.type == TLEmojiTypeFace) {
[self.imageLabel setHidden:YES];
[self.imageView setHidden:NO];
[self.titleLabel setHidden:NO];
[self.imageView setImage:[UIImage imageNamed:emoji.name]];
[self.titleLabel setText:[emoji.name substringWithRange:NSMakeRange(1, emoji.name.length - 2)]];
}
}
- (void)setRect:(CGRect)rect
{
[self setCenterX:rect.origin.x + rect.size.width / 2];
[self setY:rect.origin.y + rect.size.height - self.height - 5];
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).mas_offset(10);
make.left.mas_equalTo(self).mas_offset(12);
make.right.mas_equalTo(self).mas_equalTo(-12);
make.height.mas_equalTo(self.imageView.mas_width);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.imageView.mas_bottom).mas_offset(5);
make.centerX.mas_equalTo(self);
make.width.mas_lessThanOrEqualTo(self);
}];
[self.imageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.and.height.and.centerX.mas_equalTo(self.imageView);
make.top.mas_equalTo(self).mas_offset(12);
}];
}
#pragma mark - Getter -
- (UIImageView *)imageView
{
if (_imageView == nil) {
_imageView = [[UIImageView alloc] init];
}
return _imageView;
}
- (UILabel *)titleLabel
{
if (_titleLabel == nil) {
_titleLabel = [[UILabel alloc] init];
[_titleLabel setFont:[UIFont systemFontOfSize:12.0f]];
[_titleLabel setTextColor:[UIColor grayColor]];
}
return _titleLabel;
}
- (UILabel *)imageLabel
{
if (_imageLabel == nil) {
_imageLabel = [[UILabel alloc] init];
[_imageLabel setTextAlignment:NSTextAlignmentCenter];
[_imageLabel setHidden:YES];
[_imageLabel setFont:[UIFont systemFontOfSize:30.0f]];
}
return _imageLabel;
}
@end
@@ -0,0 +1,20 @@
//
// TLImageExpressionDisplayView.h
// TLChat
//
// Created by 李伯坤 on 16/3/16.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLExpressionModel.h"
@interface TLImageExpressionDisplayView : UIView
@property (nonatomic, strong) TLExpressionModel *emoji;
@property (nonatomic, assign) CGRect rect;
- (void)displayEmoji:(TLExpressionModel *)emoji atRect:(CGRect)rect;
@end
@@ -0,0 +1,161 @@
//
// TLImageExpressionDisplayView.m
// TLChat
//
// Created by 李伯坤 on 16/3/16.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLImageExpressionDisplayView.h"
#import <SDWebImage/UIImage+GIF.h>
#define WIDTH_TIPS 150
#define HEIGHT_TIPS 162
#define WIDTH_CENTER 25
#define SPACE_IMAGE 16
@interface TLImageExpressionDisplayView ()
@property (nonatomic, strong) UIImageView *bgLeftView;
@property (nonatomic, strong) UIImageView *bgCenterView;
@property (nonatomic, strong) UIImageView *bgRightView;
@property (nonatomic, strong) UIImageView *imageView;
@end
@implementation TLImageExpressionDisplayView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:CGRectMake(0, 0, WIDTH_TIPS, HEIGHT_TIPS)]) {
[self addSubview:self.bgLeftView];
[self addSubview:self.bgCenterView];
[self addSubview:self.bgRightView];
[self addSubview:self.imageView];
[self p_addMasonry];
}
return self;
}
- (void)displayEmoji:(TLExpressionModel *)emoji atRect:(CGRect)rect
{
[self setRect:rect];
[self setEmoji:emoji];
}
static NSString *curID;
- (void)setEmoji:(TLExpressionModel *)emoji
{
if (_emoji == emoji) {
return;
}
_emoji = emoji;
curID = emoji.eId;
NSData *data = [NSData dataWithContentsOfFile:emoji.path];
if (data) {
[self.imageView setImage:[UIImage sd_animatedGIFWithData:data]];
}
else {
NSString *urlString = [TLExpressionModel expressionDownloadURLWithEid:emoji.eId];
[self.imageView tt_setImageWithURL:TLURL(emoji.url) completed:^(UIImage *image, NSError *error, TLImageCacheType cacheType, NSURL *imageURL) {
if ([urlString containsString:curID]) {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:TLURL(urlString)];
if ([urlString containsString:curID]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.imageView setImage:[UIImage sd_animatedGIFWithData:data]];
});
}
});
}
}];
}
}
- (void)setRect:(CGRect)rect
{
self.y = rect.origin.y - self.height + 3;
CGFloat w = WIDTH_TIPS - WIDTH_CENTER;
CGFloat centerX = rect.origin.x + rect.size.width / 2;
if (rect.origin.x + rect.size.width < self.width) { // 箭头在左边
self.centerX = centerX + (WIDTH_TIPS - w / 4 - WIDTH_CENTER) / 2 - SPACE_IMAGE;
[self.bgLeftView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(w / 4);
}];
}
else if (SCREEN_WIDTH - rect.origin.x < self.width) { // 箭头在右边
self.centerX = centerX - (WIDTH_TIPS - w / 4 - WIDTH_CENTER) / 2 + SPACE_IMAGE;
[self.bgLeftView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(w / 4 * 3);
}];
}
else {
self.centerX = centerX;
[self.bgLeftView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(w / 2);
}];
}
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[self.bgLeftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.and.bottom.mas_equalTo(self);
}];
[self.bgCenterView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.bgLeftView.mas_right);
make.top.and.bottom.mas_equalTo(self.bgLeftView);
make.width.mas_equalTo(WIDTH_CENTER);
}];
[self.bgRightView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.bgCenterView.mas_right);
make.top.and.bottom.mas_equalTo(self.bgLeftView);
make.right.mas_equalTo(self);
}];
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).mas_offset(10);
make.left.mas_equalTo(self).mas_offset(10);
make.right.mas_equalTo(self).mas_offset(-10);
make.height.mas_equalTo(self.imageView.mas_width);
}];
}
#pragma mark - Getter -
- (UIImageView *)imageView
{
if (_imageView == nil) {
_imageView = [[UIImageView alloc] init];
}
return _imageView;
}
- (UIImageView *)bgLeftView
{
if (_bgLeftView == nil) {
_bgLeftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"emojiKB_bigTips_left"]];
}
return _bgLeftView;
}
- (UIImageView *)bgCenterView
{
if (_bgCenterView == nil) {
_bgCenterView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"emojiKB_bigTips_middle"]];
}
return _bgCenterView;
}
- (UIImageView *)bgRightView
{
if (_bgRightView == nil) {
_bgRightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"emojiKB_bigTips_right"]];
}
return _bgRightView;
}
@end
@@ -0,0 +1,26 @@
//
// TLRecorderIndicatorView.h
// TLChat
//
// Created by 李伯坤 on 16/7/12.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, TLRecorderStatus) {
TLRecorderStatusRecording,
TLRecorderStatusWillCancel,
TLRecorderStatusTooShort,
};
@interface TLRecorderIndicatorView : UIView
@property (nonatomic, assign) TLRecorderStatus status;
/**
* 音量大小,取值(0-1
*/
@property (nonatomic, assign) CGFloat volume;
@end
@@ -0,0 +1,177 @@
//
// TLRecorderIndicatorView.m
// TLChat
//
// Created by 李伯坤 on 16/7/12.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLRecorderIndicatorView.h"
#define STR_RECORDING @"手指上滑,取消发送"
#define STR_CANCEL @"手指松开,取消发送"
#define STR_REC_SHORT @"说话时间太短"
@interface TLRecorderIndicatorView ()
@property (nonatomic, strong) UIView *backgroundView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIView *titleBackgroundView;
@property (nonatomic, strong) UIImageView *recImageView;
@property (nonatomic, strong) UIImageView *centerImageView;
@property (nonatomic, strong) UIImageView *volumeImageView;
@end
@implementation TLRecorderIndicatorView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self addSubview:self.backgroundView];
[self addSubview:self.recImageView];
[self addSubview:self.volumeImageView];
[self addSubview:self.centerImageView];
[self addSubview:self.titleBackgroundView];
[self addSubview:self.titleLabel];
[self p_addMasonry];
}
return self;
}
- (void)setStatus:(TLRecorderStatus)status
{
if (status == TLRecorderStatusWillCancel) {
[self.centerImageView setHidden:NO];
[self.centerImageView setImage:[UIImage imageNamed:@"chat_record_cancel"]];
[self.titleBackgroundView setHidden:NO];
[self.recImageView setHidden:YES];
[self.volumeImageView setHidden:YES];
[self.titleLabel setText:STR_CANCEL];
}
else if (status == TLRecorderStatusRecording) {
[self.centerImageView setHidden:YES];
[self.titleBackgroundView setHidden:YES];
[self.recImageView setHidden:NO];
[self.volumeImageView setHidden:NO];
[self.titleLabel setText:STR_RECORDING];
}
else if (status == TLRecorderStatusTooShort) {
[self.centerImageView setHidden:NO];
[self.centerImageView setImage:[UIImage imageNamed:@"chat_record_cancel"]];
[self.titleBackgroundView setHidden:YES];
[self.recImageView setHidden:YES];
[self.volumeImageView setHidden:YES];
[self.titleLabel setText:STR_REC_SHORT];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (status == TLRecorderStatusTooShort) {
[self removeFromSuperview];
}
});
}
}
- (void)setVolume:(CGFloat)volume
{
_volume = volume;
NSInteger picId = 10 * (volume < 0 ? 0 : (volume > 1.0 ? 1.0 : volume));
picId = picId > 8 ? 8 : picId;
[self.volumeImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"chat_record_signal_%ld", (long)picId]]];
}
#pragma mark - # Private Methods
- (void)p_addMasonry
{
[self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
}];
[self.recImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(15);
make.left.mas_equalTo(21);
}];
[self.volumeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.height.mas_equalTo(self.recImageView);
make.right.mas_equalTo(-21);
}];
[self.centerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(0);
make.top.mas_equalTo(15);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(0);
make.bottom.mas_equalTo(-15);
}];
[self.titleBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.titleLabel).mas_offset(UIEdgeInsetsMake(-2, -5, -2, -5)).priorityLow();
}];
}
#pragma mark - # Getter
- (UIView *)backgroundView
{
if (_backgroundView == nil) {
_backgroundView = [[UIView alloc] init];
[_backgroundView setBackgroundColor:[UIColor blackColor]];
[_backgroundView setAlpha:0.6f];
[_backgroundView.layer setMasksToBounds:YES];
[_backgroundView.layer setCornerRadius:5.0f];
}
return _backgroundView;
}
- (UILabel *)titleLabel
{
if (_titleLabel == nil) {
_titleLabel = [[UILabel alloc] init];
[_titleLabel setFont:[UIFont systemFontOfSize:14.0f]];
[_titleLabel setTextAlignment:NSTextAlignmentCenter];
[_titleLabel setTextColor:[UIColor whiteColor]];
[_titleLabel setText:STR_RECORDING];
}
return _titleLabel;
}
- (UIView *)titleBackgroundView
{
if (_titleBackgroundView == nil) {
_titleBackgroundView = [[UIView alloc] init];
[_titleBackgroundView setHidden:YES];
[_titleBackgroundView setBackgroundColor:[UIColor redColor]];
[_titleBackgroundView.layer setMasksToBounds:YES];
[_titleBackgroundView.layer setCornerRadius:2.0f];
}
return _titleBackgroundView;
}
- (UIImageView *)recImageView
{
if (_recImageView == nil) {
_recImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chat_record_recording"]];
}
return _recImageView;
}
- (UIImageView *)centerImageView
{
if (_centerImageView == nil) {
_centerImageView = [[UIImageView alloc] init];
[_centerImageView setHidden:YES];
}
return _centerImageView;
}
- (UIImageView *)volumeImageView
{
if (_volumeImageView == nil) {
_volumeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chat_record_signal_1"]];
}
return _volumeImageView;
}
@end
@@ -0,0 +1,17 @@
//
// TLTextDisplayView.h
// TLChat
//
// Created by 李伯坤 on 16/3/16.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLTextDisplayView : UIView
@property (nonatomic, strong) NSAttributedString *attrString;
- (void)showInView:(UIView *)view withAttrText:(NSAttributedString *)attrText animation:(BOOL)animation;
@end
@@ -0,0 +1,84 @@
//
// TLTextDisplayView.m
// TLChat
//
// Created by 李伯坤 on 16/3/16.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLTextDisplayView.h"
#define WIDTH_TEXTVIEW self.width * 0.94
@interface TLTextDisplayView ()
@property (nonatomic, strong) UITextView *textView;
@end
@implementation TLTextDisplayView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setBackgroundColor:[UIColor whiteColor]];
[self addSubview:self.textView];
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self);
}];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
[self addGestureRecognizer:tapGR];
}
return self;
}
- (void)showInView:(UIView *)view withAttrText:(NSAttributedString *)attrText animation:(BOOL)animation
{
[view addSubview:self];
[self setFrame:view.bounds];
[self setAttrString:attrText];
[self setAlpha:0];
[UIView animateWithDuration:0.1 animations:^{
[self setAlpha:1.0];
} completion:^(BOOL finished) {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
}];
}
- (void)setAttrString:(NSAttributedString *)attrString
{
_attrString = attrString;
NSMutableAttributedString *mutableAttrString = [[NSMutableAttributedString alloc] initWithAttributedString:attrString];
[mutableAttrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:25.0f] range:NSMakeRange(0, attrString.length)];
[self.textView setAttributedText:mutableAttrString];
CGSize size = [self.textView sizeThatFits:CGSizeMake(WIDTH_TEXTVIEW, MAXFLOAT)];
size.height = size.height > SCREEN_HEIGHT ? SCREEN_HEIGHT : size.height;
[self.textView mas_updateConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(size);
}];
}
- (void)dismiss
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[UIView animateWithDuration:0.2 animations:^{
self.alpha = 0;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
#pragma mark - Getter -
- (UITextView *)textView
{
if (_textView == nil) {
_textView = [[UITextView alloc] init];
[_textView setBackgroundColor:[UIColor clearColor]];
[_textView setTextAlignment:NSTextAlignmentCenter];
[_textView setEditable:NO];
}
return _textView;
}
@end