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,13 @@
//
// TLAboutViewController.h
// TLChat
//
// Created by 李伯坤 on 16/2/22.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLAboutViewController : ZZFlexibleLayoutViewController
@end
@@ -0,0 +1,90 @@
//
// TLAboutViewController.m
// TLChat
//
// Created by 李伯坤 on 16/2/22.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLAboutViewController.h"
#import "TLWebViewController.h"
#import "TLAppConfig.h"
#import "TLSettingItem.h"
typedef NS_ENUM(NSInteger, TLAboutVCSectionType) {
TLAboutVCSectionTypeItems,
};
@interface TLAboutViewController ()
@property (nonatomic, strong) UILabel *cmpLabel;
@end
@implementation TLAboutViewController
- (void)loadView
{
[super loadView];
[self.navigationItem setTitle:LOCSTR(@"关于微信")];
[self.collectionView setBackgroundColor:[UIColor colorGrayBG]];
self.addSection(TLAboutVCSectionTypeItems);
[self loadAboutUI];
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.setFooter(@"TLAboutFooterView").toSection(TLAboutVCSectionTypeItems).withDataModel(@([self p_footerHeight]));
}
#pragma mark - # UI
- (void)loadAboutUI
{
@weakify(self);
{
NSInteger sectionTag = TLAboutVCSectionTypeItems;
// header
NSString *versionInfo = [NSString stringWithFormat:@"TLChat %@", [TLAppConfig sharedConfig].version];
self.setHeader(@"TLAboutHeaderView").toSection(sectionTag).withDataModel(versionInfo);
// 评分
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"去评分")).selectedAction(^ (id data) {
@strongify(self);
TLWebViewController *webVC = [[TLWebViewController alloc] initWithUrl:@"https://github.com/tbl00c/TLChat"];
PushVC(webVC);
});
// 欢迎页
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"欢迎页"));
// 功能介绍
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"功能介绍")).selectedAction(^ (id data) {
@strongify(self);
TLWebViewController *webVC = [[TLWebViewController alloc] initWithUrl:@"https://github.com/tbl00c/TLChat/blob/master/README.md"];
PushVC(webVC);
});
// footer
self.setFooter(@"TLAboutFooterView").toSection(sectionTag).withDataModel(@([self p_footerHeight]));
}
[self reloadView];
}
#pragma mark - # Private
- (CGFloat)p_footerHeight
{
CGFloat statusHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
CGFloat navHeight = self.navigationController.navigationBar.height;
CGFloat headerHeight = 120.0f;
CGFloat cellsHeight = self.sectionForTag(TLAboutVCSectionTypeItems).dataModelArray.count * 44.0f;
CGFloat footerHeight = SCREEN_HEIGHT - statusHeight - navHeight - headerHeight - cellsHeight;
return footerHeight;
}
@end
@@ -0,0 +1,13 @@
//
// TLAboutFooterView.h
// TLChat
//
// Created by 李伯坤 on 2018/3/5.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLAboutFooterView : UICollectionReusableView <ZZFlexibleLayoutViewProtocol>
@end
@@ -0,0 +1,33 @@
//
// TLAboutFooterView.m
// TLChat
//
// Created by 李伯坤 on 2018/3/5.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLAboutFooterView.h"
@implementation TLAboutFooterView
+ (CGFloat)viewHeightByDataModel:(NSNumber *)dataModel
{
return dataModel.doubleValue;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.addLabel(1).numberOfLines(0).textAlignment(NSTextAlignmentCenter)
.text(@"高仿微信 仅供学习\nhttps://github.com/tbl00c/TLChat")
.font([UIFont systemFontOfSize:12.0f]).textColor([UIColor grayColor])
.masonry(^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(0);
make.bottom.mas_equalTo(-10);
make.width.mas_lessThanOrEqualTo(self).mas_offset(-30);
});
}
return self;
}
@end
@@ -0,0 +1,13 @@
//
// TLAboutHeaderView.h
// TLChat
//
// Created by 李伯坤 on 16/2/22.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLAboutHeaderView : UICollectionReusableView <ZZFlexibleLayoutViewProtocol>
@end
@@ -0,0 +1,53 @@
//
// TLAboutHeaderView.m
// TLChat
//
// Created by 李伯坤 on 16/2/22.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLAboutHeaderView.h"
@interface TLAboutHeaderView ()
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation TLAboutHeaderView
#pragma mark - # Protocol
+ (CGFloat)viewHeightByDataModel:(id)dataModel
{
return 120.0f;
}
- (void)setViewDataModel:(id)dataModel
{
[self.titleLabel setText:dataModel];
}
#pragma mark - # View
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.titleLabel = self.addLabel(1000)
.font([UIFont systemFontOfSize:17.0f]).textColor([UIColor grayColor])
.masonry(^ (MASConstraintMaker *make) {
make.centerX.mas_equalTo(0);
make.width.mas_lessThanOrEqualTo(self).mas_offset(-30);
make.bottom.mas_equalTo(-13);
})
.view;
self.addImageView(1001).image(TLImage(@"AppLogo"))
.masonry(^(MASConstraintMaker *make) {
make.top.mas_equalTo(20);
make.centerX.mas_equalTo(0);
make.size.mas_equalTo(CGSizeMake(73, 64));
});
}
return self;
}
@end
@@ -0,0 +1,13 @@
//
// TLAccountSettingViewController.h
// TLChat
//
// Created by 李伯坤 on 16/2/10.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLAccountSettingViewController : ZZFlexibleLayoutViewController
@end
@@ -0,0 +1,144 @@
//
// TLAccountSettingViewController.m
// TLChat
//
// Created by 李伯坤 on 16/2/10.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLAccountSettingViewController.h"
#import "TLWebViewController.h"
#import "TLUserHelper.h"
#import "TLSettingItem.h"
typedef NS_ENUM(NSInteger, TLAccountSettingVCSectionType) {
TLAccountSettingVCSectionTypeAccount,
TLAccountSettingVCSectionTypeLock,
TLAccountSettingVCSectionTypeSafe,
TLAccountSettingVCSectionTypeHelp,
};
@implementation TLAccountSettingViewController
- (void)loadView
{
[super loadView];
[self setTitle:LOCSTR(@"账号与安全")];
[self.view setBackgroundColor:[UIColor colorGrayBG]];
[self loadAccountSettingUI];
}
- (void)loadAccountSettingUI
{
@weakify(self);
self.clear();
TLUser *userInfo = [TLUserHelper sharedHelper].user;
{
NSInteger sectionTag = TLAccountSettingVCSectionTypeAccount;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
// 微信号
TLSettingItem *nameItem = TLCreateSettingItem(@"微信号");
if (userInfo.username.length > 0) {
nameItem.subTitle = userInfo.username;
nameItem.showDisclosureIndicator = NO;
nameItem.disableHighlight = YES;
}
else {
nameItem.subTitle = LOCSTR(@"未设置");
nameItem.showDisclosureIndicator = YES;
nameItem.disableHighlight = NO;
}
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(nameItem).selectedAction(^ (TLSettingItem *data) {
});
// 手机号
TLSettingItem *phoneItem = TLCreateSettingItem(@"手机号");
if (userInfo.detailInfo.phoneNumber.length > 0) {
phoneItem.subTitle = userInfo.detailInfo.phoneNumber;
phoneItem.rightImagePath = @"setting_lockon";
}
else {
phoneItem.subTitle = LOCSTR(@"未设置");
phoneItem.rightImagePath = @"setting_lockoff";
}
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(phoneItem).selectedAction(^ (TLSettingItem *data) {
@strongify(self);
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"手机号" message:nil preferredStyle:UIAlertControllerStyleAlert];
__block UITextField *phoneTextField;
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
phoneTextField = textField;
[textField setKeyboardType:UIKeyboardTypePhonePad];
[textField setPlaceholder:@"请输入手机号"];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
@strongify(self);
[TLUserHelper sharedHelper].user.detailInfo.phoneNumber = phoneTextField.text;
[self loadAccountSettingUI];
}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
});
}
{
NSInteger sectionTag = TLAccountSettingVCSectionTypeLock;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
// 微信密码
TLSettingItem *passItem = TLCreateSettingItem(@"微信密码");
passItem.subTitle = @"已设置";
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(passItem).selectedAction(^ (TLSettingItem *data) {
});
// 声音锁
TLSettingItem *voiceItem = TLCreateSettingItem(@"声音锁");
voiceItem.subTitle = @"未设置";
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(voiceItem).selectedAction(^ (TLSettingItem *data) {
});
}
{
NSInteger sectionTag = TLAccountSettingVCSectionTypeSafe;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
// 应急联系人
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"应急联系人")).selectedAction(^ (TLSettingItem *data) {
});
// 登录设备管理
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"登录设备管理")).selectedAction(^ (TLSettingItem *data) {
});
// 更多安全设置
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"更多安全设置")).selectedAction(^ (TLSettingItem *data) {
});
}
{
NSInteger sectionTag = TLAccountSettingVCSectionTypeHelp;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
// 微信安全中心
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"微信安全中心")).selectedAction(^ (TLSettingItem *data) {
});
self.setFooter(VIEW_ST_FOOTER).toSection(sectionTag).withDataModel(LOCSTR(@"如果遇到账号信息泄露、忘记密码、诈骗等账号问题,可前往微信安全中心。"));
}
[self reloadView];
}
@end
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,13 @@
//
// TLNewMessageSettingViewController.h
// TLChat
//
// Created by 李伯坤 on 16/2/8.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLNewMessageSettingViewController : ZZFlexibleLayoutViewController
@end
@@ -0,0 +1,82 @@
//
// TLNewMessageSettingViewController.m
// TLChat
//
// Created by 李伯坤 on 16/2/8.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLNewMessageSettingViewController.h"
#import "TLSettingItem.h"
typedef NS_ENUM(NSInteger, TLNewMessageSettingVCSectionType) {
TLNewMessageSettingVCSectionTypeOn,
TLNewMessageSettingVCSectionTypeDetail,
TLNewMessageSettingVCSectionTypeOff,
};
@implementation TLNewMessageSettingViewController
- (void)loadView
{
[super loadView];
[self setTitle:LOCSTR(@"新消息通知")];
[self.view setBackgroundColor:[UIColor colorGrayBG]];
[self loadNewMessageSettingUI];
}
#pragma mark - # UI
- (void)loadNewMessageSettingUI
{
self.clear();
{
NSInteger sectionTag = TLNewMessageSettingVCSectionTypeOn;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(0, 0, 0, 0));
self.setHeader(VIEW_ST_HEADER).toSection(sectionTag).withDataModel(@"微信未打开时");
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"新消息通知")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"语音和视频通话提醒")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
}
{
NSInteger sectionTag = TLNewMessageSettingVCSectionTypeDetail;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 5, 0));
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"通知显示消息详情")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
}
{
NSInteger sectionTag = TLNewMessageSettingVCSectionTypeOff;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(0, 0, 0, 0));
self.setHeader(VIEW_ST_HEADER).toSection(sectionTag).withDataModel(@"微信打开时");
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"声音")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"震动")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
}
[self reloadView];
}
@end
@@ -0,0 +1,13 @@
//
// TLPrivacySettingViewController.h
// TLChat
//
// Created by 李伯坤 on 16/2/10.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLPrivacySettingViewController : ZZFlexibleLayoutViewController
@end
@@ -0,0 +1,119 @@
//
// TLPrivacySettingViewController.m
// TLChat
//
// Created by 李伯坤 on 16/2/10.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLPrivacySettingViewController.h"
#import "TLSettingItem.h"
typedef NS_ENUM(NSInteger, TLPrivacySettingVCSectionType) {
TLPrivacySettingVCSectionTypeVerify,
TLPrivacySettingVCSectionTypeWay,
TLPrivacySettingVCSectionTypeBlackList,
TLPrivacySettingVCSectionTypeMoments,
TLPrivacySettingVCSectionTypeMomentsNoti,
TLPrivacySettingVCSectionTypePower,
};
@implementation TLPrivacySettingViewController
- (void)loadView
{
[super loadView];
[self.view setBackgroundColor:[UIColor colorGrayBG]];
[self setTitle:LOCSTR(@"隐私")];
[self loadPrivacySettingUI];
}
#pragma mark - # UI
- (void)loadPrivacySettingUI
{
self.clear();
{
NSInteger sectionTag = TLPrivacySettingVCSectionTypeVerify;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"加我为好友时需要验证")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
}
{
NSInteger sectionTag = TLPrivacySettingVCSectionTypeWay;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"添加我的方式")).selectedAction(^ (id data) {
});
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"向我推荐通讯录朋友")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
self.setFooter(VIEW_ST_FOOTER).toSection(sectionTag).withDataModel(@"开启后,为你推荐已经开通微信的手机联系人。");
}
{
NSInteger sectionTag = TLPrivacySettingVCSectionTypeBlackList;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 5, 0));
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"通讯录黑名单")).selectedAction(^ (id data) {
});
}
{
NSInteger sectionTag = TLPrivacySettingVCSectionTypeMoments;
self.addSection(sectionTag);
self.setHeader(VIEW_ST_HEADER).toSection(sectionTag).withDataModel(@"朋友圈");
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"不让他(她)看我的朋友圈")).selectedAction(^ (id data) {
});
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"不看他(她)的朋友圈")).selectedAction(^ (id data) {
});
TLSettingItem *areaItem = TLCreateSettingItem(@"允许朋友查看朋友圈的范围");
areaItem.subTitle = @"全部";
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(areaItem).selectedAction(^ (id data) {
});
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"允许陌生人查看十张照片")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
}
{
NSInteger sectionTag = TLPrivacySettingVCSectionTypeMomentsNoti;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
self.addCell(CELL_ST_ITEM_SWITCH).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"朋友圈更新提醒")).eventAction(^ id(NSInteger eventType, id data) {
return nil;
});
self.setFooter(VIEW_ST_FOOTER).toSection(sectionTag).withDataModel(@"关闭后,有朋友发表朋友圈时,界面下方的”发现“切换按钮上不再出现红点提示。");
}
{
NSInteger sectionTag = TLPrivacySettingVCSectionTypePower;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(15, 0, 30, 0));
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"授权管理")).selectedAction(^ (id data) {
});
}
[self reloadView];
}
@end
@@ -0,0 +1,13 @@
//
// TLSettingViewController.h
// TLChat
//
// Created by 李伯坤 on 16/2/8.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLSettingViewController : ZZFlexibleLayoutViewController
@end
@@ -0,0 +1,107 @@
//
// TLSettingViewController.m
// TLChat
//
// Created by 李伯坤 on 16/2/8.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLSettingViewController.h"
#import "TLAccountSettingViewController.h"
#import "TLNewMessageSettingViewController.h"
#import "TLPrivacySettingViewController.h"
#import "TLCommonSettingViewController.h"
#import "TLAboutViewController.h"
#import "TLWebViewController.h"
#import "TLSettingItem.h"
typedef NS_ENUM(NSInteger, TLSettingVCSectionType) {
TLSettingVCSectionTypeAccount,
TLSettingVCSectionTypeNomal,
TLSettingVCSectionTypeAbout,
TLSettingVCSectionTypeExit,
};
@implementation TLSettingViewController
- (void)loadView
{
[super loadView];
[self setTitle:LOCSTR(@"设置")];
[self.collectionView setBackgroundColor:[UIColor colorGrayBG]];
[self loadSettingUI];
}
#pragma mark - # UI
- (void)loadSettingUI
{
@weakify(self);
self.clear();
{
NSInteger sectionTag = TLSettingVCSectionTypeAccount;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
// 账号与安全
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"账号与安全")).selectedAction(^ (id data) {
@strongify(self);
TLAccountSettingViewController *accountAndSafetyVC = [[TLAccountSettingViewController alloc] init];
PushVC(accountAndSafetyVC);
});
}
{
NSInteger sectionTag = TLSettingVCSectionTypeNomal;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
// 新消息通知
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"新消息通知")).selectedAction(^ (id data) {
@strongify(self);
TLNewMessageSettingViewController *newMessageSettingVC = [[TLNewMessageSettingViewController alloc] init];
PushVC(newMessageSettingVC);
});
// 隐私
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"隐私")).selectedAction(^ (id data) {
@strongify(self);
TLPrivacySettingViewController *privacySettingVC = [[TLPrivacySettingViewController alloc] init];
PushVC(privacySettingVC);
});
// 通用
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"通用")).selectedAction(^ (id data) {
@strongify(self);
TLCommonSettingViewController *commonSettingVC = [[TLCommonSettingViewController alloc] init];
PushVC(commonSettingVC);
});
}
{
NSInteger sectionTag = TLSettingVCSectionTypeAbout;
self.addSection(TLSettingVCSectionTypeAbout).sectionInsets(UIEdgeInsetsMake(20, 0, 0, 0));
// 帮助与反馈
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"帮助与反馈")).selectedAction(^ (id data) {
@strongify(self);
TLWebViewController *webVC = [[TLWebViewController alloc] initWithUrl:@"https://github.com/tbl00c/TLChat/issues"];
PushVC(webVC);
});
// 关于微信
self.addCell(CELL_ST_ITEM_NORMAL).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"关于微信")).selectedAction(^ (id data) {
@strongify(self);
TLAboutViewController *aboutVC = [[TLAboutViewController alloc] init];
PushVC(aboutVC);
});
}
{
NSInteger sectionTag = TLSettingVCSectionTypeExit;
self.addSection(sectionTag).sectionInsets(UIEdgeInsetsMake(20, 0, 40, 0));
self.addCell(CELL_ST_ITEM_BUTTON).toSection(sectionTag).withDataModel(TLCreateSettingItem(@"退出登录")).selectedAction(^ (id data) {
TLActionSheet *actionSheet = [[TLActionSheet alloc] initWithTitle:@"退出后不会删除任何历史数据,下次登录依然可以使用本账号。" clickAction:^(NSInteger buttonIndex) {
} cancelButtonTitle:LOCSTR(@"取消") destructiveButtonTitle:LOCSTR(@"退出登录") otherButtonTitles:nil];
[actionSheet show];
});
}
[self reloadView];
}
@end