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,15 @@
//
// TLChatBackgroundSelectViewController+CollectionView.h
// TLChat
//
// Created by 李伯坤 on 16/4/2.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLChatBackgroundSelectViewController.h"
@interface TLChatBackgroundSelectViewController (CollectionView) <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
- (void)registerCellForCollectionView:(UICollectionView *)collectionView;
@end
@@ -0,0 +1,31 @@
//
// TLChatBackgroundSelectViewController+CollectionView.m
// TLChat
//
// Created by 李伯坤 on 16/4/2.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLChatBackgroundSelectViewController+CollectionView.h"
#import "TLChatBackgroundSelectCell.h"
@implementation TLChatBackgroundSelectViewController (CollectionView)
- (void)registerCellForCollectionView:(UICollectionView *)collectionView
{
[collectionView registerClass:[TLChatBackgroundSelectCell class] forCellWithReuseIdentifier:@"TLChatBackgroundSelectCell"];
}
#pragma mark - # Delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.data.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TLChatBackgroundSelectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TLChatBackgroundSelectCell" forIndexPath:indexPath];
return cell;
}
@end
@@ -0,0 +1,13 @@
//
// TLChatBackgroundSelectViewController+Proxy.h
// TLChat
//
// Created by 李伯坤 on 16/4/2.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLChatBackgroundSelectViewController.h"
@interface TLChatBackgroundSelectViewController (Proxy)
@end
@@ -0,0 +1,13 @@
//
// TLChatBackgroundSelectViewController+Proxy.m
// TLChat
//
// Created by 李伯坤 on 16/4/2.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLChatBackgroundSelectViewController+Proxy.h"
@implementation TLChatBackgroundSelectViewController (Proxy)
@end
@@ -0,0 +1,17 @@
//
// TLChatBackgroundSelectViewController.h
// TLChat
//
// Created by 李伯坤 on 16/4/2.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLChatBackgroundSelectViewController : UIViewController
@property (nonatomic, strong) NSMutableArray *data;
@property (nonatomic, strong) UICollectionView *collectionView;
@end
@@ -0,0 +1,63 @@
//
// TLChatBackgroundSelectViewController.m
// TLChat
//
// Created by 李伯坤 on 16/4/2.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLChatBackgroundSelectViewController.h"
#import "TLChatBackgroundSelectViewController+CollectionView.h"
#import "TLChatBackgroundSelectViewController+Proxy.h"
#define SPACE_EDGE 10
#define WIDTH_COLLECTIONVIEW_CELL (SCREEN_WIDTH - SPACE_EDGE * 2) / 3 * 0.98
#define SPACE_COLLECTIONVIEW_CELL (SCREEN_WIDTH - SPACE_EDGE * 2 - WIDTH_COLLECTIONVIEW_CELL * 3) / 2
@interface TLChatBackgroundSelectViewController ()
@end
@implementation TLChatBackgroundSelectViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationItem setTitle:LOCSTR(@"选择背景图")];
[self.collectionView setBackgroundColor:[UIColor colorBlackBG]];
[self.view addSubview:self.collectionView];
[self p_addMasonry];
}
#pragma mark - # Private Methods
- (void)p_addMasonry
{
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
#pragma mark - # Getter
- (UICollectionView *)collectionView
{
if (_collectionView == nil) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
[layout setSectionHeadersPinToVisibleBounds:YES];
[layout setItemSize:CGSizeMake(WIDTH_COLLECTIONVIEW_CELL, WIDTH_COLLECTIONVIEW_CELL)];
[layout setMinimumInteritemSpacing:SPACE_COLLECTIONVIEW_CELL];
[layout setMinimumLineSpacing:SPACE_COLLECTIONVIEW_CELL];
[layout setSectionInset:UIEdgeInsetsMake(0, SPACE_EDGE, 0, SPACE_EDGE)];
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[_collectionView setBackgroundColor:[UIColor clearColor]];
[_collectionView setDataSource:self];
[_collectionView setDelegate:self];
[_collectionView setShowsHorizontalScrollIndicator:NO];
[_collectionView setShowsHorizontalScrollIndicator:NO];
[_collectionView setAlwaysBounceVertical:YES];
}
return _collectionView;
}
@end
@@ -0,0 +1,13 @@
//
// TLChatBackgroundSelectCell.h
// TLChat
//
// Created by 李伯坤 on 16/4/2.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLChatBackgroundSelectCell : UICollectionViewCell
@end
@@ -0,0 +1,13 @@
//
// TLChatBackgroundSelectCell.m
// TLChat
//
// Created by 李伯坤 on 16/4/2.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLChatBackgroundSelectCell.h"
@implementation TLChatBackgroundSelectCell
@end
@@ -0,0 +1,18 @@
//
// TLChatBackgroundViewController.h
// TLChat
//
// Created by 李伯坤 on 16/3/19.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLChatBackgroundViewController : ZZFlexibleLayoutViewController
/**
* 若为nil则全局设置,否则只给对应好友设置
*/
@property (nonatomic, strong) NSString *partnerID;
@end
@@ -0,0 +1,146 @@
//
// TLChatBackgroundViewController.m
// TLChat
//
// Created by 李伯坤 on 16/3/19.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLChatBackgroundViewController.h"
#import "TLChatBackgroundSelectViewController.h"
#import "TLChatNotificationKey.h"
#import "NSFileManager+TLChat.h"
#import "TLSettingItem.h"
typedef NS_ENUM(NSInteger, TLChatBackgroundVCSectionType) {
TLChatBackgroundVCSectionTypeDefault,
TLChatBackgroundVCSectionTypeDIY,
TLChatBackgroundVCSectionTypeFunction,
};
@implementation TLChatBackgroundViewController
- (void)loadView
{
[super loadView];
[self.view setBackgroundColor:[UIColor colorGrayBG]];
[self setTitle:LOCSTR(@"聊天背景")];
[self loadChatBGSettingUI];
}
#pragma mark - # UI
- (void)loadChatBGSettingUI
{
@weakify(self);
self.clear();
{
NSInteger sectionTag = TLChatBackgroundVCSectionTypeDefault;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"选择背景图")).selectedAction(^ (id data) {
@strongify(self);
TLChatBackgroundSelectViewController *bgSelectVC = [[TLChatBackgroundSelectViewController alloc] init];
PushVC(bgSelectVC);
});
}
{
NSInteger sectionTag = TLChatBackgroundVCSectionTypeDIY;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
// 相册
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"从手机相册中选择")).selectedAction(^ (id data) {
@strongify(self);
[self p_selectFromAlbum];
});
// 拍照
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"拍一张")).selectedAction(^ (id data) {
@strongify(self);
[self p_takePhoto];
});
}
if (self.partnerID.length == 0) {
NSInteger sectionTag = TLChatBackgroundVCSectionTypeFunction;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
self.addCell(CELL_ST_ITEM_BUTTON).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"将背景应用到所有聊天场景")).selectedAction(^ (id data) {
TLActionSheet *actionSheet = [[TLActionSheet alloc] initWithTitle:nil clickAction:^(NSInteger buttonIndex) {
if (buttonIndex == 0) {
for (NSString *key in [NSUserDefaults standardUserDefaults].dictionaryRepresentation.allKeys) {
if ([key hasPrefix:@"CHAT_BG_"] && ![key isEqualToString:@"CHAT_BG_ALL"]) {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:NOTI_CHAT_VIEW_RESET object:nil];
}
} cancelButtonTitle:@"取消" destructiveButtonTitle:@"将背景应用到所有聊天场景" otherButtonTitles:nil];
[actionSheet show];
});
}
[self reloadView];
}
#pragma mark - # Private Methods
- (void)p_selectFromAlbum
{
@weakify(self);
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController animated:YES completion:nil];
[imagePickerController.rac_imageSelectedSignal subscribeNext:^(id x) {
[imagePickerController dismissViewControllerAnimated:YES completion:^{
@strongify(self);
UIImage *image = [x objectForKey:UIImagePickerControllerOriginalImage];
[self p_setChatBackgroundImage:image];
}];
} completed:^{
[imagePickerController dismissViewControllerAnimated:YES completion:nil];
}];
}
- (void)p_takePhoto
{
@weakify(self);
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[TLUIUtility showAlertWithTitle:@"错误" message:@"相机初始化失败"];
}
else {
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:imagePickerController animated:YES completion:nil];
[imagePickerController.rac_imageSelectedSignal subscribeNext:^(id x) {
[imagePickerController dismissViewControllerAnimated:YES completion:^{
@strongify(self);
UIImage *image = [x objectForKey:UIImagePickerControllerOriginalImage];
[self p_setChatBackgroundImage:image];
}];
} completed:^{
[imagePickerController dismissViewControllerAnimated:YES completion:nil];
}];
}
}
- (void)p_setChatBackgroundImage:(UIImage *)image
{
image = [image scalingToSize:self.view.size];
NSData *imageData = (UIImagePNGRepresentation(image) ? UIImagePNGRepresentation(image) :UIImageJPEGRepresentation(image, 1));
NSString *imageName = [NSString stringWithFormat:@"%lf.jpg", [NSDate date].timeIntervalSince1970];
NSString *imagePath = [NSFileManager pathUserChatBackgroundImage:imageName];;
[[NSFileManager defaultManager] createFileAtPath:imagePath contents:imageData attributes:nil];
//TODO: 临时写法
if (self.partnerID.length > 0) {
[[NSUserDefaults standardUserDefaults] setObject:imageName forKey:[@"CHAT_BG_" stringByAppendingString:self.partnerID]];
}
else {
[[NSUserDefaults standardUserDefaults] setObject:imageName forKey:@"CHAT_BG_ALL"];
}
[[NSNotificationCenter defaultCenter] postNotificationName:NOTI_CHAT_VIEW_RESET object:nil];
}
@end