chore: import upstream snapshot with attribution
This commit is contained in:
+15
@@ -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
|
||||
+31
@@ -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
|
||||
+13
@@ -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
|
||||
+13
@@ -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
|
||||
+17
@@ -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
|
||||
+63
@@ -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
|
||||
+13
@@ -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
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// TLChatBackgroundSelectCell.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/4/2.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLChatBackgroundSelectCell.h"
|
||||
|
||||
@implementation TLChatBackgroundSelectCell
|
||||
|
||||
@end
|
||||
+18
@@ -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
|
||||
+146
@@ -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
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// TLChatFontViewController.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/21.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLViewController.h"
|
||||
|
||||
@interface TLChatFontViewController : TLViewController
|
||||
|
||||
@end
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// TLChatFontViewController.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/21.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLChatFontViewController.h"
|
||||
#import "TLChatMessageDisplayView.h"
|
||||
#import "TLChatFontSettingView.h"
|
||||
#import "TLUser+ChatModel.h"
|
||||
#import "NSFileManager+TLChat.h"
|
||||
#import "TLUserHelper.h"
|
||||
|
||||
@interface TLChatFontViewController ()
|
||||
|
||||
@property (nonatomic, strong) TLChatMessageDisplayView *messageDisplayView;
|
||||
|
||||
@property (nonatomic, strong) TLChatFontSettingView *chatFontSettingView;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TLChatFontViewController
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
[self.navigationItem setTitle:LOCSTR(@"字体大小")];
|
||||
|
||||
[self.view addSubview:self.messageDisplayView];
|
||||
[self.view addSubview:self.chatFontSettingView];
|
||||
[self p_addMasonry];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.chatFontSettingView setFontSizeChangeTo:^(CGFloat size) {
|
||||
[[NSUserDefaults standardUserDefaults] setDouble:size forKey:@"CHAT_FONT_SIZE"];
|
||||
weakSelf.messageDisplayView.data = [weakSelf p_messageDisplayViewData];
|
||||
[weakSelf.messageDisplayView reloadData];
|
||||
}];
|
||||
CGFloat size = [[NSUserDefaults standardUserDefaults] doubleForKey:@"CHAT_FONT_SIZE"];
|
||||
[self.chatFontSettingView setCurFontSize:size];
|
||||
self.messageDisplayView.data = [self p_messageDisplayViewData];
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods -
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.messageDisplayView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.and.left.and.right.mas_equalTo(self.view);
|
||||
make.bottom.mas_equalTo(self.chatFontSettingView.mas_top);
|
||||
}];
|
||||
|
||||
[self.chatFontSettingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.and.right.and.bottom.mas_equalTo(self.view);
|
||||
make.height.mas_equalTo(self.chatFontSettingView.mas_width).multipliedBy(0.4);
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSMutableArray *)p_messageDisplayViewData
|
||||
{
|
||||
TLTextMessage *message = [[TLTextMessage alloc] init];
|
||||
message.fromUser = [TLUserHelper sharedHelper].user;
|
||||
message.ownerTyper = TLMessageOwnerTypeSelf;
|
||||
message.text = @"预览字体大小";
|
||||
|
||||
TLUser *user = [[TLUser alloc] init];
|
||||
user.avatarPath = @"AppIcon";
|
||||
NSString *path = [NSFileManager pathUserAvatar:@"AppIcon"];
|
||||
if (![[NSFileManager defaultManager] isExecutableFileAtPath:path]) {
|
||||
NSString *iconPath = [[[[NSBundle mainBundle] infoDictionary] valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
|
||||
UIImage *image = [UIImage imageNamed:iconPath];
|
||||
NSData *data = (UIImagePNGRepresentation(image) ? UIImagePNGRepresentation(image) :UIImageJPEGRepresentation(image, 1));
|
||||
[[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil];
|
||||
}
|
||||
|
||||
|
||||
TLTextMessage *message1 = [[TLTextMessage alloc] init];
|
||||
message1.fromUser = user;
|
||||
message1.ownerTyper = TLMessageOwnerTypeFriend;
|
||||
message1.text = @"拖动下面的滑块,可设置字体大小";
|
||||
TLTextMessage *message2 = [[TLTextMessage alloc] init];
|
||||
message2.fromUser = user;
|
||||
message2.ownerTyper = TLMessageOwnerTypeFriend;
|
||||
message2.text = @"设置后,会改变聊天页面的字体大小。后续将支持更改菜单、朋友圈的字体修改。";
|
||||
|
||||
NSMutableArray *data = [[NSMutableArray alloc] initWithObjects:message, message1, message2, nil];
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Getter -
|
||||
- (TLChatMessageDisplayView *)messageDisplayView
|
||||
{
|
||||
if (_messageDisplayView == nil) {
|
||||
_messageDisplayView = [[TLChatMessageDisplayView alloc] init];
|
||||
[_messageDisplayView setDisablePullToRefresh:YES];
|
||||
[_messageDisplayView setDisableLongPressMenu:YES];
|
||||
}
|
||||
return _messageDisplayView;
|
||||
}
|
||||
|
||||
- (TLChatFontSettingView *)chatFontSettingView
|
||||
{
|
||||
if (_chatFontSettingView == nil) {
|
||||
_chatFontSettingView = [[TLChatFontSettingView alloc] init];
|
||||
}
|
||||
return _chatFontSettingView;
|
||||
}
|
||||
|
||||
@end
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// TLChatFontSettingView.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/22.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#define MIN_FONT_SIZE 15.0f
|
||||
#define STANDARD_FONT_SZIE 16.0f
|
||||
#define MAX_FONT_SZIE 20.0f
|
||||
|
||||
@interface TLChatFontSettingView : UIView
|
||||
|
||||
@property (nonatomic, assign) CGFloat curFontSize;
|
||||
|
||||
@property (nonatomic, copy) void (^fontSizeChangeTo)(CGFloat size);
|
||||
|
||||
|
||||
@end
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
//
|
||||
// TLChatFontSettingView.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/22.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLChatFontSettingView.h"
|
||||
|
||||
@interface TLChatFontSettingView ()
|
||||
|
||||
@property (nonatomic, strong) UILabel *miniFontLabel;
|
||||
|
||||
@property (nonatomic, strong) UILabel *maxFontLabel;
|
||||
|
||||
@property (nonatomic, strong) UILabel *standardFontLabel;
|
||||
|
||||
@property (nonatomic, strong) UISlider *slider;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TLChatFontSettingView
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self setBackgroundColor:[UIColor whiteColor]];
|
||||
[self addSubview:self.miniFontLabel];
|
||||
[self addSubview:self.maxFontLabel];
|
||||
[self addSubview:self.standardFontLabel];
|
||||
[self addSubview:self.slider];
|
||||
[self p_addMasonry];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setCurFontSize:(CGFloat)curFontSize
|
||||
{
|
||||
_curFontSize = curFontSize;
|
||||
[self.slider setValue:curFontSize];
|
||||
}
|
||||
|
||||
#pragma mark - Event Response -
|
||||
- (void)sliderValueChanged:(UISlider *)sender
|
||||
{
|
||||
NSInteger value = (NSInteger)sender.value;
|
||||
value = ((sender.value - value) > 0.5 ? value + 1 : value);
|
||||
if (value == (NSInteger)_curFontSize) {
|
||||
return;
|
||||
}
|
||||
_curFontSize = value;
|
||||
if (self.fontSizeChangeTo) {
|
||||
self.fontSizeChangeTo(value);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods -
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.miniFontLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.slider.mas_left);
|
||||
make.bottom.mas_equalTo(self.slider.mas_top).mas_offset(-6);
|
||||
}];
|
||||
|
||||
[self.maxFontLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.slider.mas_right);
|
||||
make.bottom.mas_equalTo(self.miniFontLabel);
|
||||
}];
|
||||
|
||||
[self.standardFontLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.miniFontLabel);
|
||||
make.left.mas_equalTo(self.miniFontLabel.mas_right).mas_equalTo(40);
|
||||
}];
|
||||
|
||||
[self.slider mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self);
|
||||
make.bottom.mas_equalTo(self.mas_bottom).mas_offset(-35);
|
||||
make.width.mas_equalTo(self).multipliedBy(0.8);
|
||||
make.height.mas_equalTo(40);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Getter -
|
||||
- (UILabel *)miniFontLabel
|
||||
{
|
||||
if (_miniFontLabel == nil) {
|
||||
_miniFontLabel = [[UILabel alloc] init];
|
||||
[_miniFontLabel setFont:[UIFont systemFontOfSize:MIN_FONT_SIZE]];
|
||||
[_miniFontLabel setText:@"A"];
|
||||
}
|
||||
return _miniFontLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)maxFontLabel
|
||||
{
|
||||
if (_maxFontLabel == nil) {
|
||||
_maxFontLabel = [[UILabel alloc] init];
|
||||
[_maxFontLabel setFont:[UIFont systemFontOfSize:MAX_FONT_SZIE]];
|
||||
[_maxFontLabel setText:@"A"];
|
||||
}
|
||||
return _maxFontLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)standardFontLabel
|
||||
{
|
||||
if (_standardFontLabel == nil) {
|
||||
_standardFontLabel = [[UILabel alloc] init];
|
||||
[_standardFontLabel setFont:[UIFont systemFontOfSize:STANDARD_FONT_SZIE]];
|
||||
[_standardFontLabel setText:@"标准"];
|
||||
}
|
||||
return _standardFontLabel;
|
||||
}
|
||||
|
||||
- (UISlider *)slider
|
||||
{
|
||||
if (_slider == nil) {
|
||||
_slider = [[UISlider alloc] init];
|
||||
[_slider setMinimumValue:MIN_FONT_SIZE];
|
||||
[_slider setMaximumValue:MAX_FONT_SZIE];
|
||||
[_slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
|
||||
}
|
||||
return _slider;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// TLCommonSettingViewController.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/21.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface TLCommonSettingViewController : ZZFlexibleLayoutViewController
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,148 @@
|
||||
//
|
||||
// TLCommonSettingViewController.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/21.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLCommonSettingViewController.h"
|
||||
#import "TLChatViewController.h"
|
||||
#import "TLChatFontViewController.h"
|
||||
#import "TLChatBackgroundViewController.h"
|
||||
#import "TLMyExpressionViewController.h"
|
||||
|
||||
#import "TLMessageManager.h"
|
||||
#import "TLSettingItem.h"
|
||||
#import "TLChatNotificationKey.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, TLCommonSettingVCSectionType) {
|
||||
TLCommonSettingVCSectionTypeLanguage,
|
||||
TLCommonSettingVCSectionTypeChat,
|
||||
TLCommonSettingVCSectionTypeVoice,
|
||||
TLCommonSettingVCSectionTypeFunction,
|
||||
TLCommonSettingVCSectionTypeRecord,
|
||||
TLCommonSettingVCSectionTypeClear,
|
||||
};
|
||||
|
||||
@implementation TLCommonSettingViewController
|
||||
|
||||
- (void)loadView
|
||||
{
|
||||
[super loadView];
|
||||
[self.view setBackgroundColor:[UIColor colorGrayBG]];
|
||||
[self setTitle:LOCSTR(@"通用")];
|
||||
|
||||
[self loadCommonSettingUI];
|
||||
}
|
||||
|
||||
#pragma mark - # UI
|
||||
- (void)loadCommonSettingUI
|
||||
{
|
||||
@weakify(self);
|
||||
self.clear();
|
||||
|
||||
// 语言
|
||||
{
|
||||
NSInteger sectionType = TLCommonSettingVCSectionTypeLanguage;
|
||||
self.addSection(sectionType).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
|
||||
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"多语言")).selectedAction(^ (TLSettingItem *data) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// 社交
|
||||
{
|
||||
NSInteger sectionType = TLCommonSettingVCSectionTypeChat;
|
||||
self.addSection(sectionType).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
|
||||
|
||||
// 字体
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"字体大小")).selectedAction(^ (TLSettingItem *data) {
|
||||
@strongify(self);
|
||||
TLChatFontViewController *chatFontVC = [[TLChatFontViewController alloc] init];
|
||||
PushVC(chatFontVC);
|
||||
});
|
||||
|
||||
// 聊天背景
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"聊天背景")).selectedAction(^ (TLSettingItem *data) {
|
||||
@strongify(self);
|
||||
TLChatBackgroundViewController *chatBGSettingVC = [[TLChatBackgroundViewController alloc] init];
|
||||
PushVC(chatBGSettingVC);
|
||||
});
|
||||
|
||||
// 表情
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"我的表情")).selectedAction(^ (TLSettingItem *data) {
|
||||
@strongify(self);
|
||||
TLMyExpressionViewController *myExpressionVC = [[TLMyExpressionViewController alloc] init];
|
||||
PushVC(myExpressionVC);
|
||||
});
|
||||
|
||||
// 聊天资源
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"照片、视频和文件")).selectedAction(^ (TLSettingItem *data) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// 声音
|
||||
{
|
||||
NSInteger sectionType = TLCommonSettingVCSectionTypeVoice;
|
||||
self.addSection(sectionType).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
|
||||
|
||||
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionType).withDataModel(TLCreateSettingItem(@"听筒模式")).selectedAction(^ (TLSettingItem *data) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// 功能
|
||||
{
|
||||
NSInteger sectionType = TLCommonSettingVCSectionTypeFunction;
|
||||
self.addSection(sectionType).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
|
||||
|
||||
// 发现页管理
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"发现页管理")).selectedAction(^ (TLSettingItem *data) {
|
||||
|
||||
});
|
||||
|
||||
// 辅助功能
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"辅助功能")).selectedAction(^ (TLSettingItem *data) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// 记录
|
||||
{
|
||||
NSInteger sectionType = TLCommonSettingVCSectionTypeRecord;
|
||||
self.addSection(sectionType).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
|
||||
|
||||
// 聊天记录迁移
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"聊天记录迁移")).selectedAction(^ (TLSettingItem *data) {
|
||||
|
||||
});
|
||||
|
||||
// 存储空间
|
||||
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionType).withDataModel(TLCreateSettingItem(@"存储空间")).selectedAction(^ (TLSettingItem *data) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// 清空聊天记录
|
||||
{
|
||||
NSInteger sectionType = TLCommonSettingVCSectionTypeClear;
|
||||
self.addSection(sectionType).sectionInsets(UIEdgeInsetsMake(20, 0, 40, 0));
|
||||
|
||||
self.addCell(CELL_ST_ITEM_BUTTON).toSection(sectionType).withDataModel(TLCreateSettingItem(@"清空聊天记录")).selectedAction(^ (TLSettingItem *data) {
|
||||
TLActionSheet *actionSheet = [[TLActionSheet alloc] initWithTitle:@"将删除所有个人和群的聊天记录。" clickAction:^(NSInteger buttonIndex) {
|
||||
if (buttonIndex == 0) {
|
||||
[[TLMessageManager sharedInstance] deleteAllMessages];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NOTI_CHAT_VIEW_RESET object:nil];
|
||||
}
|
||||
} cancelButtonTitle:@"取消" destructiveButtonTitle:@"清空聊天记录" otherButtonTitles:nil];
|
||||
[actionSheet show];
|
||||
});
|
||||
}
|
||||
|
||||
[self reloadView];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user